AirInv Logo  1.00.12
C++ Simulated Airline Inventory Management System Library
Loading...
Searching...
No Matches
FlightTypeCode.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 FlightTypeCode::_labels[LAST_VALUE] =
17 { "Domestic", "International", "Ground Handling"};
18
19 const std::string FlightTypeCode::_codeLabels[LAST_VALUE] =
20 { "DOM", "INT", "GRD" };
21
22
23 // //////////////////////////////////////////////////////////////////////
25 : _code (iFlightTypeCode) {
26 }
27
28 // //////////////////////////////////////////////////////////////////////
29 FlightTypeCode::FlightTypeCode (const std::string& iCode) {
30 _code = LAST_VALUE;
31
32 if (iCode == "DOM") {
33 _code = DOMESTIC;
34
35 } else if (iCode == "INT") {
36 _code = INTERNATIONAL;
37
38 } else if (iCode == "GRD") {
39 _code = GROUND_HANDLING;
40 }
41
42 if (_code == LAST_VALUE) {
43 const std::string& lLabels = describeLabels();
44 STDAIR_LOG_ERROR ("The flight type code '" << iCode
45 << "' is not known. Known flight type codes: "
46 << lLabels);
47 throw stdair::CodeConversionException ("The flight type code '" + iCode
48 + "' is not known. Known flight type codes: "
49 + lLabels);
50 }
51 }
52
53 // //////////////////////////////////////////////////////////////////////
54 const std::string& FlightTypeCode::getLabel (const EN_FlightTypeCode& iCode) {
55 return _labels[iCode];
56 }
57
58 // //////////////////////////////////////////////////////////////////////
59 const std::string& FlightTypeCode::
60 getCodeLabel (const EN_FlightTypeCode& iCode) {
61 return _codeLabels[iCode];
62 }
63
64 // //////////////////////////////////////////////////////////////////////
66 std::ostringstream ostr;
67 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
68 if (idx != 0) {
69 ostr << ", ";
70 }
71 ostr << _labels[idx];
72 }
73 return ostr.str();
74 }
75
76 // //////////////////////////////////////////////////////////////////////
80
81 // //////////////////////////////////////////////////////////////////////
82 const std::string FlightTypeCode::describe() const {
83 std::ostringstream ostr;
84 ostr << _labels[_code];
85 return ostr.str();
86 }
87
88}
static const std::string & getLabel(const EN_FlightTypeCode &)
EN_FlightTypeCode getCode() const
static const std::string & getCodeLabel(const EN_FlightTypeCode &)
FlightTypeCode(const EN_FlightTypeCode &)
static std::string describeLabels()
const std::string describe() const