| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# Time.h

Go to the documentation of this file.

    00001 // $Id: Time.h,v 1.3 2006/01/25 16:02:48 hmd Exp $
    00002 #ifndef GAUDIKERNEL_TIME_H
    00003 #define GAUDIKERNEL_TIME_H 1
    00004
    00005 // Include files
    00006 //   for the architecture independent int64 definition (longlong)
    00007 #include "GaudiKernel/Kernel.h"
    00008 #include "GaudiKernel/StreamBuffer.h"
    00009 #include "GaudiKernel/GaudiException.h"
    00010
    00021 class GAUDI_API TimeException: public GaudiException {
    00022 public:
    00023   // Standard constructor
    00024   TimeException( const std::string& Message = "unspecified exception",
    00025                  const std::string& Tag = "*Gaudi::Time*",
    00026                  const StatusCode & Code = StatusCode::FAILURE ):
    00027     GaudiException(Message,Tag,Code) {}
    00029   virtual ~TimeException() throw() {}
    00030 };
    00031
    00032 struct tm;
    00033 # ifdef WIN32
    00034 typedef struct _FILETIME FILETIME;
    00035 # endif
    00036
    00037 namespace Gaudi {
    00038
    00039   class Time;
    00040   class TimeSpan;
    00041
    00057   class GAUDI_API TimeSpan {
    00058     friend class Time;
    00059   public:
    00060     typedef longlong ValueType;
    00061
    00062     TimeSpan (void);
    00063     TimeSpan (Time t);
    00064     TimeSpan (ValueType nsecs);
    00065     TimeSpan (ValueType secs, int nsecs);
    00066     TimeSpan (int days, int hours, int mins, int secs, int nsecs);
    00067
    00068     int  days (void) const;
    00069     int  hours (void) const;
    00070     int  minutes (void) const;
    00071     ValueType  seconds (void) const;
    00072
    00073     int  lastHours (void) const;
    00074     int  lastMinutes (void) const;
    00075     int  lastSeconds (void) const;
    00076     int  lastNSeconds (void) const;
    00077
    00078     TimeSpan &  operator+= (const TimeSpan &x);
    00079     TimeSpan &  operator-= (const TimeSpan &x);
    00080     TimeSpan &  operator*= (const TimeSpan &n);
    00081     TimeSpan &  operator/= (const TimeSpan &n);
    00082     TimeSpan &  operator%= (const TimeSpan &n);
    00083
    00084     ValueType  ns (void) const;
    00085
    00086   private:
    00087     ValueType  m_nsecs; //< The span length.
    00088   };
    00089
    00090
    00214   class GAUDI_API Time {
    00215     friend class TimeSpan;
    00216   public:
    00217     typedef longlong ValueType;
    00218
    00220     enum Months {
    00221       January  = 0,
    00222       February = 1,
    00223       March  = 2,
    00224       April  = 3,
    00225       May  = 4,
    00226       June  = 5,
    00227       July  = 6,
    00228       August  = 7,
    00229       September = 8,
    00230       October  = 9,
    00231       November = 10,
    00232       December = 11
    00233     };
    00234
    00236     static const int SECS_PER_DAY = 86400;
    00237
    00239     static const int SECS_PER_HOUR = 3600;
    00240
    00242     static const ValueType SEC_NSECS = 1000000000;
    00243
    00244     Time (void);
    00245     Time (TimeSpan ts);
    00246     Time (ValueType nsecs);
    00247     Time (ValueType secs, int nsecs);
    00248     Time (int year, int month, int day, int hour, int min, int sec,
    00249           ValueType nsecs, bool local = true);
    00250     // implicit copy constructor
    00251     // implicit assignment operator
    00252     // implicit destructor
    00253
    00255     static Time epoch   (void);
    00257     static Time max     (void);
    00259     static Time  current (void);
    00260 # ifdef WIN32
    00261     static Time  from    (const FILETIME *systime);
    00262 # endif
    00263     static Time  build   (bool local, const tm &base, TimeSpan diff = 0);
    00264
    00265     tm   split   (bool local, int *nsecpart = 0) const;
    00266     tm   utc     (int *nsecpart = 0) const;
    00267     tm   local   (int *nsecpart = 0) const;
    00268
    00269     int       year    (bool local) const;
    00270     int       month   (bool local) const;
    00271     int       day     (bool local) const;
    00272     int       hour    (bool local) const;
    00273     int       minute  (bool local) const;
    00274     int       second  (bool local) const;
    00275     int       nsecond (void) const;
    00276     int       weekday (bool local) const;
    00277     bool      isdst   (bool local) const;
    00278
    00279     ValueType  utcoffset (int *daylight = 0) const;
    00280     const char * timezone (int *daylight = 0) const;
    00281
    00282     Time &  operator+= (const TimeSpan &x);
    00283     Time &  operator-= (const TimeSpan &x);
    00284
    00285     ValueType  ns (void) const;
    00286
    00287     std::string  format (bool local, const std::string &spec) const;
    00288     std::string  nanoformat (int minwidth = 1, int maxwidth = 9) const;
    00289
    00290     static bool  isLeap (int year);
    00291
    00292     // Conversion helpers
    00293     static unsigned toDosDate (Time time);
    00294     static Time  fromDosDate (unsigned dosDate);
    00295
    00296   private:
    00297     ValueType  m_nsecs; //< Time value as nsecs from #epoch().
    00298
    00299     inline void TimeAssert(bool cond, const std::string &msg = "time assertion failed") const {
    00300       if (!cond) throw TimeException(msg);
    00301     }
    00302
    00303   };
    00304
    00305 }
    00306
    00307 #include "GaudiKernel/Time.icpp"
    00308
    00309 #endif // GAUDIKERNEL_TIME_H