StdAir Logo  1.00.21
C++ Standard Airline IT Object Library
Loading...
Searching...
No Matches
DemandGenerationMethod.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 DemandGenerationMethod::_labels[LAST_VALUE] =
15 { "PoissonProcess", "StatisticsOrder" };
16
17 // //////////////////////////////////////////////////////////////////////
18 const char DemandGenerationMethod::_methodLabels[LAST_VALUE] = { 'P', 'S' };
19
20
21 // //////////////////////////////////////////////////////////////////////
23 assert (false);
24 }
25
26 // //////////////////////////////////////////////////////////////////////
27 DemandGenerationMethod::
28 DemandGenerationMethod (const DemandGenerationMethod& iDemandGenerationMethod)
29 : _method (iDemandGenerationMethod._method) {
30 }
31
32 // //////////////////////////////////////////////////////////////////////
34 DemandGenerationMethod (const EN_DemandGenerationMethod& iDemandGenerationMethod)
35 : _method (iDemandGenerationMethod) {
36 }
37
38 // //////////////////////////////////////////////////////////////////////
40 DemandGenerationMethod::getMethod (const char iMethodChar) {
42 switch (iMethodChar) {
43 case 'P': oMethod = POI_PRO; break;
44 case 'S': oMethod = STA_ORD; break;
45 default: oMethod = LAST_VALUE; break;
46 }
47
48 if (oMethod == LAST_VALUE) {
49 const std::string& lLabels = describeLabels();
50 std::ostringstream oMessage;
51 oMessage << "The demand (booking request) generation method '"
52 << iMethodChar
53 << "' is not known. Known demand (booking request) generation "
54 << "methods: " << lLabels;
55 throw CodeConversionException (oMessage.str());
56 }
57
58 return oMethod;
59 }
60
61 // //////////////////////////////////////////////////////////////////////
63 : _method (getMethod (iMethodChar)) {
64 }
65
66 // //////////////////////////////////////////////////////////////////////
68 DemandGenerationMethod (const std::string& iMethodStr) {
69 //
70 const size_t lSize = iMethodStr.size();
71 assert (lSize == 1);
72 const char lMethodChar = iMethodStr[0];
73 _method = getMethod (lMethodChar);
74 }
75
76 // //////////////////////////////////////////////////////////////////////
77 const std::string& DemandGenerationMethod::
78 getLabel (const EN_DemandGenerationMethod& iMethod) {
79 return _labels[iMethod];
80 }
81
82 // //////////////////////////////////////////////////////////////////////
85 return _methodLabels[iMethod];
86 }
87
88 // //////////////////////////////////////////////////////////////////////
91 std::ostringstream oStr;
92 oStr << _methodLabels[iMethod];
93 return oStr.str();
94 }
95
96 // //////////////////////////////////////////////////////////////////////
98 std::ostringstream ostr;
99 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
100 if (idx != 0) {
101 ostr << ", ";
102 }
103 ostr << _labels[idx];
104 }
105 return ostr.str();
106 }
107
108 // //////////////////////////////////////////////////////////////////////
111 return _method;
112 }
113
114 // //////////////////////////////////////////////////////////////////////
116 const char oMethodChar = _methodLabels[_method];
117 return oMethodChar;
118 }
119
120 // //////////////////////////////////////////////////////////////////////
122 std::ostringstream oStr;
123 oStr << _methodLabels[_method];
124 return oStr.str();
125 }
126
127 // //////////////////////////////////////////////////////////////////////
128 const std::string DemandGenerationMethod::describe() const {
129 std::ostringstream ostr;
130 ostr << _labels[_method];
131 return ostr.str();
132 }
133
134 // //////////////////////////////////////////////////////////////////////
136 operator== (const EN_DemandGenerationMethod& iMethod) const {
137 return (_method == iMethod);
138 }
139
140}
Handle on the StdAir library context.
static std::string getMethodLabelAsString(const EN_DemandGenerationMethod &)
static const std::string & getLabel(const EN_DemandGenerationMethod &)
EN_DemandGenerationMethod getMethod() const
DemandGenerationMethod(const EN_DemandGenerationMethod &)
static EN_DemandGenerationMethod getMethod(const char)
bool operator==(const EN_DemandGenerationMethod &) const
static char getMethodLabel(const EN_DemandGenerationMethod &)