Motiv
Marvelous OTF2 Traces Interactive Visualizer
Loading...
Searching...
No Matches
src
ui
TimeUnit.cpp
1
/*
2
* Marvelous OTF2 Traces Interactive Visualizer (MOTIV)
3
* Copyright (C) 2023 Florian Gallrein, Björn Gehrke
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
#include "TimeUnit.hpp"
19
20
TimeUnit::TimeUnit
(
TimeUnit::Unit
unit) : unit(unit) {}
21
22
QString
TimeUnit::str
()
const
{
23
switch
(this->unit) {
24
case
NanoSecond
:
25
return
"ns"
;
26
case
MicroSecond
:
27
return
"μs"
;
28
case
MilliSecond
:
29
return
"ms"
;
30
case
Second
:
31
return
"s"
;
32
case
Minute
:
33
return
"m"
;
34
case
Hour
:
35
return
"h"
;
36
default
:
37
throw
std::invalid_argument(
"Unknown TimeUnit"
);
38
}
39
}
40
41
TimeUnit::TimeUnit
(QString unit) {
42
std::map<QString, Unit> lut = {
43
{
"ns"
,
NanoSecond
},
44
{
"μs"
,
MicroSecond
},
45
{
"ms"
,
MilliSecond
},
46
{
"s"
,
Second
},
47
{
"m"
,
Minute
},
48
{
"h"
,
Hour
},
49
};
50
51
auto
it = lut.find(unit);
52
if
(it == lut.end()) {
53
throw
std::invalid_argument(
"Unknown TimeUnit"
);
54
}
55
56
this->unit = it->second;
57
}
58
59
double
TimeUnit::multiplier
()
const
{
60
switch
(this->unit) {
61
case
TimeUnit::NanoSecond
:
62
return
1;
63
case
TimeUnit::MicroSecond
:
64
return
1e3;
65
case
TimeUnit::MilliSecond
:
66
return
1e6;
67
case
TimeUnit::Second
:
68
return
1e9;
69
case
TimeUnit::Minute
:
70
return
60e9;
71
case
TimeUnit::Hour
:
72
return
60 * 60e9;
73
default
:
74
// This should be caught by the constructors
75
__builtin_unreachable();
76
}
77
}
TimeUnit::Unit
Unit
Definition:
TimeUnit.hpp:30
TimeUnit::MicroSecond
@ MicroSecond
Definition:
TimeUnit.hpp:32
TimeUnit::Hour
@ Hour
Definition:
TimeUnit.hpp:36
TimeUnit::Second
@ Second
Definition:
TimeUnit.hpp:34
TimeUnit::MilliSecond
@ MilliSecond
Definition:
TimeUnit.hpp:33
TimeUnit::NanoSecond
@ NanoSecond
Definition:
TimeUnit.hpp:31
TimeUnit::Minute
@ Minute
Definition:
TimeUnit.hpp:35
TimeUnit::TimeUnit
TimeUnit(Unit unit)
Constructs or implicitly converts a TimeUnit from a Unit.
Definition:
TimeUnit.cpp:20
TimeUnit::str
QString str() const
Definition:
TimeUnit.cpp:22
TimeUnit::multiplier
double multiplier() const
Definition:
TimeUnit.cpp:59
Generated by
1.9.5