Timestamp.hpp
Go to the documentation of this file.
1 
28  /*
29  * Timestamp.h
30  *
31  * Created on: 14.01.2011
32  * Author: Thomas Wiemann
33  */
34 
35 #ifndef TIMESTAMP_H_
36 #define TIMESTAMP_H_
37 
38 #include <iostream>
39 #include <string>
40 
41 using std::ostream;
42 using std::string;
43 
44 namespace lvr2 {
45 
53 class Timestamp
54 {
55 public:
56 
60  Timestamp();
61 
65  unsigned long getCurrentTimeInMs() const;
66 
70  unsigned long getElapsedTimeInMs() const;
71 
75  double getCurrentTimeinS() const;
76 
80  double getElapsedTimeInS() const;
81 
85  void resetTimer();
86 
87  void setQuiet(bool quiet) { m_quiet = quiet;};
88 
93  string getElapsedTime() const;
94 
95  bool isQuiet() {return m_quiet;};
96 
97  ostream& getNullStream() { return m_nullStream; };
98 
99 
100 private:
101 
102  class NullBuffer : public std::streambuf
103  {
104  public:
105  int overflow(int c) { return c; }
106  };
107 
109  unsigned long m_startTime;
110  bool m_quiet;
112  std::ostream m_nullStream;
113 };
114 
117 
119 inline ostream& operator<<(ostream& os, Timestamp &ts)
120 {
121  if(ts.isQuiet())
122  {
123  return ts.getNullStream();
124  }
125  else
126  {
127  os << ts.getElapsedTime();
128  return os;
129  }
130 }
131 
132 } // namespace lvr
133 
134 #endif /* TIMESTAMP_H_ */
std::ostream & operator<<(std::ostream &os, const BaseVector< T > &v)
Definition: BaseVector.hpp:227
A helper class for automated time stamping. Timing is started as soon as an object of this class is c...
Definition: Timestamp.hpp:53
Timestamp()
Constructor.
Definition: Timestamp.cpp:103
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
unsigned long m_startTime
The system at object instantiation.
Definition: Timestamp.hpp:109
void resetTimer()
Resets the internal timer.
Definition: Timestamp.cpp:131
unsigned long getElapsedTimeInMs() const
Returns the milliseconds since object creation.
Definition: Timestamp.cpp:116
double getCurrentTimeinS() const
Returns the current system time in seconds.
Definition: Timestamp.cpp:121
NullBuffer m_nullBuffer
Definition: Timestamp.hpp:111
double getElapsedTimeInS() const
Returns the time since instantiation in seconds.
Definition: Timestamp.cpp:126
unsigned long getCurrentTimeInMs() const
Returns the current system time in milliseconds.
Definition: Timestamp.cpp:109
std::ostream m_nullStream
Definition: Timestamp.hpp:112
string getElapsedTime() const
Returns a string representation of the current timer value.
Definition: Timestamp.cpp:136
void setQuiet(bool quiet)
Definition: Timestamp.hpp:87
ostream & getNullStream()
Definition: Timestamp.hpp:97


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09