Program Listing for File Timestamp.hpp
↰ Return to documentation for file (include/lvr2/util/Timestamp.hpp)
/*
* Timestamp.h
*
* Created on: 14.01.2011
* Author: Thomas Wiemann
*/
#ifndef TIMESTAMP_H_
#define TIMESTAMP_H_
#include <iostream>
#include <string>
using std::ostream;
using std::string;
namespace lvr2 {
class Timestamp
{
public:
Timestamp();
unsigned long getCurrentTimeInMs() const;
unsigned long getElapsedTimeInMs() const;
double getCurrentTimeinS() const;
double getElapsedTimeInS() const;
void resetTimer();
void setQuiet(bool quiet) { m_quiet = quiet;};
string getElapsedTime() const;
bool isQuiet() {return m_quiet;};
ostream& getNullStream() { return m_nullStream; };
private:
class NullBuffer : public std::streambuf
{
public:
int overflow(int c) { return c; }
};
unsigned long m_startTime;
bool m_quiet;
NullBuffer m_nullBuffer;
std::ostream m_nullStream;
};
static Timestamp timestamp;
inline std::ostream& operator<<(std::ostream& os, Timestamp &ts)
{
if(ts.isQuiet())
{
return ts.getNullStream();
}
else
{
os << ts.getElapsedTime();
return os;
}
}
} // namespace lvr
#endif /* TIMESTAMP_H_ */