Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Utils.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, Dirk De Vos.
15  */
21 #include <cmath>
22 #include <iomanip>
23 #include <iostream>
24 #include <sstream>
25 #include <string>
26 
27 namespace UA_CoMP {
28 namespace Timekeeper {
29 
33 struct Utils
34 {
36  static std::string ToColonString(std::chrono::seconds d)
37  {
38  using namespace std;
39  using namespace std::chrono;
40 
41  ostringstream oss;
42  hours hh = duration_cast<hours>(d);
43  minutes mm = duration_cast<minutes>(d % hours(1));
44  seconds ss = duration_cast<seconds>(d % minutes(1));
45 
46  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
47  << ss.count();
48  return oss.str();
49  }
50 
52  static std::string ToColonString(std::chrono::milliseconds d)
53  {
54  using namespace std;
55  using namespace std::chrono;
56 
57  ostringstream oss;
58  hours hh = duration_cast<hours>(d);
59  minutes mm = duration_cast<minutes>(d % hours(1));
60  seconds ss = duration_cast<seconds>(d % minutes(1));
61  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
62 
63  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
64  << ss.count() << ":" << setw(3) << milli.count();
65  return oss.str();
66  }
67 
69  static std::string ToColonString(std::chrono::microseconds d)
70  {
71  using namespace std;
72  using namespace std::chrono;
73 
74  ostringstream oss;
75  hours hh = duration_cast<hours>(d);
76  minutes mm = duration_cast<minutes>(d % hours(1));
77  seconds ss = duration_cast<seconds>(d % minutes(1));
78  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
79  microseconds micro = duration_cast<microseconds>(d % milliseconds(1));
80 
81  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
82  << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count();
83  return oss.str();
84  }
85 
87  static std::string ToColonString(std::chrono::nanoseconds d)
88  {
89  using namespace std;
90  using namespace std::chrono;
91 
92  ostringstream oss;
93  hours hh = duration_cast<hours>(d);
94  minutes mm = duration_cast<minutes>(d % hours(1));
95  seconds ss = duration_cast<seconds>(d % minutes(1));
96  milliseconds milli = duration_cast<milliseconds>(d % seconds(1));
97  microseconds micro = duration_cast<microseconds>(d % milliseconds(1));
98  nanoseconds nano = duration_cast<nanoseconds>(d % microseconds(1));
99 
100  oss << right << setfill('0') << setw(2) << hh.count() << ":" << setw(2) << mm.count() << ":" << setw(2)
101  << ss.count() << ":" << setw(3) << milli.count() << ":" << setw(3) << micro.count() << ":"
102  << setw(3) << nano.count() << endl;
103  return oss.str();
104  }
105 };
106 
107 } // namespace Timekeeper
108 } // namespace UA_CoMP
static std::string ToColonString(std::chrono::milliseconds d)
Produce string in hh:mm:ss:mus format.
Definition: Utils.h:52
Utilities to tag clocks and to reformat number of ticks to a string.
Definition: Utils.h:33
static std::string ToColonString(std::chrono::nanoseconds d)
Produce string in hh:mm:ss:ms:mus:ns format.
Definition: Utils.h:87
static std::string ToColonString(std::chrono::microseconds d)
Produce string in hh:mm:ss:ms:mus format.
Definition: Utils.h:69
static std::string ToColonString(std::chrono::seconds d)
Procude string in hh:mm:ss format.
Definition: Utils.h:36