StdAir Logo  1.00.16
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
PassengerChoiceModel.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 PassengerChoiceModel::_labels[LAST_VALUE] =
15 { "HardRestrictionModel", "PriceOrientedModel", "HybridModel"};
16
17 // //////////////////////////////////////////////////////////////////////
18 const char PassengerChoiceModel::
19 _modelLabels[LAST_VALUE] = { 'R', 'P', 'H'};
20
21
22 // //////////////////////////////////////////////////////////////////////
24 : _model (LAST_VALUE) {
25 assert (false);
26 }
27
28 // //////////////////////////////////////////////////////////////////////
29 PassengerChoiceModel::
30 PassengerChoiceModel (const PassengerChoiceModel& iPassengerChoiceModel)
31 : _model (iPassengerChoiceModel._model) {
32 }
33
34 // //////////////////////////////////////////////////////////////////////
35 PassengerChoiceModel::
36 PassengerChoiceModel (const EN_PassengerChoiceModel& iPassengerChoiceModel)
37 : _model (iPassengerChoiceModel) {
38 }
39
40 // //////////////////////////////////////////////////////////////////////
42 switch (iModel) {
43 case 'R': _model = HARD_RESTRICTION; break;
44 case 'P': _model = PRICE_ORIENTED; break;
45 case 'H': _model = HYBRID; break;
46 default: _model = LAST_VALUE; break;
47 }
48
49 if (_model == LAST_VALUE) {
50 const std::string& lLabels = describeLabels();
51 std::ostringstream oMessage;
52 oMessage << "The passenger choice model '"
53 << "' is not known. Known passenger choice models " << lLabels;
54 throw stdair::CodeConversionException (oMessage.str());
55 }
56 }
57
58 // //////////////////////////////////////////////////////////////////////
59 const std::string& PassengerChoiceModel::
60 getLabel (const EN_PassengerChoiceModel& iModel) {
61 return _labels[iModel];
62 }
63
64 // //////////////////////////////////////////////////////////////////////
66 return _modelLabels[iModel];
67 }
68
69 // //////////////////////////////////////////////////////////////////////
72 std::ostringstream oStr;
73 oStr << _modelLabels[iModel];
74 return oStr.str();
75 }
76
77 // //////////////////////////////////////////////////////////////////////
79 std::ostringstream ostr;
80 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
81 if (idx != 0) {
82 ostr << ", ";
83 }
84 ostr << _labels[idx] << " (" << _modelLabels[idx] << ")";
85 }
86 return ostr.str();
87 }
88
89 // //////////////////////////////////////////////////////////////////////
93
94 // //////////////////////////////////////////////////////////////////////
96 std::ostringstream oStr;
97 oStr << _modelLabels[_model];
98 return oStr.str();
99 }
100
101 // //////////////////////////////////////////////////////////////////////
102 const std::string PassengerChoiceModel::describe() const {
103 std::ostringstream ostr;
104 ostr << _labels[_model];
105 return ostr.str();
106 }
107
108 // //////////////////////////////////////////////////////////////////////
110 operator== (const EN_PassengerChoiceModel& iModel) const {
111 return (_model == iModel);
112 }
113
114}
Handle on the StdAir library context.
const std::string describe() const
PassengerChoiceModel(const EN_PassengerChoiceModel &)
EN_PassengerChoiceModel getModel() const
static const std::string & getLabel(const EN_PassengerChoiceModel &)
static char getModelLabel(const EN_PassengerChoiceModel &)
static std::string getModelLabelAsString(const EN_PassengerChoiceModel &)
bool operator==(const EN_PassengerChoiceModel &) const