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_ */
lvr2::Timestamp::getElapsedTimeInS
double getElapsedTimeInS() const
Returns the time since instantiation in seconds.
Definition: Timestamp.cpp:126
lvr2::Timestamp::NullBuffer::overflow
int overflow(int c)
Definition: Timestamp.hpp:105
lvr2::Timestamp::NullBuffer
Definition: Timestamp.hpp:102
lvr2::Timestamp::getNullStream
ostream & getNullStream()
Definition: Timestamp.hpp:97
lvr2::Timestamp::getCurrentTimeinS
double getCurrentTimeinS() const
Returns the current system time in seconds.
Definition: Timestamp.cpp:121
lvr2::operator<<
std::ostream & operator<<(std::ostream &os, const BaseVector< T > &v)
Definition: BaseVector.hpp:227
lvr2::Timestamp::isQuiet
bool isQuiet()
Definition: Timestamp.hpp:95
lvr2::Timestamp::getElapsedTime
string getElapsedTime() const
Returns a string representation of the current timer value.
Definition: Timestamp.cpp:136
lvr2::Timestamp::m_nullStream
std::ostream m_nullStream
Definition: Timestamp.hpp:112
lvr2::Timestamp::Timestamp
Timestamp()
Constructor.
Definition: Timestamp.cpp:103
lvr2::Timestamp::getElapsedTimeInMs
unsigned long getElapsedTimeInMs() const
Returns the milliseconds since object creation.
Definition: Timestamp.cpp:116
lvr2::timestamp
static Timestamp timestamp
A global time stamp object for program runtime measurement.
Definition: Timestamp.hpp:116
lvr2::Timestamp::m_nullBuffer
NullBuffer m_nullBuffer
Definition: Timestamp.hpp:111
lvr2::Timestamp::resetTimer
void resetTimer()
Resets the internal timer.
Definition: Timestamp.cpp:131
lvr2::Timestamp::setQuiet
void setQuiet(bool quiet)
Definition: Timestamp.hpp:87
lvr2::Timestamp
A helper class for automated time stamping. Timing is started as soon as an object of this class is c...
Definition: Timestamp.hpp:53
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Timestamp::m_quiet
bool m_quiet
Definition: Timestamp.hpp:110
lvr2::Timestamp::m_startTime
unsigned long m_startTime
The system at object instantiation.
Definition: Timestamp.hpp:109
lvr2::Timestamp::getCurrentTimeInMs
unsigned long getCurrentTimeInMs() const
Returns the current system time in milliseconds.
Definition: Timestamp.cpp:109


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 Wed Mar 2 2022 00:37:25