Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
TimeStamp.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This file is part of the gobelijn software.
4  * Gobelijn is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or any later
7  * version. Gobelijn is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9  * or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for details. You should have received
11  * a copy of the GNU General Public License along with the software. If not,
12  * see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2012, Jan Broeckhove.
15  */
20 #include <chrono>
21 #include <ctime>
22 #include <string>
23 
24 namespace UA_CoMP {
25 namespace Timekeeper {
26 
31 class TimeStamp
32 {
33 public:
35  TimeStamp() : m_tp(std::chrono::system_clock::now()) {}
36 
38  std::string ToString() const
39  {
40  std::time_t t = std::chrono::system_clock::to_time_t(m_tp);
41  std::string str = std::ctime(&t);
42  str[str.length() - 1] = ' ';
43  return str;
44  }
45 
47  std::time_t ToTimeT() const { return std::chrono::system_clock::to_time_t(m_tp); }
48 
49 private:
50  std::chrono::system_clock::time_point m_tp;
51 };
52 
56 inline std::ostream& operator<<(std::ostream& os, TimeStamp t) { return (os << t.ToString()); }
57 
58 } // namespace Timekeeper
59 } // namespace UA_CoMP
TimeStamp()
Constructor marks the time for the time stamp.
Definition: TimeStamp.h:35
std::string ToString() const
Returns string with the time stamp after eliminating newline.
Definition: TimeStamp.h:38
std::ostream & operator<<(std::ostream &oss, Stopwatch< T > const &stopwatch)
Insert accumulated time into output stream without altering stopwatch state.
Definition: Stopwatch.h:124
std::time_t ToTimeT() const
Returns time stamp as a time_t.
Definition: TimeStamp.h:47
std::chrono::system_clock::time_point m_tp
Definition: TimeStamp.h:50
Provides wall-clock time stamp using the time call.
Definition: TimeStamp.h:31