ANNA Suite  2020b
Multipurpose development suite for Telco applications
Microsecond.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_Microsecond_hpp
10 #define anna_core_util_Microsecond_hpp
11 
12 #include <string>
13 
16 
17 namespace anna {
18 
19 class Millisecond;
20 class Second;
21 
22 class Microsecond {
23 public:
24  typedef S64 type_t;
25 
29  Microsecond() : a_value(0) {;}
30 
35  explicit Microsecond(const type_t value) : a_value(value) {;}
36 
41  Microsecond(const Microsecond& other) : a_value(other.a_value) {;}
42 
47  Microsecond(const Millisecond& other);
48 
53  Microsecond(const Second& other);
54 
59  operator type_t () const { return a_value; }
60 
64  type_t& refValue() { return a_value; }
65 
66  Microsecond& operator= (const Microsecond& other) { a_value = other.a_value; return *this; }
67 
68  Microsecond& operator= (const Millisecond& other) ;
69 
70  Microsecond& operator= (const Second& other) ;
71 
72  bool operator== (const Microsecond& other) const { return a_value == other.a_value; }
73 
74  bool operator== (const Millisecond& other) const ;
75 
76  bool operator== (const Second& other) const ;
77 
78  bool operator!= (const Microsecond& other) const { return a_value != other.a_value; }
79 
80  bool operator!= (const Millisecond& other) const ;
81 
82  bool operator!= (const Second& other) const ;
83 
84  bool operator> (const Microsecond& other) const { return a_value > other.a_value; }
85 
86  bool operator> (const Millisecond& other) const ;
87 
88  bool operator> (const Second& other) const ;
89 
90  bool operator< (const Microsecond& other) const { return a_value < other.a_value; }
91 
92  bool operator< (const Millisecond& other) const ;
93 
94  bool operator< (const Second& other) const ;
95 
96  bool operator>= (const Microsecond& other) const { return a_value >= other.a_value; }
97 
98  bool operator>= (const Millisecond& other) const { return (operator==(other) == true) ? true : operator>(other); }
99 
100  bool operator>= (const Second& other) const { return (operator==(other) == true) ? true : operator>(other); }
101 
102  bool operator<= (const Microsecond& other) const { return a_value <= other.a_value; }
103 
104  bool operator<= (const Millisecond& other) const { return (operator==(other) == true) ? true : operator<(other); }
105 
106  bool operator<= (const Second& other) const { return (operator==(other) == true) ? true : operator<(other); }
107 
108  Microsecond& operator+= (const Microsecond& other) { a_value += other.a_value; return *this; }
109  Microsecond& operator*= (const int& value) { a_value *= value; return *this; }
110 
115  type_t getValue() const { return a_value; }
116 
121  static Microsecond getTime() ;
122 
127  std::string asString() const ;
128 
134  static Microsecond fromString(const std::string& value) noexcept(false);
135 
136 private:
137  type_t a_value;
138 
139  friend class Millisecond;
140  friend class Second;
141 
142  friend class Microsecond operator - (const Microsecond& left, const Microsecond& right) ;
143  friend class Microsecond operator + (const Microsecond& left, const Microsecond& right) ;
144  friend class Microsecond operator / (const Microsecond& left, const Microsecond& right) ;
145  friend class Microsecond operator / (const Microsecond& left, const int right) ;
146  friend class Microsecond operator / (const Microsecond& left, const unsigned int right) ;
147 };
148 
149 inline Microsecond operator - (const Microsecond& left, const Microsecond& right)
150 {
151  return Microsecond(left.a_value - right.a_value);
152 }
153 
154 inline Microsecond operator + (const Microsecond& left, const Microsecond& right)
155 {
156  return Microsecond(left.a_value + right.a_value);
157 }
158 
159 inline Microsecond operator / (const Microsecond& left, const Microsecond& right)
160 {
161  return Microsecond(left.a_value / right.a_value);
162 }
163 
164 inline Microsecond operator / (const Microsecond& left, const int right)
165 {
166  return Microsecond(left.a_value / right);
167 }
168 
169 inline Microsecond operator / (const Microsecond& left, const unsigned int right)
170 {
171  return Microsecond(left.a_value / right);
172 }
173 
174 }
175 
176 #endif
Definition: Millisecond.hpp:24
S64 type_t
Definition: Microsecond.hpp:24
bool operator==(const Microsecond &other) const
Definition: Microsecond.hpp:72
bool operator>(const Microsecond &other) const
Definition: Microsecond.hpp:84
Definition: Second.hpp:25
type_t & refValue()
Definition: Microsecond.hpp:64
bool operator>=(const Microsecond &other) const
Definition: Microsecond.hpp:96
int64_t S64
Definition: defines.hpp:84
bool operator!=(const Microsecond &other) const
Definition: Microsecond.hpp:78
friend class Microsecond operator+(const Microsecond &left, const Microsecond &right)
Definition: Microsecond.hpp:154
Microsecond(const Microsecond &other)
Definition: Microsecond.hpp:41
Microsecond & operator*=(const int &value)
Definition: Microsecond.hpp:109
friend class Microsecond operator/(const Microsecond &left, const Microsecond &right)
Definition: Microsecond.hpp:159
Microsecond(const type_t value)
Definition: Microsecond.hpp:35
static Microsecond getTime()
bool operator<(const Microsecond &other) const
Definition: Microsecond.hpp:90
static Microsecond fromString(const std::string &value) noexcept(false)
Definition: app.hpp:12
friend class Microsecond operator-(const Microsecond &left, const Microsecond &right)
Definition: Microsecond.hpp:149
std::string asString() const
Microsecond & operator=(const Microsecond &other)
Definition: Microsecond.hpp:66
bool operator<=(const Microsecond &other) const
Definition: Microsecond.hpp:102
Microsecond & operator+=(const Microsecond &other)
Definition: Microsecond.hpp:108
Microsecond()
Definition: Microsecond.hpp:29
type_t getValue() const
Definition: Microsecond.hpp:115
Definition: Microsecond.hpp:22