source: trunk/MagicSoft/Cosy/base/timer.h@ 3791

Last change on this file since 3791 was 2384, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 1.9 KB
Line 
1#ifndef COSY_Timer
2#define COSY_Timer
3
4struct timeval;
5
6class ostream;
7
8class Timer
9{
10 friend ostream &operator<<(ostream &out, Timer &t);
11private:
12 double fMs; // Microsec in units of sec as returned by gettimeofday
13 int fSecs; // Seconds as returned by gettimeofday
14
15 int fSec; // Sec of time
16 int fMin; // Min of time
17 int fHor; // Hor of time
18 int fDay; // Day of time
19 int fMon; // Mon of time
20 int fYea; // Yea of time
21
22 double fDiv; // Division of day
23 double fMjd; // MJD
24
25 char fDateStr[30];
26
27 //void Set(const long mjd);
28
29public:
30 Timer(int d, int m, int y, int h, int min, int s, double ms)
31 : fMs(ms), fSecs(0), fSec(s), fMin(m), fHor(h), fDay(d), fMon(m), fYea(y), fDiv(0), fMjd(0) {}
32 Timer() : fMs(0), fSecs(0), fSec(0), fMin(0), fHor(0), fDay(0), fMon(0), fYea(0), fDiv(0), fMjd(0) {}
33 Timer(double t);
34 Timer(struct timeval *tv);
35 Timer(const Timer &t);
36
37 void SetTimer(int tv_sec, double tv_usec);
38 void SetTimer(const struct timeval *tv);
39 void SetTimer(int y, int m, int d, int h, int min, int s, double ms)
40 {
41 fMs = ms;
42 fSec = s;
43 fMin = min;
44 fHor = h;
45 fDay = d;
46 fMon = m;
47 fYea = y;
48 }
49
50 void GetTimeval(struct timeval *tv) const;
51
52 int GetSecs() { return fSecs; }
53
54 double Now(); //[s]
55 double GetMjd() const { return fMjd/*+fDiv*/; }
56
57 virtual void SetMjd(double mjd);
58
59 int Day() const { return fDay; }
60 int Month() const { return fMon; }
61 int Year() const { return fYea; }
62
63 int H() const { return fHor; }
64 int M() const { return fMin; }
65 int S() const { return fSec; }
66 int MilliSec() const { return (int)(fMs*1000); }
67 double MicroSec() const { return fMs; }
68
69 const char *GetTimeStr();
70
71 void Print();
72
73 operator double() const; //[s]
74};
75
76ostream &operator<<(ostream &out, Timer &t);
77
78#endif
Note: See TracBrowser for help on using the repository browser.