Image Component Library (ICL)
Time.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLUtils/src/ICLUtils/Time.h **
10 ** Module : ICLUtils **
11 ** Authors: Christof Elbrechter, Robert Haschke **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #include <ICLUtils/CompatMacros.h>
32 #include <string>
33 #include <iostream>
34 #include <stdint.h>
35 
36 // **********************************************************************
37 //
38 // Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
39 //
40 // This copy of Ice is licensed to you under the terms described in the
41 // ICE_LICENSE file included in this distribution.
42 //
43 // **********************************************************************
44 
45 #pragma once
46 
47 
48 namespace icl{
49  namespace utils{
50 
53  public:
54 
56  typedef int64_t value_type;
57 
58  // undefined time: 0
59  static const Time null;
60 
61  Time();
62 
64 
65  // No copy constructor and assignment operator necessary. The
66  // automatically generated copy constructor and assignment
67  // operator do the right thing.
68 
69  static Time now();
70  static Time seconds(value_type);
71  static Time milliSeconds(value_type);
72  static Time microSeconds(value_type);
73 
74  value_type toSeconds() const;
75  value_type toMilliSeconds() const;
76  value_type toMicroSeconds() const;
77 
78  double toSecondsDouble() const;
79  double toMilliSecondsDouble() const;
80  double toMicroSecondsDouble() const;
81 
82  std::string toString() const;
83 
85 
96  std::string toStringFormated(const std::string &pattern, unsigned int bufferSize=32, bool zeropadded = false) const;
97 
98  //xcf4cis stuff
99  Time age() const {
100  return Time::microSeconds(Time::now().m_usec - m_usec);
101  }
102 
104  inline std::string getAgeString() const{
105  return age().toString();
106  }
107 
109 
115  inline void showAge(const std::string &title="") const{
116  std::cout << title << ":" << age().toMilliSecondsDouble() << "ms" << std::endl;
117  }
118 
120  inline void printAge(const std::string &title="") const {
121  showAge(title);
122  }
123 
124 
125  Time operator-() const
126  {
127  return Time(-m_usec);
128  }
129 
130  Time operator-(const Time& rhs) const
131  {
132  return Time(m_usec - rhs.m_usec);
133  }
134 
135  Time operator+(const Time& rhs) const
136  {
137  return Time(m_usec + rhs.m_usec);
138  }
139 
140  Time& operator+=(const Time& rhs)
141  {
142  m_usec += rhs.m_usec;
143  return *this;
144  }
145 
146  Time& operator-=(const Time& rhs)
147  {
148  m_usec -= rhs.m_usec;
149  return *this;
150  }
151 
152  bool operator<(const Time& rhs) const
153  {
154  return m_usec < rhs.m_usec;
155  }
156 
157  bool operator<=(const Time& rhs) const
158  {
159  return m_usec <= rhs.m_usec;
160  }
161 
162  bool operator>(const Time& rhs) const
163  {
164  return m_usec > rhs.m_usec;
165  }
166 
167  bool operator>=(const Time& rhs) const
168  {
169  return m_usec >= rhs.m_usec;
170  }
171 
172  bool operator==(const Time& rhs) const
173  {
174  return m_usec == rhs.m_usec;
175  }
176 
177  bool operator!=(const Time& rhs) const
178  {
179  return m_usec != rhs.m_usec;
180  }
181 
182  Time& operator*=(const Time& rhs)
183  {
184  m_usec *= rhs.m_usec;
185  return *this;
186  }
187 
188  Time operator*(const Time& rhs) const
189  {
190  Time t;
191  t.m_usec = m_usec * rhs.m_usec;
192  return t;
193  }
194 
195  Time& operator/=(const Time& rhs)
196  {
197  m_usec /= rhs.m_usec;
198  return *this;
199  }
200 
201  Time operator/(const Time& rhs) const
202  {
203  Time t;
204  t.m_usec = m_usec / rhs.m_usec;
205  return t;
206  }
207 
208  Time& operator*=(int rhs)
209  {
210  m_usec *= rhs;
211  return *this;
212  }
213 
214  Time operator*(int rhs) const
215  {
216  Time t;
217  t.m_usec = m_usec * rhs;
218  return t;
219  }
220 
221  Time& operator/=(int rhs)
222  {
223  m_usec /= rhs;
224  return *this;
225  }
226 
227  Time operator/(int rhs) const
228  {
229  Time t;
230  t.m_usec = m_usec / rhs;
231  return t;
232  }
233 
235  {
236  m_usec *= rhs;
237  return *this;
238  }
239 
241  {
242  Time t;
243  t.m_usec = m_usec * rhs;
244  return t;
245  }
246 
248  {
249  m_usec /= rhs;
250  return *this;
251  }
252 
254  {
255  Time t;
256  t.m_usec = m_usec / rhs;
257  return t;
258  }
259 
260  Time& operator*=(double rhs)
261  {
262  m_usec = static_cast<value_type>(static_cast<double>(m_usec) * rhs);
263  return *this;
264  }
265 
266  Time operator*(double rhs) const
267  {
268  Time t;
269  t.m_usec = static_cast<value_type>(static_cast<double>(m_usec) * rhs);
270  return t;
271  }
272 
273  Time& operator/=(double rhs)
274  {
275  m_usec = static_cast<value_type>(static_cast<double>(m_usec) / rhs);
276  return *this;
277  }
278 
279  Time operator/(double rhs) const
280  {
281  Time t;
282  t.m_usec = static_cast<value_type>(static_cast<double>(m_usec) / rhs);
283  return t;
284  }
285 
286  friend ICLUtils_API std::ostream& operator<<(std::ostream&, const Time&);
287 
288  friend ICLUtils_API std::istream& operator>>(std::istream&, Time&);
289 
290  private:
291 
293  };
294 
296  ICLUtils_API std::ostream& operator<<(std::ostream&, const Time&);
297 
299  ICLUtils_API std::istream& operator>>(std::istream&, Time&);
300 
301  } // namespace utils
302 } // End namespace icl
303 
bool operator>(const Time &rhs) const
Definition: Time.h:162
Time & operator/=(value_type rhs)
Definition: Time.h:247
void showAge(const std::string &title="") const
common function for simple benchmarking
Definition: Time.h:115
Time & operator-=(const Time &rhs)
Definition: Time.h:146
undocument this line if you encounter any issues!
Definition: Any.h:37
Time & operator+=(const Time &rhs)
Definition: Time.h:140
#define ICLUtils_API
this macros are important for creating dll's
Definition: CompatMacros.h:171
Time operator-() const
Definition: Time.h:125
ICL Time class (taken from the Ice lib)
Definition: Time.h:52
static Time microSeconds(value_type)
std::string getAgeString() const
returns string representation of the times age
Definition: Time.h:104
value_type m_usec
Definition: Time.h:292
bool operator<=(const Time &rhs) const
Definition: Time.h:157
Time age() const
Definition: Time.h:99
Time operator/(double rhs) const
Definition: Time.h:279
Time operator/(int rhs) const
Definition: Time.h:227
static Time now()
int64_t value_type
internal data type (64Bit integer)
Definition: Time.h:56
Time & operator/=(double rhs)
Definition: Time.h:273
FixedMatrix< T, V_COLS, M_ROWS_AND_COLS > & operator *=(FixedMatrix< T, V_COLS, M_ROWS_AND_COLS > &v, const FixedMatrix< T, M_ROWS_AND_COLS, M_ROWS_AND_COLS > &m)
Matrix multiplication (inplace)
Definition: FixedMatrix.h:959
Time operator/(const Time &rhs) const
Definition: Time.h:201
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.
ICLUtils_API std::istream & operator>>(std::istream &s, Point &p)
istream operator
Time & operator/=(int rhs)
Definition: Time.h:221
ICLQt_API ImgQ operator *(const ImgQ &a, const ImgQ &b)
multiplies two images pixel-wise
bool operator!=(const Time &rhs) const
Definition: Time.h:177
bool operator>=(const Time &rhs) const
Definition: Time.h:167
void printAge(const std::string &title="") const
alternative function name for showAge
Definition: Time.h:120
Time operator/(value_type rhs) const
Definition: Time.h:253
Time & operator/=(const Time &rhs)
Definition: Time.h:195
Time operator+(const Time &rhs) const
Definition: Time.h:135
bool operator<(const Time &rhs) const
Definition: Time.h:152
bool operator==(const Time &rhs) const
Definition: Time.h:172
Time operator-(const Time &rhs) const
Definition: Time.h:130