ANNA Suite  2020b
Multipurpose development suite for Telco applications
DelayMeter.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_DelayMeter_hpp
10 #define anna_core_util_DelayMeter_hpp
11 
12 #include <string>
13 
14 namespace anna {
15 
41 template <class _TimeUnit> class DelayMeter {
42 public:
47  DelayMeter() { a_timestamp = _TimeUnit::getTime(); }
48 
54  DelayMeter(const DelayMeter& other) : a_timestamp(other.a_timestamp), a_topReference(other.a_topReference) { ;}
55 
62  void setControlPoint() {
63  a_timestamp = _TimeUnit::getTime();
65  }
66 
75  void setControlPoint(const _TimeUnit& timestamp) {
76  a_timestamp = timestamp;
78  }
79 
92  void setTopReference(const _TimeUnit& topReference) { a_topReference = topReference; }
93 
97  void clearTopReference() { a_topReference = _TimeUnit(0); }
98 
102  void clear() { a_timestamp = 0; }
103 
112  _TimeUnit getValue() const {
113  a_now = (a_topReference == _TimeUnit(0)) ? _TimeUnit::getTime() : a_topReference;
114  return (a_now > a_timestamp) ? (a_now - a_timestamp) : _TimeUnit(0);
115  }
116 
126  _TimeUnit getValue(const _TimeUnit& now) const {
127  return ((a_now = now) > a_timestamp) ? (a_now - a_timestamp) : _TimeUnit(0);
128  }
129 
134  const _TimeUnit& getNow() const { return a_now; }
135 
140  DelayMeter& operator= (const DelayMeter& other) { a_timestamp = other.a_timestamp; a_topReference = other.a_topReference; return *this; }
141 
147  bool operator> (const _TimeUnit& left) const { return getValue() > left; }
148 
154  bool operator< (const _TimeUnit& left) const { return getValue() < left; }
155 
160  std::string asString() const { return getValue().asString(); }
161 
167  std::string asDebugString(const char* whatis) const {
168  std::string result(whatis);
169  result += " { TopReference: ";
170  result += a_topReference.asString();
171  result += " | TimeStamp: ";
172  result += a_timestamp.asString();
173  result += " | Now: ";
174  result += a_now.asString();
175  return result += " }";
176  }
177 
178 private:
179  _TimeUnit a_topReference;
180  _TimeUnit a_timestamp;
181  mutable _TimeUnit a_now;
182 };
183 
184 }
185 
186 #endif
187 
188 
void setTopReference(const _TimeUnit &topReference)
Definition: DelayMeter.hpp:92
Definition: DelayMeter.hpp:41
_TimeUnit getValue(const _TimeUnit &now) const
Definition: DelayMeter.hpp:126
std::string asString() const
Definition: DelayMeter.hpp:160
void setControlPoint(const _TimeUnit &timestamp)
Definition: DelayMeter.hpp:75
DelayMeter(const DelayMeter &other)
Definition: DelayMeter.hpp:54
_TimeUnit getValue() const
Definition: DelayMeter.hpp:112
DelayMeter & operator=(const DelayMeter &other)
Definition: DelayMeter.hpp:140
void clear()
Definition: DelayMeter.hpp:102
void setControlPoint()
Definition: DelayMeter.hpp:62
bool operator>(const _TimeUnit &left) const
Definition: DelayMeter.hpp:147
DelayMeter()
Definition: DelayMeter.hpp:47
Definition: app.hpp:12
bool operator<(const _TimeUnit &left) const
Definition: DelayMeter.hpp:154
void clearTopReference()
Definition: DelayMeter.hpp:97
const _TimeUnit & getNow() const
Definition: DelayMeter.hpp:134
std::string asDebugString(const char *whatis) const
Definition: DelayMeter.hpp:167