Stride Reference Manual  - generated for commit 9643b11
TimeToString.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2017, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "TimeToString.h"
22 
23 #include <cmath>
24 #include <iomanip>
25 #include <iostream>
26 #include <sstream>
27 
28 namespace stride {
29 namespace util {
30 
31 using namespace std;
32 
33 string TimeToString::ToColonString(chrono::minutes d)
34 {
35  using namespace std;
36  using namespace chrono;
37 
38  ostringstream oss;
39  hours hh = duration_cast<hours>(d);
40  minutes mm = duration_cast<minutes>(d % hours(1));
41 
42  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2) << 0;
43  return oss.str();
44 }
45 
46 string TimeToString::ToColonString(chrono::seconds d)
47 {
48  using namespace std;
49  using namespace chrono;
50 
51  ostringstream oss;
52  hours hh = duration_cast<hours>(d);
53  minutes mm = duration_cast<minutes>(d % hours(1));
54  seconds ss = duration_cast<seconds>(d % minutes(1));
55 
56  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
57  << ss.count();
58  return oss.str();
59 }
60 
61 string TimeToString::ToColonString(chrono::milliseconds d)
62 {
63  using namespace std;
64  using namespace chrono;
65 
66  ostringstream oss;
67  hours hh = duration_cast<hours>(d);
68  minutes mm = duration_cast<minutes>(d % hours(1));
69  seconds ss = duration_cast<seconds>(d % minutes(1));
70  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
71 
72  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
73  << ss.count() << ":" << setw(3) << milli.count();
74  return oss.str();
75 }
76 
77 string TimeToString::ToColonString(chrono::microseconds d)
78 {
79  using namespace std;
80  using namespace chrono;
81 
82  ostringstream oss;
83  hours hh = duration_cast<hours>(d);
84  minutes mm = duration_cast<minutes>(d % hours(1));
85  seconds ss = duration_cast<seconds>(d % minutes(1));
86  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
87  microseconds micro = duration_cast<microseconds>(d % milliseconds(1));
88 
89  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
90  << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count();
91  return oss.str();
92 }
93 
94 string TimeToString::ToColonString(chrono::nanoseconds d)
95 {
96  using namespace std;
97  using namespace chrono;
98 
99  ostringstream oss;
100  hours hh = duration_cast<hours>(d);
101  minutes mm = duration_cast<minutes>(d % hours(1));
102  seconds ss = duration_cast<seconds>(d % minutes(1));
103  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
104  microseconds micro = duration_cast<microseconds>(d % milliseconds(1));
105  nanoseconds nano = duration_cast<nanoseconds>(d % microseconds(1));
106 
107  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
108  << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count() << ":" << setw(3)
109  << nano.count() << endl;
110  return oss.str();
111 }
112 
113 } // namespace util
114 } // namespace stride
Utilities to tag clocks and reformat clock readout to string.
STL namespace.
static std::string ToColonString(std::chrono::minutes d)
Produce string in hh:mm:ss format.
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28