-
Notifications
You must be signed in to change notification settings - Fork 1
/
constate.cc
76 lines (63 loc) · 1.25 KB
/
constate.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iomanip.h>
#include "constate.h"
Time::Time(const Time &rhs) : timeval((timeval&)rhs)
{}
Time::Time(const timeval &rhs) : timeval(rhs)
{}
Time::Time(const double time)
{
tv_sec = (int)time;
tv_usec= (int)((time-((double)((int)time)))*1e6);
}
Time::Time(const unsigned sec, const unsigned usec)
{
tv_sec=sec;
tv_usec=usec;
}
Time::Time()
{
SetToCurrentTime();
}
void Time::SetToCurrentTime()
{
gettimeofday((struct timeval *)this,0);
}
Time & Time::operator=(const Time &rhs)
{
tv_sec=rhs.tv_sec;
tv_usec=rhs.tv_usec;
return *this;
}
Time & Time::operator=(const double &rhs)
{
return operator=(Time(rhs));
}
Time::operator double() const
{
return ((double)(tv_sec)) + ((double)(tv_usec)/1e6);
}
bool Time::operator<(const Time &rhs) const
{
if (tv_sec<rhs.tv_sec) {
return true;
} else {
if (tv_sec>rhs.tv_sec) {
return false;
} else {
return (tv_usec<rhs.tv_usec);
}
}
}
bool Time::operator>(const Time &rhs) const
{
return !(operator <(rhs));
}
bool Time::operator==(const Time &rhs) const
{
return tv_sec==rhs.tv_sec && tv_usec==rhs.tv_usec;
}
ostream & Time::Print(ostream &os) const
{
os << "Time(sec="<<tv_sec<<", usec="<<tv_usec<<", double="<<((double)(*this))<<")";
return os;
}