StdAir Logo  1.00.16
C++ Standard Airline IT Object Library
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
10
11namespace 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 // //////////////////////////////////////////////////////////////////////
19 : _command (LAST_VALUE) {
20 assert (false);
21 }
22
23 // //////////////////////////////////////////////////////////////////////
24 JSonCommand::
25 JSonCommand (const JSonCommand& iJSonCommand)
26 : _command (iJSonCommand._command) {
27 }
28
29 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
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 // //////////////////////////////////////////////////////////////////////
102 operator== (const EN_JSonCommand& iCommand) const {
103 return (_command == iCommand);
104 }
105
106}
Handle on the StdAir library context.
const std::string describe() const
static std::string describeLabels()
bool operator==(const EN_JSonCommand &) const
static std::string getLabel(const EN_JSonCommand &)
EN_JSonCommand getCommand() const
JSonCommand(const EN_JSonCommand &)