1.00.26
C++ Standard Airline IT Object Library
Toggle main menu visibility
Loading...
Searching...
No Matches
JSonCommand.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
#include <
stdair/basic/JSonCommand.hpp
>
10
11
namespace
stdair
{
12
13
// //////////////////////////////////////////////////////////////////////
14
const
std::string JSonCommand::_labels[
LAST_VALUE
] =
15
{
"list"
,
"flight_date"
,
"event_list"
,
"break_point"
,
"run"
,
"reset"
,
"status"
,
"config"
};
16
17
// //////////////////////////////////////////////////////////////////////
18
JSonCommand::JSonCommand
()
19
: _command (
LAST_VALUE
) {
20
assert (
false
);
21
}
22
23
// //////////////////////////////////////////////////////////////////////
24
JSonCommand::
25
JSonCommand (
const
JSonCommand
& iJSonCommand)
26
: _command (iJSonCommand._command) {
27
}
28
29
// //////////////////////////////////////////////////////////////////////
30
JSonCommand::EN_JSonCommand
31
JSonCommand::getCommand
(
const
std::string& iCommandStr) {
32
33
EN_JSonCommand
oJSonCommand;
34
if
(iCommandStr ==
"list"
) {
35
oJSonCommand =
LIST
;
36
}
else
if
(iCommandStr ==
"flight_date"
) {
37
oJSonCommand =
FLIGHT_DATE
;
38
}
else
if
(iCommandStr ==
"event_list"
) {
39
oJSonCommand =
EVENT_LIST
;
40
}
else
if
(iCommandStr ==
"break_point"
) {
41
oJSonCommand =
BREAK_POINT
;
42
}
else
if
(iCommandStr ==
"run"
) {
43
oJSonCommand =
RUN
;
44
}
else
if
(iCommandStr ==
"reset"
) {
45
oJSonCommand =
RESET
;
46
}
else
if
(iCommandStr ==
"status"
) {
47
oJSonCommand =
STATUS
;
48
}
else
if
(iCommandStr ==
"config"
) {
49
oJSonCommand =
CONFIG
;
50
}
else
{
51
oJSonCommand =
LAST_VALUE
;
52
}
53
54
if
(oJSonCommand ==
LAST_VALUE
) {
55
const
std::string& lLabels =
describeLabels
();
56
std::ostringstream oMessage;
57
oMessage <<
"The JSON command '"
<< iCommandStr
58
<<
"' is not known. Known forecasting commands: "
<< lLabels;
59
throw
CodeConversionException
(oMessage.str());
60
}
61
62
return
oJSonCommand;
63
}
64
65
// //////////////////////////////////////////////////////////////////////
66
std::string
JSonCommand::getLabel
(
const
EN_JSonCommand
& iCommand) {
67
return
_labels[iCommand];
68
}
69
70
// //////////////////////////////////////////////////////////////////////
71
JSonCommand::JSonCommand
(
const
std::string& iCommandStr) {
72
//
73
_command =
getCommand
(iCommandStr);
74
}
75
76
// //////////////////////////////////////////////////////////////////////
77
std::string
JSonCommand::describeLabels
() {
78
std::ostringstream ostr;
79
for
(
unsigned
short
idx = 0; idx !=
LAST_VALUE
; ++idx) {
80
if
(idx != 0) {
81
ostr <<
", "
;
82
}
83
ostr << _labels[idx] <<
" "
;
//'" << _commandLabels[idx] << "'";
84
}
85
return
ostr.str();
86
}
87
88
// //////////////////////////////////////////////////////////////////////
89
JSonCommand::EN_JSonCommand
JSonCommand::getCommand
()
const
{
90
return
_command;
91
}
92
93
// //////////////////////////////////////////////////////////////////////
94
const
std::string
JSonCommand::describe
()
const
{
95
std::ostringstream ostr;
96
ostr << _labels[_command];
97
return
ostr.str();
98
}
99
100
// //////////////////////////////////////////////////////////////////////
101
bool
JSonCommand::
102
operator==
(
const
EN_JSonCommand
& iCommand)
const
{
103
return
(_command == iCommand);
104
}
105
106
}
JSonCommand.hpp
stdair_exceptions.hpp
stdair
Handle on the StdAir library context.
Definition
BasChronometer.cpp:9
stdair::LOG::LAST_VALUE
@ LAST_VALUE
Definition
stdair_log.hpp:25
stdair::JSonCommand::EN_JSonCommand
EN_JSonCommand
Definition
JSonCommand.hpp:19
stdair::JSonCommand::EVENT_LIST
@ EVENT_LIST
Definition
JSonCommand.hpp:22
stdair::JSonCommand::RUN
@ RUN
Definition
JSonCommand.hpp:24
stdair::JSonCommand::FLIGHT_DATE
@ FLIGHT_DATE
Definition
JSonCommand.hpp:21
stdair::JSonCommand::STATUS
@ STATUS
Definition
JSonCommand.hpp:26
stdair::JSonCommand::RESET
@ RESET
Definition
JSonCommand.hpp:25
stdair::JSonCommand::LIST
@ LIST
Definition
JSonCommand.hpp:20
stdair::JSonCommand::BREAK_POINT
@ BREAK_POINT
Definition
JSonCommand.hpp:23
stdair::JSonCommand::CONFIG
@ CONFIG
Definition
JSonCommand.hpp:27
stdair::JSonCommand::LAST_VALUE
@ LAST_VALUE
Definition
JSonCommand.hpp:28
stdair::JSonCommand::describe
const std::string describe() const
Definition
JSonCommand.cpp:94
stdair::JSonCommand::describeLabels
static std::string describeLabels()
Definition
JSonCommand.cpp:77
stdair::JSonCommand::operator==
bool operator==(const EN_JSonCommand &) const
Definition
JSonCommand.cpp:102
stdair::JSonCommand::getLabel
static std::string getLabel(const EN_JSonCommand &)
Definition
JSonCommand.cpp:66
stdair::JSonCommand::getCommand
EN_JSonCommand getCommand() const
Definition
JSonCommand.cpp:89
stdair::JSonCommand::JSonCommand
JSonCommand(const EN_JSonCommand &)
stdair::CodeConversionException
Definition
stdair_exceptions.hpp:133
Generated for StdAir by
1.17.0