VPTissue Reference Manual
TimeStamp.h
Go to the documentation of this file.
1 #ifndef UTIL_CLOCK_MAN_TIMESTAMP_H_INCLUDED
2 #define UTIL_CLOCK_MAN_TIMESTAMP_H_INCLUDED
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they
7  * will be approved by the European Commission - subsequent
8  * versions of the EUPL (the "Licence");
9  * You may not use this work except in compliance with the
10  * Licence. You may obtain a copy of the Licence at:
11  *
12  * http://ec.europa.eu/idabc/eupl5
13  *
14  * Unless required by applicable law or agreed to in
15  * writing, software distributed under the Licence is
16  * distributed on an "AS IS" basis,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
18  * express or implied.
19  * See the Licence for the specific language governing
20  * permissions and limitations under the Licence.
21  */
26 #include <string>
27 #include <ctime>
28 #include <chrono>
29 
30 namespace SimPT_Sim {
31 namespace ClockMan {
32 
37 class TimeStamp
38 {
39 public:
41  TimeStamp() : m_tp(std::chrono::system_clock::now()) {}
42 
44  std::string ToString() const
45  {
46  std::time_t t = std::chrono::system_clock::to_time_t(m_tp);
47  std::string str = std::ctime(&t);
48  str[str.length() - 1] = ' ';
49  return str;
50  }
51 
53  std::time_t ToTimeT() const
54  {
55  return std::chrono::system_clock::to_time_t(m_tp);
56  }
57 
58 private:
59  std::chrono::system_clock::time_point m_tp;
60 };
61 
65 inline std::ostream&
66 operator<<(std::ostream& os, TimeStamp t) {
67  return (os << t.ToString());
68 }
69 
70 } // namespace
71 } // namespace
72 
73 #endif // include guard
STL namespace.
TimeStamp()
Constructor marks the time for the time stamp.
Definition: TimeStamp.h:41
Namespace for the core simulator.
std::time_t ToTimeT() const
Returns time stamp as a time_t.
Definition: TimeStamp.h:53
Provides wall-clock time stamp using the time call.
Definition: TimeStamp.h:37
std::ostream & operator<<(std::ostream &os, CumulativeRecords< std::chrono::nanoseconds > const &dr)
Nicely formated output with nanoseconds.
std::string ToString() const
Returns string with the time stamp after eliminating newline.
Definition: TimeStamp.h:44