TvlSim Logo  1.01.6
C++ Simulated Travel-Oriented Distribution System Library
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
11
12namespace 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 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
80 return _modeLabels[iMode];
81 }
82
83 // //////////////////////////////////////////////////////////////////////
84 std::string SimulationMode::
86 std::ostringstream oStr;
87 oStr << _modeLabels[iMode];
88 return oStr.str();
89 }
90
91 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
107
108 // //////////////////////////////////////////////////////////////////////
110 std::ostringstream oStr;
111 oStr << _modeLabels[_mode];
112 return oStr.str();
113 }
114
115 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
130 operator== (const EN_SimulationMode& iMode) const {
131 return (_mode == iMode);
132 }
133
134}
Enumeration of json commands.
std::string getModeAsString() const
bool operator==(const EN_SimulationMode &) const
const std::string describe() const
static std::string getModeLabelAsString(const EN_SimulationMode &)
static char getModeLabel(const EN_SimulationMode &)
static const std::string & getLabel(const EN_SimulationMode &)
EN_SimulationMode getMode() const
static std::string describeLabels()