ANNA Suite  2020b
Multipurpose development suite for Telco applications
Millisecond.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7 
8 
9 #ifndef anna_core_util_Millisecond_hpp
10 #define anna_core_util_Millisecond_hpp
11 
12 #include <time.h>
13 
14 #include <string>
15 
18 
19 namespace anna {
20 
21 class Second;
22 class Microsecond;
23 
24 class Millisecond {
25 public:
26  typedef S64 type_t;
27 
31  Millisecond() : a_value(0) {;}
32 
37  explicit Millisecond(const type_t value) : a_value(value) {;}
38 
43  Millisecond(const Millisecond& other) : a_value(other.a_value) {;}
44 
49  Millisecond(const Second& other);
50 
55  Millisecond(const Microsecond& other);
56 
61  operator type_t () const { return a_value; }
62 
66  type_t& refValue() { return a_value; }
67 
68  Millisecond& operator= (const type_t other) { a_value = other; return *this; }
69 
70  Millisecond& operator= (const Millisecond& other) { a_value = other.a_value; return *this; }
71 
72  Millisecond& operator= (const Second& other) ;
73 
74  Millisecond& operator= (const Microsecond& other) ;
75 
76  bool operator== (const Millisecond& other) const { return a_value == other.a_value; }
77 
78  bool operator== (const Second& other) const ;
79 
80  bool operator== (const Microsecond& other) const ;
81 
82  bool operator!= (const Millisecond& other) const { return a_value != other.a_value; }
83 
84  bool operator!= (const Second& other) const ;
85 
86  bool operator!= (const Microsecond& other) const ;
87 
88  bool operator> (const Millisecond& other) const { return a_value > other.a_value; }
89 
90  bool operator> (const Second& other) const ;
91 
92  bool operator> (const Microsecond& other) const ;
93 
94  bool operator< (const Millisecond& other) const { return a_value < other.a_value; }
95 
96  bool operator< (const Second& other) const ;
97 
98  bool operator< (const Microsecond& other) const ;
99 
100  bool operator>= (const Millisecond& other) const { return a_value >= other.a_value; }
101 
102  bool operator>= (const Second& other) const { return (operator==(other) == true) ? true : operator>(other); }
103 
104  bool operator>= (const Microsecond& other) const { return (operator==(other) == true) ? true : operator>(other); }
105 
106  bool operator<= (const Millisecond& other) const { return a_value <= other.a_value; }
107 
108  bool operator<= (const Second& other) const { return (operator==(other) == true) ? true : operator<(other); }
109 
110  bool operator<= (const Microsecond& other) const { return (operator==(other) == true) ? true : operator<(other); }
111 
112  Millisecond& operator+= (const Millisecond& other) { a_value += other.a_value; return *this; }
113 
114  Millisecond& operator-= (const Millisecond& other) {(a_value > other.a_value) ? (a_value -= other.a_value) : (a_value = 0); return *this; }
115 
120  type_t getValue() const { return a_value; }
121 
129  timeval* getTimeVal(timeval& tv) const ;
130 
135  static Millisecond getTime() ;
136 
141  std::string asString() const ;
142 
148  static Millisecond fromString(const std::string& value) noexcept(false);
149 
150 private:
151  type_t a_value;
152 
153  friend class Second;
154  friend class Microsecond;
155 
156  friend class Millisecond operator / (const Millisecond& left, const Millisecond& right) ;
157  friend class Millisecond operator + (const Millisecond& left, const Millisecond& right) ;
158  friend class Millisecond operator - (const Millisecond& left, const Millisecond& right) ;
159  friend class Millisecond operator / (const Millisecond& left, const int right) ;
160  friend class Millisecond operator / (const Millisecond& left, const unsigned int right) ;
161  friend class Millisecond operator *(const Millisecond& left, const int right) ;
162 };
163 
164 inline Millisecond operator / (const Millisecond& left, const Millisecond& right)
165 {
166  return Millisecond(left.a_value / right.a_value);
167 }
168 
169 inline Millisecond operator + (const Millisecond& left, const Millisecond& right)
170 {
171  return Millisecond(left.a_value + right.a_value);
172 }
173 
174 inline Millisecond operator - (const Millisecond& left, const Millisecond& right)
175 {
176  return Millisecond(left.a_value - right.a_value);
177 }
178 
179 inline Millisecond operator / (const Millisecond& left, const int right)
180 {
181  return Millisecond(left.a_value / right);
182 }
183 
184 inline Millisecond operator / (const Millisecond& left, const unsigned int right)
185 {
186  return Millisecond(left.a_value / right);
187 }
188 
189 inline Millisecond operator *(const Millisecond& left, const int right)
190 {
191  return Millisecond(left.a_value * right);
192 }
193 
194 }
195 
196 #endif
static Millisecond getTime()
bool operator!=(const Millisecond &other) const
Definition: Millisecond.hpp:82
Definition: Millisecond.hpp:24
bool operator<=(const Millisecond &other) const
Definition: Millisecond.hpp:106
Millisecond(const Millisecond &other)
Definition: Millisecond.hpp:43
friend class Millisecond operator*(const Millisecond &left, const int right)
Definition: Millisecond.hpp:189
Definition: Second.hpp:25
bool operator==(const Millisecond &other) const
Definition: Millisecond.hpp:76
timeval * getTimeVal(timeval &tv) const
std::string asString() const
int64_t S64
Definition: defines.hpp:84
Millisecond & operator+=(const Millisecond &other)
Definition: Millisecond.hpp:112
type_t & refValue()
Definition: Millisecond.hpp:66
Millisecond()
Definition: Millisecond.hpp:31
Millisecond & operator=(const type_t other)
Definition: Millisecond.hpp:68
friend class Millisecond operator/(const Millisecond &left, const Millisecond &right)
Definition: Millisecond.hpp:164
type_t getValue() const
Definition: Millisecond.hpp:120
bool operator>(const Millisecond &other) const
Definition: Millisecond.hpp:88
friend class Millisecond operator-(const Millisecond &left, const Millisecond &right)
Definition: Millisecond.hpp:174
Definition: app.hpp:12
S64 type_t
Definition: Millisecond.hpp:26
Millisecond & operator-=(const Millisecond &other)
Definition: Millisecond.hpp:114
Millisecond(const type_t value)
Definition: Millisecond.hpp:37
friend class Millisecond operator+(const Millisecond &left, const Millisecond &right)
Definition: Millisecond.hpp:169
bool operator>=(const Millisecond &other) const
Definition: Millisecond.hpp:100
bool operator<(const Millisecond &other) const
Definition: Millisecond.hpp:94
Definition: Microsecond.hpp:22
static Millisecond fromString(const std::string &value) noexcept(false)