StdAir Logo  1.00.17
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
PassengerType.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 PassengerType::_labels[LAST_VALUE] =
15 { "Leisure", "Business", "First" };
16
17 const char PassengerType::_typeLabels[LAST_VALUE] = { 'L', 'B', 'F' };
18
19
20 // //////////////////////////////////////////////////////////////////////
22 : _type (iPassengerType) {
23 }
24
25 // //////////////////////////////////////////////////////////////////////
26 PassengerType::PassengerType (const char iType) {
27 switch (iType) {
28 case 'L': _type = LEISURE; break;
29 case 'B': _type = BUSINESS; break;
30 case 'F': _type = FIRST; break;
31 default: _type = LAST_VALUE; break;
32 }
33
34 if (_type == LAST_VALUE) {
35 const std::string& lLabels = describeLabels();
36 std::ostringstream oMessage;
37 oMessage << "The passenger type '" << iType
38 << "' is not known. Known passenger types: " << lLabels;
39 throw CodeConversionException (oMessage.str());
40 }
41 }
42
43 // //////////////////////////////////////////////////////////////////////
44 const std::string& PassengerType::getLabel (const EN_PassengerType& iType) {
45 return _labels[iType];
46 }
47
48 // //////////////////////////////////////////////////////////////////////
50 return _typeLabels[iType];
51 }
52
53 // //////////////////////////////////////////////////////////////////////
54 std::string PassengerType::
56 std::ostringstream oStr;
57 oStr << _typeLabels[iType];
58 return oStr.str();
59 }
60
61 // //////////////////////////////////////////////////////////////////////
63 std::ostringstream ostr;
64 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
65 if (idx != 0) {
66 ostr << ", ";
67 }
68 ostr << _labels[idx];
69 }
70 return ostr.str();
71 }
72
73 // //////////////////////////////////////////////////////////////////////
77
78 // //////////////////////////////////////////////////////////////////////
79 std::string PassengerType::getTypeAsString() const {
80 std::ostringstream oStr;
81 oStr << _typeLabels[_type];
82 return oStr.str();
83 }
84
85 // //////////////////////////////////////////////////////////////////////
86 const std::string PassengerType::describe() const {
87 std::ostringstream ostr;
88 ostr << _labels[_type];
89 return ostr.str();
90 }
91
92 // //////////////////////////////////////////////////////////////////////
94 return (_type == iType);
95 }
96
97}
Handle on the StdAir library context.
const std::string describe() const
bool operator==(const EN_PassengerType &) const
EN_PassengerType getType() const
std::string getTypeAsString() const
static const std::string & getLabel(const EN_PassengerType &)
static std::string describeLabels()
PassengerType(const EN_PassengerType &)
static std::string getTypeLabelAsString(const EN_PassengerType &)
static char getTypeLabel(const EN_PassengerType &)