Fawkes API Fawkes Development Version
time.cpp
1
2/***************************************************************************
3 * time.c - A time class
4 *
5 * Created: Wed Jun 06 16:50:11 2007
6 * Copyright 2007 Daniel Beck
7 * 2007-2009 Tim Niemueller [www.niemueller.de]
8 *
9 ****************************************************************************/
10
11/* This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. A runtime exception applies to
15 * this software (see LICENSE.GPL_WRE file mentioned below for details).
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
21 *
22 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
23 */
24
25#include <core/exception.h>
26#include <core/exceptions/software.h>
27#include <utils/time/clock.h>
28#include <utils/time/time.h>
29
30#include <cmath>
31#include <cstdio>
32#include <cstdlib>
33#include <cstring>
34#include <limits>
35#include <time.h>
36#include <unistd.h>
37
38namespace fawkes {
39
40/** Instance of Time denoting the maximum value possible.
41 * This is particularly useful when initializing a minimization in time.
42 */
43const Time TIME_MAX = Time(std::numeric_limits<time_t>::max(), 999999);
44
45/** Instance of Time denoting the minimum value possible.
46 * This is particularly useful when initializing a maximization in time.
47 */
48const Time TIME_MIN = Time(0, 1);
49
50/** @class Time <utils/time/time.h>
51 * A class for handling time.
52 * @author Daniel Beck
53 * @author Tim Niemueller
54 *
55 * @fn const timeval * Time::get_timeval() const
56 * Obtain the timeval where the time is stored.
57 * @return a const pointer to the timeval where the time is stored
58 *
59 * @fn long Time::get_sec() const
60 * Get seconds.
61 * @return seconds stored in time stamp
62 *
63 * @fn long Time::get_msec() const
64 * Get milliseconds.
65 * @return milliseconds stored in time stamp
66 *
67 * @fn long Time::get_usec() const
68 * Get microseconds.
69 * @return microseconds stored in time stamp
70 *
71 * @fn long Time::get_nsec() const
72 * Get nanoseconds.
73 * @return microsecons converted to nanoseconds
74 *
75 * @fn bool Time::is_zero() const
76 * Check if time is zero.
77 * @return true if time is zero, i.e. sec = usec = 0, false otherwise
78 *
79 * @fn void Time::get_timestamp(long &sec, long &usec) const
80 * Get time stamp.
81 * @param sec upon return contains seconds stored in time stamp
82 * @param usec upon return contains microseconds stored in time stamp
83 */
84
85/** Maximum size of string returned by str() and the minimum size
86 * of the string passwd to str_r(). */
87// as recommened in asctime_r() docs
88const unsigned int Time::TIMESTR_SIZE = 26;
89
90/** Constructor.
91 * Sets time to the current time.
92 */
94{
95 clock_ = Clock::instance();
96 clock_->get_time(&time_);
97 timestr_ = NULL;
98}
99
100/** Constructor.
101 * Sets time to the given time.
102 * @param tv the Time object is initialized with the time given in this timeval
103 */
104Time::Time(const timeval *tv)
105{
106 time_.tv_sec = tv->tv_sec;
107 time_.tv_usec = tv->tv_usec;
108 clock_ = Clock::instance();
109 timestr_ = NULL;
110}
111
112/** Constructor.
113 * Sets time to the given time. Basically the same as setting from a timeval struct
114 * but the components are given separately.
115 * @param sec time in seconds since the epoch (or time range)
116 * @param usec fractions in microseconds added to sec
117 * @param clock optional clock to use, if NULL Clock::instance() will be used
118 */
119Time::Time(long sec, long usec, Clock *clock)
120{
121 time_.tv_sec = sec;
122 time_.tv_usec = usec;
123 if (clock) {
124 clock_ = clock;
125 } else {
126 clock_ = Clock::instance();
127 }
128 timestr_ = NULL;
129}
130
131/** Constructor.
132 * Sets time to given number of ms, use for time range.
133 * @param ms the Time object is initialized to the time given in milli-seconds
134 */
136{
137 time_t sec = (time_t)(ms / 1000.0);
138 suseconds_t usec = (ms % 1000) * 1000;
139
140 time_.tv_sec = sec;
141 time_.tv_usec = usec;
142 clock_ = Clock::instance();
143 timestr_ = NULL;
144}
145
146/** Constructor.
147 * Sets time to given number of ms, use for time range.
148 * @param s the Time object is initialized to the time given in seconds
149 */
150Time::Time(double s)
151{
152 time_t sec = (time_t)s;
153 suseconds_t usec = (suseconds_t)roundf((s - sec) * 1000000.f);
154
155 time_.tv_sec = sec;
156 time_.tv_usec = usec;
157 clock_ = Clock::instance();
158 timestr_ = NULL;
159}
160
161/** Constructor.
162 * This constructor uses the supplied clock for setting the time. The
163 * time is set to the current time.
164 * @param clock clock
165 */
167{
168 this->clock_ = clock;
169 clock_->get_time(&time_);
170 timestr_ = NULL;
171}
172
173/** Copy constructor.
174 * @param t time to copy
175 */
177{
178 time_.tv_sec = t.time_.tv_sec;
179 time_.tv_usec = t.time_.tv_usec;
180 clock_ = t.clock_;
181 if (t.timestr_) {
182 timestr_ = (char *)malloc(TIMESTR_SIZE);
183 strncpy(timestr_, t.timestr_, TIMESTR_SIZE - 1);
184 } else {
185 timestr_ = NULL;
186 }
187}
188
189/** Copy constructor.
190 * @param t time to copy
191 */
193{
194 time_.tv_sec = t->time_.tv_sec;
195 time_.tv_usec = t->time_.tv_usec;
196 clock_ = t->clock_;
197 if (t->timestr_) {
198 timestr_ = (char *)malloc(TIMESTR_SIZE);
199 strncpy(timestr_, t->timestr_, TIMESTR_SIZE - 1);
200 } else {
201 timestr_ = NULL;
202 }
203}
204
205/** Destructor. */
207{
208 if (timestr_)
209 free(timestr_);
210}
211
212/** Convet time to seconds.
213 * Convert the stored time in a floating point number representing the
214 * number of seconds. For a time the integral part is the number of seconds
215 * since the epoch, for ranges you get the value as a float second.
216 * @return the time in seconds
217 */
218double
220{
221 return ((double)time_.tv_sec + (double)time_.tv_usec / 1000000.);
222}
223
224/** Convert the stored time into milli-seconds.
225 * @return the time in milli-seconds
226 */
227long
229{
230 return (time_.tv_sec * 1000 + (long)(time_.tv_usec / 1000));
231}
232
233/** Convert the stored time into micro-seconds.
234 * @return the time in micro-seconds
235 */
236long
238{
239 return (time_.tv_sec * 1000000 + time_.tv_usec);
240}
241
242/** Sets the time.
243 * @param tv set the time to this value
244 */
245void
246Time::set_time(const timeval *tv)
247{
248 time_.tv_sec = tv->tv_sec;
249 time_.tv_usec = tv->tv_usec;
250}
251
252/** Sets the time.
253 * @param sec seconds part of the time
254 * @param usec microseconds part of the time
255 */
256void
257Time::set_time(long int sec, long int usec)
258{
259 time_.tv_sec = sec;
260 time_.tv_usec = usec;
261}
262
263/** Sets the time.
264 * @param ms set the time to this value
265 */
266void
268{
269 time_.tv_sec = (time_t)(ms / 1000.0);
270 time_.tv_usec = (ms % 1000) * 1000;
271}
272
273/** Sets the time.
274 * @param s set the time to this value
275 */
276void
278{
279 time_.tv_sec = (time_t)floor(s);
280 time_.tv_usec = (suseconds_t)(s - time_.tv_sec) * 1000000;
281}
282
283/** Set time to given time.
284 * this is equivalent to operator+, but can be used in situations where
285 * the operator cannot be used (for example in Lua).
286 * @param t time to set to
287 */
288void
290{
291 *this = t;
292}
293
294/** Set time to given time.
295 * @param t time to set to
296 */
297void
299{
300 time_.tv_sec = t->time_.tv_sec;
301 time_.tv_usec = t->time_.tv_usec;
302}
303
304/** Set clock for this instance.
305 * @param clock clock to use from now on
306 */
307void
309{
310 if (clock == NULL)
311 throw NullPointerException("Clock may not be NULL");
312 clock_ = clock;
313}
314
315/** Add seconds.
316 * The effect is equivalent to operator+=(const double sec), but this
317 * can be used when the operator is not available (i.e. wrapper languages)
318 * and it does not return itself.
319 * @param seconds time in seconds to add
320 */
321void
322Time::add(double seconds)
323{
324 *this += seconds;
325}
326
327/** Operator that adds times.
328 * @param t the other summand
329 * @return the sum
330 */
331Time
332Time::operator+(const Time &t) const
333{
334 Time ret(0, 0);
335 if (time_.tv_usec + t.time_.tv_usec >= 1000000) {
336 ret.time_.tv_usec = time_.tv_usec + t.time_.tv_usec - 1000000;
337 ret.time_.tv_sec = time_.tv_sec + t.time_.tv_sec + 1;
338 } else {
339 ret.time_.tv_usec = time_.tv_usec + t.time_.tv_usec;
340 ret.time_.tv_sec = time_.tv_sec + t.time_.tv_sec;
341 }
342
343 return ret;
344}
345
346/** Operator that adds times.
347 * @param t the other summand
348 * @return the sum
349 */
350Time
351Time::operator+(const Time *t) const
352{
353 return *this + *t;
354}
355
356/** Operator that adds times.
357 * @param sec number of seconds to add
358 * @return the sum
359 */
360Time
361Time::operator+(const double sec) const
362{
363 Time ret(0, 0);
364 time_t sec_only = (time_t)floor(sec);
365 suseconds_t usec_only = (suseconds_t)roundf((sec - sec_only) * 1000000);
366 if ((time_.tv_usec + usec_only) >= 1000000) {
367 ret.time_.tv_usec = time_.tv_usec + usec_only - 1000000;
368 ret.time_.tv_sec = time_.tv_sec + sec_only + 1;
369 } else {
370 ret.time_.tv_usec = time_.tv_usec + usec_only;
371 ret.time_.tv_sec = time_.tv_sec + sec_only;
372 }
373
374 return ret;
375}
376
377/** Operator to add usec value.
378 * @param usec microseconds to add
379 * @return new resulting instance
380 */
381Time
382Time::operator+(const long int usec) const
383{
384 Time ret(0, 0);
385 if (time_.tv_usec + usec >= 1000000) {
386 //usec + time_.tv_usec might be more than 1 second
387 long int tmp_usec = time_.tv_usec + usec;
388 ret.time_.tv_usec = tmp_usec % 1000000;
389 ret.time_.tv_sec = time_.tv_sec + (tmp_usec / 1000000);
390 } else {
391 ret.time_.tv_sec = time_.tv_sec;
392 ret.time_.tv_usec += usec;
393 }
394
395 return ret;
396}
397
398/** Operator that substracts one Time from another.
399 * @param t the Time that is substracted
400 * @return the difference
401 */
402Time
403Time::operator-(const Time &t) const
404{
405 Time ret(0, 0);
406 if (time_.tv_usec < t.time_.tv_usec) {
407 ret.time_.tv_usec = 1000000 + time_.tv_usec - t.time_.tv_usec;
408 ret.time_.tv_sec = time_.tv_sec - t.time_.tv_sec - 1;
409 } else {
410 ret.time_.tv_usec = time_.tv_usec - t.time_.tv_usec;
411 ret.time_.tv_sec = time_.tv_sec - t.time_.tv_sec;
412 }
413
414 return ret;
415}
416
417/** Operator that substracts one Time from another.
418 * @param t the Time that is substracted
419 * @return the difference
420 */
421double
422Time::operator-(const Time *t) const
423{
424 return time_diff_sec(time_, t->time_);
425}
426
427/** Operator that subtracts some time.
428 * @param sec number of seconds to subtract
429 * @return the difference
430 */
431Time
432Time::operator-(const double sec) const
433{
434 Time ret(0, 0);
435 time_t sec_only = (time_t)floor(sec);
436 suseconds_t usec_only = (suseconds_t)roundf((sec - sec_only) * 1000000);
437 if (time_.tv_usec < usec_only) {
438 ret.time_.tv_usec = 1000000 + time_.tv_usec - usec_only;
439 ret.time_.tv_sec = time_.tv_sec - sec_only - 1;
440 } else {
441 ret.time_.tv_usec = time_.tv_usec - usec_only;
442 ret.time_.tv_sec = time_.tv_sec - sec_only;
443 }
444
445 return ret;
446}
447
448/** Operator that subtracts some time.
449 * @param usec number of microseconds to subtract
450 * @return the difference
451 */
452Time
453Time::operator-(const long int usec) const
454{
455 Time ret(0, 0);
456 time_t sec_only = usec / 1000000;
457 suseconds_t usec_only = usec % 1000000;
458 if (time_.tv_usec < usec_only) {
459 ret.time_.tv_usec = 1000000 + time_.tv_usec - usec_only;
460 ret.time_.tv_sec = time_.tv_sec - sec_only - 1;
461 } else {
462 ret.time_.tv_usec = time_.tv_usec - usec_only;
463 ret.time_.tv_sec = time_.tv_sec - sec_only;
464 }
465
466 return ret;
467}
468
469/** += operator
470 * @param t the other time
471 * @return reference to this instance
472 */
473Time &
475{
476 if (time_.tv_usec + t.time_.tv_usec >= 1000000) {
477 time_.tv_usec += t.time_.tv_usec - 1000000;
478 time_.tv_sec += t.time_.tv_sec + 1;
479 } else {
480 time_.tv_usec += t.time_.tv_usec;
481 time_.tv_sec += t.time_.tv_sec;
482 }
483
484 return *this;
485}
486
487/** += operator
488 * @param usec microseconds to add
489 * @return reference to this instance
490 */
491Time &
492Time::operator+=(const long int usec)
493{
494 if (time_.tv_usec + usec >= 1000000) {
495 //usec + time_.tv_usec might be more than 1 second
496 long int tmp_usec = time_.tv_usec + usec;
497 time_.tv_usec = tmp_usec % 1000000;
498 time_.tv_sec += tmp_usec / 1000000;
499 } else {
500 time_.tv_usec += usec;
501 }
502
503 return *this;
504}
505
506/** += operator for double seconds
507 * @param sec number of seconds to add
508 * @return the sum
509 */
510Time &
511Time::operator+=(const double sec)
512{
513 time_t sec_only = (time_t)floor(sec);
514 suseconds_t usec_only = (suseconds_t)roundf((sec - sec_only) * 1000000);
515 if ((time_.tv_usec + usec_only) >= 1000000) {
516 time_.tv_usec += usec_only - 1000000;
517 time_.tv_sec += sec_only + 1;
518 } else {
519 time_.tv_usec += usec_only;
520 time_.tv_sec += sec_only;
521 }
522
523 return *this;
524}
525
526/** -= operator.
527 * @param t the other time
528 * @return reference to this instance after subtraction
529 */
530Time &
532{
533 *this = *this - t;
534 return *this;
535}
536
537/** -= operator.
538 * @param sec seconds to subtract
539 * @return reference to this instance after subtraction
540 */
541Time &
542Time::operator-=(const double sec)
543{
544 *this = *this - sec;
545 return *this;
546}
547
548/** -= operator.
549 * @param usec microseconds to subtract
550 * @return reference to this instance after subtraction
551 */
552Time &
553Time::operator-=(const long int usec)
554{
555 *this = *this - usec;
556 return *this;
557}
558
559/** Assign operator.
560 * @param t time to assign to this instance
561 * @return reference to this instance
562 */
563Time &
565{
566 time_.tv_sec = t.time_.tv_sec;
567 time_.tv_usec = t.time_.tv_usec;
568 clock_ = t.clock_;
569 return *this;
570}
571
572/** Check equality of times.
573 * @param t time to compare to
574 * @return true if sec and usec of both times are the same, false otherwise
575 */
576bool
577Time::operator==(const Time &t) const
578{
579 return (time_.tv_sec == t.time_.tv_sec) && (time_.tv_usec == t.time_.tv_usec);
580}
581
582/** Check equality of times.
583 * @param t time to compare to
584 * @return true if sec and usec of both times are the same, false otherwise
585 */
586bool
587Time::operator==(const Time *t) const
588{
589 return (time_.tv_sec == t->time_.tv_sec) && (time_.tv_usec == t->time_.tv_usec);
590}
591
592/** Check inequality of times.
593 * @param t time to compare to
594 * @return true if sec or usec of both times are different, false otherwise
595 */
596bool
597Time::operator!=(const Time &t) const
598{
599 return (time_.tv_sec != t.time_.tv_sec) || (time_.tv_usec != t.time_.tv_usec);
600}
601
602/** Check inequality of times.
603 * @param t time to compare to
604 * @return true if sec or usec of both times are different, false otherwise
605 */
606bool
607Time::operator!=(const Time *t) const
608{
609 return (time_.tv_sec != t->time_.tv_sec) || (time_.tv_usec != t->time_.tv_usec);
610}
611
612/** Greater than operator.
613 * @param t time to compare to
614 * @return true if this time is greater than @p t, false otherwise
615 */
616bool
617Time::operator>(const Time &t) const
618{
619 return (time_.tv_sec > t.time_.tv_sec)
620 || ((time_.tv_sec == t.time_.tv_sec) && (time_.tv_usec > t.time_.tv_usec));
621}
622
623/** Greater than operator.
624 * @param t time to compare to
625 * @return true if this time is greater than @p t, false otherwise
626 */
627bool
628Time::operator>(const Time *t) const
629{
630 return (time_.tv_sec > t->time_.tv_sec)
631 || ((time_.tv_sec == t->time_.tv_sec) && (time_.tv_usec > t->time_.tv_usec));
632}
633
634/** Greater than or equal to operator.
635 * @param t time to compare to
636 * @return true if this time is greater than @p t, false otherwise
637 */
638bool
639Time::operator>=(const Time &t) const
640{
641 return (time_.tv_sec > t.time_.tv_sec)
642 || ((time_.tv_sec == t.time_.tv_sec) && (time_.tv_usec >= t.time_.tv_usec));
643}
644
645/** Greater than or equal to operator.
646 * @param t time to compare to
647 * @return true if this time is greater than @p t, false otherwise
648 */
649bool
650Time::operator>=(const Time *t) const
651{
652 return (time_.tv_sec > t->time_.tv_sec)
653 || ((time_.tv_sec == t->time_.tv_sec) && (time_.tv_usec >= t->time_.tv_usec));
654}
655
656/** Less than operator.
657 * @param t time to compare to
658 * @return true if this time is less than @p t, false otherwise
659 */
660bool
661Time::operator<(const Time &t) const
662{
663 return (time_.tv_sec < t.time_.tv_sec)
664 || ((time_.tv_sec == t.time_.tv_sec) && (time_.tv_usec < t.time_.tv_usec));
665}
666
667/** Less than operator.
668 * @param t time to compare to
669 * @return true if this time is less than @p t, false otherwise
670 */
671bool
672Time::operator<(const Time *t) const
673{
674 return (time_.tv_sec < t->time_.tv_sec)
675 || ((time_.tv_sec == t->time_.tv_sec) && (time_.tv_usec < t->time_.tv_usec));
676}
677
678/** Less than or equal to operator.
679 * @param t time to compare to
680 * @return true if this time is less than @p t, false otherwise
681 */
682bool
683Time::operator<=(const Time &t) const
684{
685 return (time_.tv_sec < t.time_.tv_sec)
686 || ((time_.tv_sec == t.time_.tv_sec) && (time_.tv_usec <= t.time_.tv_usec));
687}
688
689/** Less than or equal to operator.
690 * @param t time to compare to
691 * @return true if this time is less than @p t, false otherwise
692 */
693bool
694Time::operator<=(const Time *t) const
695{
696 return (time_.tv_sec < t->time_.tv_sec)
697 || ((time_.tv_sec == t->time_.tv_sec) && (time_.tv_usec <= t->time_.tv_usec));
698}
699
700/** Set this time to the current time.
701 * @return reference to this instance
702 */
703Time &
705{
706 if (NULL != clock_) {
707 clock_->get_time(&time_);
708 } else {
709 throw Exception("Clock not set, cannot stamp time");
710 }
711 return *this;
712}
713
714/** Set this time to the current system time.
715 * This bypasses any possibly registered time source. Use with care and only
716 * where you really need the system time.
717 * @return reference to this instance
718 */
719Time &
721{
722 if (NULL != clock_) {
723 clock_->get_systime(&time_);
724 } else {
725 throw Exception("Clock not set, cannot stamp time (systime)");
726 }
727 return *this;
728}
729
730/** Wait (sleep) for this time.
731 * This waits for as much time as this instance provides. Note that you have to
732 * make sure that you call this on a sensible time range. You probably do not want
733 * to wait for almost 40 years when passing a time point...
734 */
735void
737{
738 Time until, now;
739 until += *this;
740
741 // we want to release run status at least shortly
742 usleep(0);
743
744 long int remaining_usec = (until - now).in_usec();
745 while (remaining_usec > 0) {
746 usleep(remaining_usec);
747 now.stamp();
748 remaining_usec = (until - now).in_usec();
749 }
750}
751
752/** Wait (sleep) for this system time.
753 * This waits for as much time as this instance provides. Unlike wait() this
754 * method calculates the time in system time, althouh the main clock may run
755 * slower for example in a simulation. Note that you have to make sure that you
756 * call this on a sensible time range. You probably do not want to wait for
757 * almost 40 years when passing a time point...
758 */
759void
761{
762 Time until, now;
763
764 clock_->get_systime(until);
765 until += *this;
766
767 clock_->get_systime(now);
768
769 // we want to release run status at least shortly
770 usleep(0);
771
772 long int remaining_usec = (until - now).in_usec();
773 while (remaining_usec > 0) {
774 usleep(remaining_usec);
775 clock_->get_systime(now);
776 remaining_usec = (until - now).in_usec();
777 }
778}
779
780/** Output function.
781 * @return a pointer to a member containing a string represenation of
782 * the given time. If seconds is smaller than 1 billion it is assumed that
783 * this time represents a time range rather than a point in time and
784 * the time is formatted as seconds.microseconds, otherwise the time
785 * is formatted either via localtime() (if utc is false) or gmtime (if utc
786 * is true).
787 * @param utc true to get type formatted in UTC, otherwise local time
788 */
789const char *
790Time::str(bool utc) const
791{
792 // allocate time string if not done yet
793 if (!timestr_)
794 timestr_ = (char *)malloc(TIMESTR_SIZE);
795
796 // heuristic to distinguish times and time ranges
797 if (time_.tv_sec < 1000000000) {
798 snprintf(timestr_, TIMESTR_SIZE, "%li:%li", time_.tv_sec, (long)time_.tv_usec);
799 } else {
800 tm time_tm;
801 if (utc) {
802 gmtime_r(&(time_.tv_sec), &time_tm);
803 } else {
804 localtime_r(&(time_.tv_sec), &time_tm);
805 }
806 asctime_r(&time_tm, timestr_);
807 timestr_[strlen(timestr_) - 1] = 0;
808 }
809
810 return timestr_;
811}
812
813/** Output function.
814 * This is the thread-safe version of str().
815 * @param s pointer to a string of at least TIMESTR_SIZE bytes.
816 * @param utc true to get type formatted in UTC, otherwise local time
817 */
818void
819Time::str_r(char *s, bool utc)
820{
821 // heuristic to distinguish times and time ranges
822 if (time_.tv_sec < 1000000000) {
823 snprintf(s, TIMESTR_SIZE, "%li:%li", time_.tv_sec, (long)time_.tv_usec);
824 } else {
825 tm time_tm;
826 if (utc) {
827 gmtime_r(&(time_.tv_sec), &time_tm);
828 } else {
829 localtime_r(&(time_.tv_sec), &time_tm);
830 }
831 asctime_r(&time_tm, s);
832 s[strlen(s) - 1] = 0;
833 }
834}
835
836} // end namespace fawkes
This is supposed to be the central clock in Fawkes.
Definition: clock.h:35
void get_time(struct timeval *tv) const
Returns the time of the selected time source.
Definition: clock.cpp:161
static Clock * instance()
Clock initializer.
Definition: clock.cpp:63
void get_systime(struct timeval *tv) const
Returns the system time.
Definition: clock.cpp:215
Base class for exceptions in Fawkes.
Definition: exception.h:36
A NULL pointer was supplied where not allowed.
Definition: software.h:32
A class for handling time.
Definition: time.h:93
void set_clock(Clock *clock)
Set clock for this instance.
Definition: time.cpp:308
Time & operator=(const Time &t)
Assign operator.
Definition: time.cpp:564
~Time()
Destructor.
Definition: time.cpp:206
static const unsigned int TIMESTR_SIZE
Maximum size of string returned by str() and the minimum size of the string passwd to str_r().
Definition: time.h:196
Time & stamp()
Set this time to the current time.
Definition: time.cpp:704
void str_r(char *s, bool utc=false)
Output function.
Definition: time.cpp:819
bool operator>(const Time &t) const
Greater than operator.
Definition: time.cpp:617
void add(double seconds)
Add seconds.
Definition: time.cpp:322
void wait_systime()
Wait (sleep) for this system time.
Definition: time.cpp:760
void wait()
Wait (sleep) for this time.
Definition: time.cpp:736
Time & operator-=(const Time &t)
-= operator.
Definition: time.cpp:531
double in_sec() const
Convet time to seconds.
Definition: time.cpp:219
bool operator<=(const Time &t) const
Less than or equal to operator.
Definition: time.cpp:683
bool operator<(const Time &t) const
Less than operator.
Definition: time.cpp:661
bool operator!=(const Time &t) const
Check inequality of times.
Definition: time.cpp:597
Time & operator+=(const long int usec)
+= operator
Definition: time.cpp:492
bool operator==(const Time &t) const
Check equality of times.
Definition: time.cpp:577
bool operator>=(const Time &t) const
Greater than or equal to operator.
Definition: time.cpp:639
long in_usec() const
Convert the stored time into micro-seconds.
Definition: time.cpp:237
Time()
Constructor.
Definition: time.cpp:93
Time operator-(const Time &t) const
Operator that substracts one Time from another.
Definition: time.cpp:403
Time & stamp_systime()
Set this time to the current system time.
Definition: time.cpp:720
const char * str(bool utc=false) const
Output function.
Definition: time.cpp:790
void set_time(const timeval *tv)
Sets the time.
Definition: time.cpp:246
Time operator+(const double sec) const
Operator that adds times.
Definition: time.cpp:361
long in_msec() const
Convert the stored time into milli-seconds.
Definition: time.cpp:228
Fawkes library namespace.
const Time TIME_MAX
Instance of Time denoting the maximum value possible.
Definition: time.cpp:43
double time_diff_sec(const timeval &a, const timeval &b)
Calculate time difference of two time structs.
Definition: time.h:41
const Time TIME_MIN
Instance of Time denoting the minimum value possible.
Definition: time.cpp:48