Ice 3.7 C++98 API Reference
Loading...
Searching...
No Matches
Time.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_UTIL_TIME_H
6#define ICE_UTIL_TIME_H
7
8#include <IceUtil/Config.h>
9
10#ifndef _WIN32
11# include <sys/time.h>
12#endif
13
14namespace IceUtil
15{
16
18{
19public:
20
22
23 // No copy constructor and assignment operator necessary. The
24 // automatically generated copy constructor and assignment
25 // operator do the right thing.
26
29
33
34 static Time secondsDouble(double);
35 static Time milliSecondsDouble(double);
36 static Time microSecondsDouble(double);
37
38#ifndef _WIN32
39 operator timeval() const;
40#endif
41
45
46 double toSecondsDouble() const;
47 double toMilliSecondsDouble() const;
48 double toMicroSecondsDouble() const;
49
50 std::string toDateTime() const;
51 std::string toDuration() const;
52 std::string toString(const std::string&) const;
53
55 {
56 return Time(-_usec);
57 }
58
59 Time operator-(const Time& rhs) const
60 {
61 return Time(_usec - rhs._usec);
62 }
63
64 Time operator+(const Time& rhs) const
65 {
66 return Time(_usec + rhs._usec);
67 }
68
69 Time& operator+=(const Time& rhs)
70 {
71 _usec += rhs._usec;
72 return *this;
73 }
74
75 Time& operator-=(const Time& rhs)
76 {
77 _usec -= rhs._usec;
78 return *this;
79 }
80
81 bool operator<(const Time& rhs) const
82 {
83 return _usec < rhs._usec;
84 }
85
86 bool operator<=(const Time& rhs) const
87 {
88 return _usec <= rhs._usec;
89 }
90
91 bool operator>(const Time& rhs) const
92 {
93 return _usec > rhs._usec;
94 }
95
96 bool operator>=(const Time& rhs) const
97 {
98 return _usec >= rhs._usec;
99 }
100
101 bool operator==(const Time& rhs) const
102 {
103 return _usec == rhs._usec;
104 }
105
106 bool operator!=(const Time& rhs) const
107 {
108 return _usec != rhs._usec;
109 }
110
111 double operator/(const Time& rhs) const
112 {
113 return static_cast<double>(_usec) / static_cast<double>(rhs._usec);
114 }
115
116 Time& operator*=(int rhs)
117 {
118 _usec *= rhs;
119 return *this;
120 }
121
122 Time operator*(int rhs) const
123 {
124 Time t;
125 t._usec = _usec * rhs;
126 return t;
127 }
128
129 Time& operator/=(int rhs)
130 {
131 _usec /= rhs;
132 return *this;
133 }
134
135 Time operator/(int rhs) const
136 {
137 Time t;
138 t._usec = _usec / rhs;
139 return t;
140 }
141
143 {
144 _usec *= rhs;
145 return *this;
146 }
147
149 {
150 Time t;
151 t._usec = _usec * rhs;
152 return t;
153 }
154
156 {
157 _usec /= rhs;
158 return *this;
159 }
160
162 {
163 Time t;
164 t._usec = _usec / rhs;
165 return t;
166 }
167
168 Time& operator*=(double rhs)
169 {
170 _usec = static_cast<Int64>(static_cast<double>(_usec) * rhs);
171 return *this;
172 }
173
174 Time operator*(double rhs) const
175 {
176 Time t;
177 t._usec = static_cast<Int64>(static_cast<double>(_usec) * rhs);
178 return t;
179 }
180
181 Time& operator/=(double rhs)
182 {
183 _usec = static_cast<Int64>(static_cast<double>(_usec) / rhs);
184 return *this;
185 }
186
187 Time operator/(double rhs) const
188 {
189 Time t;
190 t._usec = static_cast<Int64>(static_cast<double>(_usec) / rhs);
191 return t;
192 }
193
194private:
195
196 Time(Int64);
197
198 Int64 _usec;
199};
200
201ICE_API std::ostream& operator<<(std::ostream&, const Time&);
202
203} // End namespace IceUtil
204
205#endif
#define ICE_API
Definition Config.h:197
Definition Time.h:18
Time operator+(const Time &rhs) const
Definition Time.h:64
static Time microSeconds(Int64)
Time & operator+=(const Time &rhs)
Definition Time.h:69
double operator/(const Time &rhs) const
Definition Time.h:111
Time operator*(double rhs) const
Definition Time.h:174
Int64 toSeconds() const
Time operator-() const
Definition Time.h:54
std::string toDateTime() const
Time operator-(const Time &rhs) const
Definition Time.h:59
bool operator>(const Time &rhs) const
Definition Time.h:91
Time & operator/=(int rhs)
Definition Time.h:129
static Time now(Clock=Realtime)
static Time milliSeconds(Int64)
bool operator==(const Time &rhs) const
Definition Time.h:101
double toMilliSecondsDouble() const
bool operator<(const Time &rhs) const
Definition Time.h:81
Time & operator/=(double rhs)
Definition Time.h:181
Clock
Definition Time.h:27
@ Realtime
Definition Time.h:27
@ Monotonic
Definition Time.h:27
Time & operator-=(const Time &rhs)
Definition Time.h:75
Time operator/(double rhs) const
Definition Time.h:187
Time & operator*=(double rhs)
Definition Time.h:168
static Time microSecondsDouble(double)
Time & operator/=(Int64 rhs)
Definition Time.h:155
double toSecondsDouble() const
bool operator!=(const Time &rhs) const
Definition Time.h:106
double toMicroSecondsDouble() const
Time & operator*=(Int64 rhs)
Definition Time.h:142
Int64 toMilliSeconds() const
bool operator>=(const Time &rhs) const
Definition Time.h:96
Time operator/(Int64 rhs) const
Definition Time.h:161
static Time seconds(Int64)
static Time milliSecondsDouble(double)
Time operator/(int rhs) const
Definition Time.h:135
bool operator<=(const Time &rhs) const
Definition Time.h:86
Int64 toMicroSeconds() const
Time & operator*=(int rhs)
Definition Time.h:116
std::string toDuration() const
static Time secondsDouble(double)
Time operator*(Int64 rhs) const
Definition Time.h:148
std::string toString(const std::string &) const
Time operator*(int rhs) const
Definition Time.h:122
Definition Cond.h:39
long long Int64
Definition Config.h:342
std::ostream & operator<<(std::ostream &, const Exception &)