AirInv Logo  1.00.7
C++ Simulated Airline Inventory Management System Library
Loading...
Searching...
No Matches
FlightVisibilityCode.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/service/Logger.hpp>
9// Airinv
12
13namespace AIRINV {
14
15 // //////////////////////////////////////////////////////////////////////
16 const std::string FlightVisibilityCode::_labels[LAST_VALUE] =
17 { "Normal", "Hidden", "Pseudo"};
18
19 const std::string FlightVisibilityCode::_codeLabels[LAST_VALUE] =
20 { "NOR", "HID", "PSD" };
21
22
23 // //////////////////////////////////////////////////////////////////////
25 FlightVisibilityCode (const EN_FlightVisibilityCode& iFlightVisibilityCode)
26 : _code (iFlightVisibilityCode) {
27 }
28
29 // //////////////////////////////////////////////////////////////////////
30 FlightVisibilityCode::FlightVisibilityCode (const std::string& iCode) {
31 _code = LAST_VALUE;
32
33 if (iCode == "NOR") {
34 _code = NORMAL;
35
36 } else if (iCode == "HID") {
37 _code = HIDDEN;
38
39 } else if (iCode == "PSD") {
40 _code = PSEUDO;
41 }
42
43 if (_code == LAST_VALUE) {
44 const std::string& lLabels = describeLabels();
45 STDAIR_LOG_ERROR ("The flight visibility code '" << iCode
46 << "' is not known. Known flight visibility codes: "
47 << lLabels);
48 throw stdair::CodeConversionException ("The flight visibility code '"
49 + iCode
50 + "' is not known. Known flight visibility codes: "
51 + lLabels);
52 }
53 }
54
55 // //////////////////////////////////////////////////////////////////////
56 const std::string& FlightVisibilityCode::
58 return _labels[iCode];
59 }
60
61 // //////////////////////////////////////////////////////////////////////
62 const std::string& FlightVisibilityCode::
64 return _codeLabels[iCode];
65 }
66
67 // //////////////////////////////////////////////////////////////////////
69 std::ostringstream ostr;
70 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
71 if (idx != 0) {
72 ostr << ", ";
73 }
74 ostr << _labels[idx];
75 }
76 return ostr.str();
77 }
78
79 // //////////////////////////////////////////////////////////////////////
81 getCode() const {
82 return _code;
83 }
84
85 // //////////////////////////////////////////////////////////////////////
86 const std::string FlightVisibilityCode::describe() const {
87 std::ostringstream ostr;
88 ostr << _labels[_code];
89 return ostr.str();
90 }
91
92}
EN_FlightVisibilityCode getCode() const
FlightVisibilityCode(const EN_FlightVisibilityCode &)
const std::string describe() const
static const std::string & getCodeLabel(const EN_FlightVisibilityCode &)
static const std::string & getLabel(const EN_FlightVisibilityCode &)