StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForecastingMethod.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
10 
11 namespace stdair {
12 
13  // //////////////////////////////////////////////////////////////////////
14  const std::string ForecastingMethod::_labels[LAST_VALUE] =
15  { "AdditivePickUp", "MultiplicativePickUp" };
16 
17  // //////////////////////////////////////////////////////////////////////
18  const char ForecastingMethod::
19  _methodLabels[LAST_VALUE] = { 'A', 'M' };
20 
21 
22  // //////////////////////////////////////////////////////////////////////
23  ForecastingMethod::ForecastingMethod()
24  : _method (LAST_VALUE) {
25  assert (false);
26  }
27 
28  // //////////////////////////////////////////////////////////////////////
29  ForecastingMethod::
30  ForecastingMethod (const ForecastingMethod& iForecastingMethod)
31  : _method (iForecastingMethod._method) {
32  }
33 
34  // //////////////////////////////////////////////////////////////////////
35  ForecastingMethod::
36  ForecastingMethod (const EN_ForecastingMethod& iForecastingMethod)
37  : _method (iForecastingMethod) {
38  }
39 
40  // //////////////////////////////////////////////////////////////////////
41  ForecastingMethod::ForecastingMethod (const char iMethod) {
42  switch (iMethod) {
43  case 'A': _method = ADD_PK; break;
44  case 'M': _method = MUL_PK; break;
45  default: _method = LAST_VALUE; break;
46  }
47 
48  if (_method == LAST_VALUE) {
49  const std::string& lLabels = describeLabels();
50  std::ostringstream oMessage;
51  oMessage << "The forecasting method '" << iMethod
52  << "' is not known. Known forecasting methods: " << lLabels;
53  throw CodeConversionException (oMessage.str());
54  }
55  }
56 
57  // //////////////////////////////////////////////////////////////////////
58  const std::string& ForecastingMethod::
59  getLabel (const EN_ForecastingMethod& iMethod) {
60  return _labels[iMethod];
61  }
62 
63  // //////////////////////////////////////////////////////////////////////
65  return _methodLabels[iMethod];
66  }
67 
68  // //////////////////////////////////////////////////////////////////////
69  std::string ForecastingMethod::
71  std::ostringstream oStr;
72  oStr << _methodLabels[iMethod];
73  return oStr.str();
74  }
75 
76  // //////////////////////////////////////////////////////////////////////
78  std::ostringstream ostr;
79  for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
80  if (idx != 0) {
81  ostr << ", ";
82  }
83  ostr << _labels[idx];
84  }
85  return ostr.str();
86  }
87 
88  // //////////////////////////////////////////////////////////////////////
90  return _method;
91  }
92 
93  // //////////////////////////////////////////////////////////////////////
95  std::ostringstream oStr;
96  oStr << _methodLabels[_method];
97  return oStr.str();
98  }
99 
100  // //////////////////////////////////////////////////////////////////////
101  const std::string ForecastingMethod::describe() const {
102  std::ostringstream ostr;
103  ostr << _labels[_method];
104  return ostr.str();
105  }
106 
107  // //////////////////////////////////////////////////////////////////////
109  operator== (const EN_ForecastingMethod& iMethod) const {
110  return (_method == iMethod);
111  }
112 
113 }