ANNA Suite  2020b
Multipurpose development suite for Telco applications
Second.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_Second_hpp
10 #define anna_core_util_Second_hpp
11 
12 #include <string>
13 
14 #include <anna/config/defines.hpp>
16 
17 namespace anna {
18 
19 class Millisecond;
20 class Microsecond;
21 
25 class Second {
26 public:
27 #ifdef __anna64__
28  typedef S64 type_t;
29 #else
30  typedef int type_t;
31 #endif
32 
39  static const int DateTimeSizeString = 21;
40 
44  Second() : a_value(0) {;}
45 
50  explicit Second(const type_t value) : a_value(value) {;}
51 
56  Second(const Second& other) : a_value(other.a_value) {;}
57 
62  Second(const Millisecond& other);
63 
68  Second(const Microsecond& other);
69 
74  operator type_t () const { return a_value; }
75 
79  type_t& refValue() { return a_value; }
80 
81  Second& operator= (const type_t other) { a_value = other; return *this; }
82 
83  Second& operator= (const Second& other) { a_value = other.a_value; return *this; }
84 
85  Second& operator= (const Millisecond& other) ;
86 
87  Second& operator= (const Microsecond& other) ;
88 
89  bool operator== (const Second& other) const { return a_value == other.a_value; }
90 
91  bool operator== (const Millisecond& other) const ;
92 
93  bool operator== (const Microsecond& other) const ;
94 
95  bool operator!= (const Second& other) const { return a_value != other.a_value; }
96 
97  bool operator!= (const Millisecond& other) const ;
98 
99  bool operator!= (const Microsecond& other) const ;
100 
101  bool operator> (const Second& other) const { return a_value > other.a_value; }
102 
103  bool operator> (const Millisecond& other) const ;
104 
105  bool operator> (const Microsecond& other) const ;
106 
107  bool operator< (const Second& other) const { return a_value < other.a_value; }
108 
109  bool operator< (const Millisecond& other) const ;
110 
111  bool operator< (const Microsecond& other) const ;
112 
113  bool operator>= (const Second& other) const { return a_value >= other.a_value; }
114 
115  bool operator>= (const Millisecond& other) const { return (operator==(other) == true) ? true : operator>(other); }
116 
117  bool operator>= (const Microsecond& other) const { return (operator==(other) == true) ? true : operator>(other); }
118 
119  bool operator<= (const Second& other) const { return a_value <= other.a_value; }
120 
121  bool operator<= (const Millisecond& other) const { return (operator==(other) == true) ? true : operator<(other); }
122 
123  bool operator<= (const Microsecond& other) const { return (operator==(other) == true) ? true : operator<(other); }
124 
129  type_t getValue() const { return a_value; }
130 
138  std::string asDateTime(const char* format = "%d/%0m/%Y %T") const ;
139 
149  const char* asDateTime(char* result, const char* format = "%d/%0m/%Y %T") const ;
150 
155  std::string asString() const ;
156 
161  static Second getTime() ;
162 
168  static Second getLocalTime() ;
169 
175  static Second fromString(const std::string& value) noexcept(false);
176 
177 private:
178  type_t a_value;
179 
180  friend class Millisecond;
181  friend class Microsecond;
182 
183  friend class Second operator + (const Second& left, const Second& right) ;
184  friend class Second operator - (const Second& left, const Second& right) ;
185  friend class Second operator / (const Second& left, const Second& right) ;
186  friend class Second operator / (const Second& left, const int right) ;
187  friend class Second operator / (const Second& left, const unsigned int right) ;
188 };
189 
190 inline Second operator + (const Second& left, const Second& right)
191 {
192  return Second(left.a_value + right.a_value);
193 }
194 
195 inline Second operator - (const Second& left, const Second& right)
196 {
197  return Second(left.a_value - right.a_value);
198 }
199 
200 inline Second operator / (const Second& left, const Second& right)
201 {
202  return Second(left.a_value / right.a_value);
203 }
204 
205 inline Second operator / (const Second& left, const int right)
206 {
207  return Second(left.a_value / right);
208 }
209 
210 inline Second operator / (const Second& left, const unsigned int right)
211 {
212  return Second(left.a_value / right);
213 }
214 
215 }
216 
217 #endif
bool operator>=(const Second &other) const
Definition: Second.hpp:113
Definition: Millisecond.hpp:24
friend class Second operator/(const Second &left, const Second &right)
Definition: Second.hpp:200
static Second getLocalTime()
bool operator<(const Second &other) const
Definition: Second.hpp:107
std::string asDateTime(const char *format="%d/%0m/%Y %T") const
static const int DateTimeSizeString
Definition: Second.hpp:39
Definition: Second.hpp:25
std::string asString() const
int64_t S64
Definition: defines.hpp:84
friend class Second operator+(const Second &left, const Second &right)
Definition: Second.hpp:190
type_t & refValue()
Definition: Second.hpp:79
static Second getTime()
Second & operator=(const type_t other)
Definition: Second.hpp:81
bool operator>(const Second &other) const
Definition: Second.hpp:101
Second()
Definition: Second.hpp:44
static Second fromString(const std::string &value) noexcept(false)
Definition: app.hpp:12
bool operator!=(const Second &other) const
Definition: Second.hpp:95
friend class Second operator-(const Second &left, const Second &right)
Definition: Second.hpp:195
Second(const type_t value)
Definition: Second.hpp:50
int type_t
Definition: Second.hpp:30
type_t getValue() const
Definition: Second.hpp:129
bool operator<=(const Second &other) const
Definition: Second.hpp:119
Second(const Second &other)
Definition: Second.hpp:56
Definition: Microsecond.hpp:22
bool operator==(const Second &other) const
Definition: Second.hpp:89