1.01.12
C++ Simulated Travel-Oriented Distribution System Library
Toggle main menu visibility
Loading...
Searching...
No Matches
SimulationMode.cpp
Go to the documentation of this file.
1
// //////////////////////////////////////////////////////////////////////
2
// Import section
3
// //////////////////////////////////////////////////////////////////////
4
// STL
5
#include <cassert>
6
#include <sstream>
7
// StdAir
8
#include <stdair/stdair_exceptions.hpp>
9
// TvlSim
10
#include <
tvlsim/basic/SimulationMode.hpp
>
11
12
namespace
TVLSIM
{
13
14
// //////////////////////////////////////////////////////////////////////
15
const
std::string SimulationMode::_labels[LAST_VALUE] =
16
{
"start"
,
"running"
,
"break"
,
"done"
};
17
18
// //////////////////////////////////////////////////////////////////////
19
const
char
SimulationMode::_modeLabels[LAST_VALUE] = {
's'
,
'r'
,
'b'
,
'd'
};
20
21
// //////////////////////////////////////////////////////////////////////
22
SimulationMode::SimulationMode
()
23
: _mode (LAST_VALUE) {
24
assert (
false
);
25
}
26
27
// //////////////////////////////////////////////////////////////////////
28
SimulationMode::
29
SimulationMode (
const
SimulationMode
& iSimulationMode)
30
: _mode (iSimulationMode._mode) {
31
}
32
33
// //////////////////////////////////////////////////////////////////////
34
SimulationMode::EN_SimulationMode
35
SimulationMode::getMode
(
const
char
iModeChar) {
36
37
EN_SimulationMode
oSimulationMode;
38
switch
(iModeChar) {
39
case
's'
: oSimulationMode =
START
;
break
;
40
case
'r'
: oSimulationMode =
RUNNING
;
break
;
41
case
'b'
: oSimulationMode =
BREAK
;
break
;
42
case
'd'
: oSimulationMode =
DONE
;
break
;
43
default
: oSimulationMode =
LAST_VALUE
;
break
;
44
}
45
46
if
(oSimulationMode ==
LAST_VALUE
) {
47
const
std::string& lLabels =
describeLabels
();
48
std::ostringstream oMessage;
49
oMessage <<
"The simulation mode '"
<< iModeChar
50
<<
"' is not known. Known simulation modes: "
<< lLabels;
51
throw
stdair::CodeConversionException (oMessage.str());
52
}
53
54
return
oSimulationMode;
55
}
56
57
58
// //////////////////////////////////////////////////////////////////////
59
SimulationMode::SimulationMode
(
const
char
iModeChar)
60
: _mode (
getMode
(iModeChar)) {
61
}
62
63
// //////////////////////////////////////////////////////////////////////
64
SimulationMode::SimulationMode
(
const
std::string& iModeStr) {
65
//
66
const
size_t
lSize = iModeStr.size();
67
assert (lSize == 1);
68
const
char
lModeChar = iModeStr[0];
69
_mode =
getMode
(lModeChar);
70
}
71
72
// //////////////////////////////////////////////////////////////////////
73
const
std::string&
SimulationMode::
74
getLabel
(
const
EN_SimulationMode
& iMode) {
75
return
_labels[iMode];
76
}
77
78
// //////////////////////////////////////////////////////////////////////
79
char
SimulationMode::getModeLabel
(
const
EN_SimulationMode
& iMode) {
80
return
_modeLabels[iMode];
81
}
82
83
// //////////////////////////////////////////////////////////////////////
84
std::string
SimulationMode::
85
getModeLabelAsString
(
const
EN_SimulationMode
& iMode) {
86
std::ostringstream oStr;
87
oStr << _modeLabels[iMode];
88
return
oStr.str();
89
}
90
91
// //////////////////////////////////////////////////////////////////////
92
std::string
SimulationMode::describeLabels
() {
93
std::ostringstream ostr;
94
for
(
unsigned
short
idx = 0; idx !=
LAST_VALUE
; ++idx) {
95
if
(idx != 0) {
96
ostr <<
", "
;
97
}
98
ostr << _labels[idx] <<
" '"
<< _modeLabels[idx] <<
"'"
;
99
}
100
return
ostr.str();
101
}
102
103
// //////////////////////////////////////////////////////////////////////
104
SimulationMode::EN_SimulationMode
SimulationMode::getMode
()
const
{
105
return
_mode;
106
}
107
108
// //////////////////////////////////////////////////////////////////////
109
std::string
SimulationMode::getModeAsString
()
const
{
110
std::ostringstream oStr;
111
oStr << _modeLabels[_mode];
112
return
oStr.str();
113
}
114
115
// //////////////////////////////////////////////////////////////////////
116
char
SimulationMode::getModeAsChar
()
const
{
117
const
char
oModeChar = _modeLabels[_mode];
118
return
oModeChar;
119
}
120
121
// //////////////////////////////////////////////////////////////////////
122
const
std::string
SimulationMode::describe
()
const
{
123
std::ostringstream ostr;
124
ostr << _labels[_mode];
125
return
ostr.str();
126
}
127
128
// //////////////////////////////////////////////////////////////////////
129
bool
SimulationMode::
130
operator==
(
const
EN_SimulationMode
& iMode)
const
{
131
return
(_mode == iMode);
132
}
133
134
}
SimulationMode.hpp
TVLSIM
Definition
BasConst.cpp:7
TVLSIM::SimulationMode::getModeAsChar
char getModeAsChar() const
Definition
SimulationMode.cpp:116
TVLSIM::SimulationMode::getMode
static EN_SimulationMode getMode(const char)
Definition
SimulationMode.cpp:35
TVLSIM::SimulationMode::getModeAsString
std::string getModeAsString() const
Definition
SimulationMode.cpp:109
TVLSIM::SimulationMode::operator==
bool operator==(const EN_SimulationMode &) const
Definition
SimulationMode.cpp:130
TVLSIM::SimulationMode::describe
const std::string describe() const
Definition
SimulationMode.cpp:122
TVLSIM::SimulationMode::getModeLabelAsString
static std::string getModeLabelAsString(const EN_SimulationMode &)
Definition
SimulationMode.cpp:85
TVLSIM::SimulationMode::SimulationMode
SimulationMode(const EN_SimulationMode &)
TVLSIM::SimulationMode::EN_SimulationMode
EN_SimulationMode
Definition
SimulationMode.hpp:19
TVLSIM::SimulationMode::DONE
@ DONE
Definition
SimulationMode.hpp:23
TVLSIM::SimulationMode::RUNNING
@ RUNNING
Definition
SimulationMode.hpp:21
TVLSIM::SimulationMode::LAST_VALUE
@ LAST_VALUE
Definition
SimulationMode.hpp:24
TVLSIM::SimulationMode::START
@ START
Definition
SimulationMode.hpp:20
TVLSIM::SimulationMode::BREAK
@ BREAK
Definition
SimulationMode.hpp:22
TVLSIM::SimulationMode::getModeLabel
static char getModeLabel(const EN_SimulationMode &)
Definition
SimulationMode.cpp:79
TVLSIM::SimulationMode::getLabel
static const std::string & getLabel(const EN_SimulationMode &)
Definition
SimulationMode.cpp:74
TVLSIM::SimulationMode::getMode
EN_SimulationMode getMode() const
Definition
SimulationMode.cpp:104
TVLSIM::SimulationMode::describeLabels
static std::string describeLabels()
Definition
SimulationMode.cpp:92
Generated on
for TvlSim by
1.17.0