Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Time.h
1 /*
2  * Time class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2020, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef INCLUDE_ELM_UTIL_TIME_H_
22 #define INCLUDE_ELM_UTIL_TIME_H_
23 
24 #include <elm/types.h>
25 #include <elm/io/Output.h>
26 
27 namespace elm {
28 
29 class Time {
30 public:
31  const static t::int64
32  ONE_MS = 1000,
33  ONE_S = ONE_MS * 1000,
34  ONE_M = ONE_S * 60,
35  ONE_H = ONE_M * 60,
36  ONE_D = ONE_H * 24,
37  ONE_Y = ONE_D * 365;
38 
39  inline Time(): _t(0) { }
40  inline Time(int t): _t(t) { }
41  inline Time(t::int64 t): _t(t) { }
42  inline Time(t::uint64 t): _t(t) { }
43  inline Time(const Time& t): _t(t._t) { }
44 
45  inline t::int64 time() const { return _t; }
46  inline t::int64 micros() const { return _t; }
47  inline t::int64 millis() const { return _t / ONE_MS; }
48  inline t::int64 seconds() const { return _t / ONE_S; }
49  inline t::int64 mins() const { return _t / ONE_M; }
50  inline t::int64 hours() const { return _t / ONE_H; }
51  inline t::int64 days() const { return _t / ONE_D; }
52  inline t::int64 years() const { return _t / ONE_Y; }
53 
54  inline Time operator+(const Time& t) const { return _t + t._t; }
55  inline Time operator-(const Time& t) const { return _t - t._t; }
56  inline Time operator*(int n) const { return _t * n; }
57  inline Time operator/(const Time& t) const { return _t / t._t; }
58 
59  inline bool operator==(const Time& t) const { return _t == t._t; }
60  inline bool operator!=(const Time& t) const { return _t != t._t; }
61  inline bool operator<(const Time& t) const { return _t < t._t; }
62  inline bool operator<=(const Time& t) const { return _t <= t._t; }
63  inline bool operator>(const Time& t) const { return _t > t._t; }
64  inline bool operator>=(const Time& t) const { return _t >= t._t; }
65 
66 private:
67  t::int64 _t;
68 };
69 io::Output& operator<<(io::Output& out, const Time& t);
70 
71 }; // elm
72 
73 #endif /* INCLUDE_ELM_UTIL_TIME_H_ */
elm::Time::micros
t::int64 micros() const
Definition: Time.h:46
elm::t::out
typename type_info< T >::out_t out
Definition: type_info.h:284
elm::Time::Time
Time(const Time &t)
Definition: Time.h:43
elm::Time::ONE_S
const static t::int64 ONE_S
Definition: Time.h:33
elm::Time::Time
Time(t::uint64 t)
Definition: Time.h:42
elm::operator<<
AutoString & operator<<(CString str, const T &value)
Definition: AutoString.h:75
elm::Time::ONE_H
const static t::int64 ONE_H
Definition: Time.h:35
elm::Time::ONE_MS
const static t::int64 ONE_MS
Definition: Time.h:32
elm::Time::Time
Time()
Definition: Time.h:39
elm::Time::ONE_M
const static t::int64 ONE_M
Definition: Time.h:34
elm::t::int64
long int64
Definition: arch.h:32
elm::Time::operator!=
bool operator!=(const Time &t) const
Definition: Time.h:60
elm::Time::operator<
bool operator<(const Time &t) const
Definition: Time.h:61
elm::Time::operator-
Time operator-(const Time &t) const
Definition: Time.h:55
elm::Time::operator/
Time operator/(const Time &t) const
Definition: Time.h:57
elm::Time::ONE_Y
const static t::int64 ONE_Y
Definition: Time.h:37
elm::Time::operator==
bool operator==(const Time &t) const
Definition: Time.h:59
elm::Time::mins
t::int64 mins() const
Definition: Time.h:49
elm::Time::time
t::int64 time() const
Definition: Time.h:45
elm::Time
Definition: Time.h:29
elm::Time::millis
t::int64 millis() const
Definition: Time.h:47
elm
Definition: adapter.h:26
elm::t::uint64
unsigned long uint64
Definition: arch.h:33
elm::Time::ONE_D
const static t::int64 ONE_D
Definition: Time.h:36
elm::Time::operator*
Time operator*(int n) const
Definition: Time.h:56
elm::Time::years
t::int64 years() const
Definition: Time.h:52
elm::Time::Time
Time(t::int64 t)
Definition: Time.h:41
elm::Time::operator+
Time operator+(const Time &t) const
Definition: Time.h:54
elm::Time::hours
t::int64 hours() const
Definition: Time.h:50
elm::Time::operator>=
bool operator>=(const Time &t) const
Definition: Time.h:64
elm::Time::Time
Time(int t)
Definition: Time.h:40
elm::Time::days
t::int64 days() const
Definition: Time.h:51
elm::Time::operator<=
bool operator<=(const Time &t) const
Definition: Time.h:62
elm::Time::operator>
bool operator>(const Time &t) const
Definition: Time.h:63
elm::Time::seconds
t::int64 seconds() const
Definition: Time.h:48