mn_timespan.hpp
Go to the documentation of this file.
1 
19 #ifndef _MINLIB_b7a90cc_ab5c_11eb_aa97_e9108ec71670_H__
20 #define _MINLIB_b7a90cc_ab5c_11eb_aa97_e9108ec71670_H__
21 
22 #include "mn_config.hpp"
23 
24 #include <stdint.h>
25 #include <time.h>
26 
27 #include "mn_algorithm.hpp"
28 
29 
30 namespace mn {
31 
36  public:
37  using time_type = int64_t;
38  using int_type= uint64_t;
40 
45 
50 
54  basic_timespan(struct timeval& val);
55 
59  basic_timespan(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t microSeconds = 0);
60 
64  basic_timespan(const self_type& other);
65 
66 
70  uint16_t get_days() const;
71 
75  uint8_t get_hours() const;
76 
80  uint8_t get_minutes() const;
81 
85  uint8_t get_seconds() const;
86 
90  uint16_t get_milliseconds() const;
91 
95  int_type get_microseconds() const;
96 
97 
101  int_type get_total_hours() const;
102 
106  int_type get_total_minutes() const;
107 
111  int_type get_total_seconds() const;
112 
117 
122 
123 
124  self_type& operator = (const self_type& timespan);
125 
126  self_type& operator = (time_type microseconds);
127 
128  self_type& operator = (struct timeval val);
129 
130 
131  bool operator == (const self_type& ts) const
132  { return m_timeSpan == ts.m_timeSpan; }
133 
134  bool operator == (time_type microSeconds) const
135  { return m_timeSpan == microSeconds; }
136 
137  bool operator != (const self_type& ts) const
138  { return m_timeSpan != ts.m_timeSpan; }
139 
140  bool operator != (time_type microSeconds) const
141  { return m_timeSpan != microSeconds; }
142 
143 
144  bool operator > (const self_type& ts) const
145  { return m_timeSpan > ts.m_timeSpan; }
146 
147  bool operator > (time_type microSeconds) const
148  { return m_timeSpan > microSeconds; }
149 
150  bool operator >= (const self_type& ts) const
151  { return m_timeSpan >= ts.m_timeSpan; }
152 
153  bool operator >= (time_type microSeconds) const
154  { return m_timeSpan >= microSeconds; }
155 
156  bool operator < (const self_type& ts) const
157  { return m_timeSpan < ts.m_timeSpan; }
158 
159  bool operator < (time_type microSeconds) const
160  { return m_timeSpan < microSeconds; }
161 
162  bool operator <= (const self_type& ts) const
163  { return m_timeSpan <= ts.m_timeSpan; }
164 
165  bool operator <= (time_type microSeconds) const
166  { return m_timeSpan <= microSeconds; }
167 
168 
170  { m_timeSpan += other.m_timeSpan; return *this; }
171 
173  { m_timeSpan += ms; return *this; }
174 
176  { m_timeSpan -= other.m_timeSpan; return *this; }
177 
179  { m_timeSpan -= ms; return *this; }
180 
181  self_type operator + (const self_type& other) const
182  { return self_type(m_timeSpan + other.m_timeSpan); }
183 
184  self_type operator - (const self_type& other) const
185  { return self_type(m_timeSpan - other.m_timeSpan); }
186 
188  { return self_type(m_timeSpan + ms); }
189 
191  { return self_type(m_timeSpan - ms); }
192 
197  static basic_timespan now();
198  public:
202  void swap(self_type& other) {
204  }
205 
209  self_type& assign(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t microSeconds);
210 
214  self_type& assign(struct timeval val);
215  public:
216  static basic_timespan from_ticks(const unsigned int& ticks);
217  time_type to_ticks() const;
218  private:
223  };
224 
226 
227  inline void swap(timespan_t& s1, timespan_t& s2) {
228  s1.swap(s2);
229  }
230 }
231 
232 #endif // _MINLIB_b7a90cc_ab5c_11eb_aa97_e9108ec71670_H__
This class represents a time span (using microseconds)
Definition: mn_timespan.hpp:35
basic_timespan self_type
Definition: mn_timespan.hpp:39
int_type get_total_seconds() const
Get the total number of seconds.
Definition: mn_timespan.cpp:177
uint8_t get_seconds() const
Get the number of (0 to 59) seconds.
Definition: mn_timespan.cpp:142
basic_timespan()
Construct a new time span and initializes it to zero.
Definition: mn_timespan.cpp:63
self_type operator+(const self_type &other) const
Definition: mn_timespan.hpp:181
self_type & operator=(const self_type &timespan)
Definition: mn_timespan.cpp:198
bool operator==(const self_type &ts) const
Definition: mn_timespan.hpp:131
time_type to_ticks() const
Definition: mn_timespan.cpp:108
uint16_t get_days() const
Get the number of days.
Definition: mn_timespan.cpp:121
time_type m_timeSpan
Definition: mn_timespan.hpp:222
bool operator>(const self_type &ts) const
Definition: mn_timespan.hpp:144
self_type operator-(const self_type &other) const
Definition: mn_timespan.hpp:184
bool operator!=(const self_type &ts) const
Definition: mn_timespan.hpp:137
int_type get_total_milliseconds() const
Get the total number of milliseconds.
Definition: mn_timespan.cpp:184
uint8_t get_hours() const
Get the number of (0 to 23) hours.
Definition: mn_timespan.cpp:128
int_type get_microseconds() const
Get the number of microseconds.
Definition: mn_timespan.cpp:156
bool operator<=(const self_type &ts) const
Definition: mn_timespan.hpp:162
uint64_t int_type
Definition: mn_timespan.hpp:38
static basic_timespan from_ticks(const unsigned int &ticks)
Definition: mn_timespan.cpp:101
self_type & operator-=(const self_type &other)
Definition: mn_timespan.hpp:175
int_type get_total_microseconds() const
Get the total number of microseconds.
Definition: mn_timespan.cpp:191
self_type & assign(uint16_t days, uint8_t hours, uint8_t minutes, uint8_t seconds, uint16_t microSeconds)
Assigns a new time span.
Definition: mn_timespan.cpp:221
bool operator<(const self_type &ts) const
Definition: mn_timespan.hpp:156
uint8_t get_minutes() const
Get the number of (0 to 59) minutes.
Definition: mn_timespan.cpp:135
int_type get_total_hours() const
Get the total number of hours.
Definition: mn_timespan.cpp:163
static basic_timespan now()
Get the current time.
Definition: mn_timespan.cpp:91
int_type get_total_minutes() const
Get the total number of minutes.
Definition: mn_timespan.cpp:170
bool operator>=(const self_type &ts) const
Definition: mn_timespan.hpp:150
void swap(self_type &other)
Swap this time span with a other time span.
Definition: mn_timespan.hpp:202
int64_t time_type
Definition: mn_timespan.hpp:37
self_type & operator+=(const self_type &other)
Definition: mn_timespan.hpp:169
uint16_t get_milliseconds() const
Get the number of milliseconds.
Definition: mn_timespan.cpp:149
Basic algorithmens This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniT...
Definition: mn_allocator_typetraits.hpp:25
void swap(TAssignable &a, TAssignable &b)
Definition: mn_algorithm.hpp:312