VPTissue Reference Manual
Utils.h
Go to the documentation of this file.
1 #ifndef UTIL_CLOCK_MAN_UTILS_H_INCLUDED
2 #define UTIL_CLOCK_MAN_UTILS_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  */
27 #include <string>
28 #include <sstream>
29 #include <iostream>
30 #include <iomanip>
31 #include <cmath>
32 
33 namespace SimPT_Sim {
34 namespace ClockMan {
35 
39 struct Utils
40 {
42  static std::string ToColonString(std::chrono::seconds d)
43  {
44  using namespace std;
45  using namespace std::chrono;
46 
47  ostringstream oss;
48  hours hh = duration_cast < hours > (d);
49  minutes mm = duration_cast < minutes > (d % hours(1));
50  seconds ss = duration_cast < seconds > (d % minutes(1));
51 
52  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
53  << ":" << setw(2) << ss.count();
54  return oss.str();
55  }
56 
58  static std::string ToColonString(std::chrono::milliseconds d)
59  {
60  using namespace std;
61  using namespace std::chrono;
62 
63  ostringstream oss;
64  hours hh = duration_cast < hours > (d);
65  minutes mm = duration_cast < minutes > (d % hours(1));
66  seconds ss = duration_cast < seconds > (d % minutes(1));
67  milliseconds milli = duration_cast < milliseconds > (d % seconds(1));
68 
69  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
70  << ":" << setw(2) << ss.count() << ":" << setw(3) << milli.count();
71  return oss.str();
72  }
73 
75  static std::string ToColonString(std::chrono::microseconds d)
76  {
77  using namespace std;
78  using namespace std::chrono;
79 
80  ostringstream oss;
81  hours hh = duration_cast < hours > (d);
82  minutes mm = duration_cast < minutes > (d % hours(1));
83  seconds ss = duration_cast < seconds > (d % minutes(1));
84  milliseconds milli = duration_cast < milliseconds > (d % seconds(1));
85  microseconds micro = duration_cast < microseconds > (d % milliseconds(1));
86 
87  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
88  << ":" << setw(2) << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count();
89  return oss.str();
90  }
91 
93  static std::string ToColonString(std::chrono::nanoseconds d)
94  {
95  using namespace std;
96  using namespace std::chrono;
97 
98  ostringstream oss;
99  hours hh = duration_cast < hours > (d);
100  minutes mm = duration_cast < minutes > (d % hours(1));
101  seconds ss = duration_cast < seconds > (d % minutes(1));
102  milliseconds milli = duration_cast < milliseconds > (d % seconds(1));
103  microseconds micro = duration_cast < microseconds > (d % milliseconds(1));
104  nanoseconds nano = duration_cast < nanoseconds > (d % microseconds(1));
105 
106  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count()
107  << ":" << setw(2) << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count()
108  << ":" << setw(3) << nano.count();
109  return oss.str();
110  }
111 };
112 
113 } // namespace
114 } // namespace
115 
116 #endif // end of include guard
static std::string ToColonString(std::chrono::milliseconds d)
Produce string in hh:mm:ss:mus format.
Definition: Utils.h:58
STL namespace.
static std::string ToColonString(std::chrono::seconds d)
Procude string in hh:mm:ss format.
Definition: Utils.h:42
Namespace for the core simulator.
Utilities to tag clocks and to reformat number of ticks to a string.
Definition: Utils.h:39
static std::string ToColonString(std::chrono::microseconds d)
Produce string in hh:mm:ss:ms:mus format.
Definition: Utils.h:75
static std::string ToColonString(std::chrono::nanoseconds d)
Produce string in hh:mm:ss:ms:mus:ns format.
Definition: Utils.h:93