149 cout <<
"\nTIME MANAGER EXAMPLE" << endl;
151 cout <<
" Example: create times (t0,t1,t2)\n\n";
152 CTime t0,t1,t2,t3,t20,td,ta,td0,ta0,ts,ts0,ta2,ta20;
153 cout <<
" t0: " << t0 << endl;
155 cout <<
"\n Example: sleep 300 ms " << endl;
158 cout <<
"\n Example: set t1 (0.300 rel)\n\n";
161 cout <<
" t1: " << t1 <<
"\n t1o: " << t10 << endl;
163 cout <<
"\n Example: set t3 delayed 200 ms (0.200 abs)\n\n";
165 cout <<
" t3: " << t3 << endl;
167 cout <<
"\n Example: sleep 1705 ms " << endl;
170 cout <<
"\n Example: set t2 (2.005 rel)\n\n";
173 cout <<
" t2: " << t2 <<
"\n t2o: " << t20 << endl;
175 cout <<
"\n Example: t2 - t1 (1.705)\n\n";
178 cout <<
" td: " << td <<
"\n tdo: " << td0 << endl;
180 cout <<
"\n Example: + addition (t1+t2)\n\n";
183 cout <<
" ts: " << ts <<
"\n tso: " << ts0 <<
"\n ulongmax: " << ULONG_MAX << endl;
185 cout <<
"\n Example: + Exception (overvalue)\n\n";
190 cout << e.
what() << endl;
192 cout <<
"\n Example: - Exception (negative)\n\n";
197 cout << e.
what() << endl;
200 cout <<
"\n Example: average (t1,t2)\n\n";
201 ta = ( t1 + t2 ) / 2;
202 ta0 = (t10 + t20)/2 ;
203 cout <<
" ta: " << ta <<
"\n tao: " << ta0 << endl;
205 cout <<
"\n Example: comparative (t1==t2, t3==t2)\n\n";
207 cout <<
" ?: " << boolalpha << (bool)(t1==t2) <<
" "
208 << (bool)(t3==t2) << endl;
210 cout <<
"\n Example: comparative (t1<t2, t1<=t2, t3>t2, t3>=t2)\n\n";
213 <<
" t1: " << t1 <<
"\n t2: " << t2 << endl <<
" t3: " << t3 << endl
214 <<
" ?: <: " << boolalpha << (bool)(t1<t2) <<
" <=: " << (bool)(t1<=t2) << endl
215 <<
" ?: >: " << boolalpha << (bool)(t3>t2) <<
" >=: " << (
bool)(t3>=t2) << endl;
218 cout <<
"\n Example: getting time (t1/t0)\n\n";
220 cout <<
" seconds and nanoseconds:" << endl
221 <<
" " << t1.
seconds() <<
" " << t1.nanoseconds() << endl
222 <<
" " << t10.seconds() <<
" " << t10.nanoseconds() << endl;
223 cout <<
" double Seconds:" << endl
224 <<
" " << t1.getTimeInSeconds() << endl
225 <<
" " << t10.getTimeInSeconds() << endl
226 <<
" double milliseconds:" << endl
227 <<
" " << t1.getTimeInMilliseconds() << endl
228 <<
" " << t10.getTimeInMilliseconds() << endl;
230 t1.setFormat(ctf_secnano);
231 t10.setFormat(ctf_secnano);
232 cout <<
" Format ctf_secnano: " << endl
234 <<
" " << t10 << endl;
236 t1.setFormat(ctf_datetime);
237 t10.setFormat(ctf_datetime);
238 cout <<
" Format ctf_datetime: " << endl
240 <<
" " << t10 << endl;
242 t1.setFormat(ctf_dtfile);
243 t10.setFormat(ctf_dtfile);
244 cout <<
" Format ctf_dtfile: " << endl
246 <<
" " << t10 << endl;
248 t1.setFormat(ctf_ms);
249 t10.setFormat(ctf_ms);
250 cout <<
" Format ctf_ms: " << endl
252 <<
" " << t10 << endl;
254 t1.setFormat(ctf_us);
255 t10.setFormat(ctf_us);
256 cout <<
" Format ctf_us: " << endl
258 <<
" " << t10 << endl;
261 t1t = t1.getTimeInTimespec();
262 cout <<
" Timespec" << endl;
263 cout <<
" " << t1t.tv_sec <<
" " << t1t.tv_nsec << endl;
266 struct tm * timeinfo;
268 t1tt = t1.getTimeInTime_t();
269 cout <<
" Time_t" << endl;
270 cout <<
" " << t1tt << endl;
271 timeinfo = localtime ( &t1tt );
272 cout <<
" some formats using time_t" << endl;
273 strftime (buffer,80,
"%F,%T\n %I:%M%p\n %c",timeinfo);
274 cout <<
" " << buffer << endl;
276 cout <<
"\n Example: Using Reference Time\n\n";
277 cout <<
" Set Reference and wait 1 second" << endl << endl;
282 cout <<
" Time ref: " << tzero << endl;
283 cout <<
" t1 (ref.): " << t1 << endl;
284 cout <<
" t2 (raw): " << t2 << endl << endl;
285 cout <<
" Set useRef(true) for t2 and set its time" << endl << endl;
288 cout <<
" t2: " << t2 <<
" Is ref used?: " << t2.isRefUsed() << endl << endl;
290 cout <<
"\n Example: END\n\n";
virtual const std::string & what(void)
Function to get the error message.
unsigned long seconds(void)
Get Seconds.
Implementation of a time class and operations.
void set(double milliseconds=-1.0)
Sets the internal time.
CTime getRef()
Get the reference internal time.