StdAir Logo  0.45.1
C++ Standard Airline IT Object Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ForecastingMethod.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/stdair_exceptions.hpp>
00009 #include <stdair/basic/ForecastingMethod.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string ForecastingMethod::_labels[LAST_VALUE] =
00015     { "AdditivePickUp", "MultiplicativePickUp" };
00016 
00017   // //////////////////////////////////////////////////////////////////////
00018   const char ForecastingMethod::
00019   _methodLabels[LAST_VALUE] = { 'A', 'M' };
00020 
00021   
00022   // //////////////////////////////////////////////////////////////////////
00023   ForecastingMethod::ForecastingMethod()
00024     : _method (LAST_VALUE) {
00025     assert (false);
00026   }
00027 
00028   // //////////////////////////////////////////////////////////////////////
00029   ForecastingMethod::
00030   ForecastingMethod (const ForecastingMethod& iForecastingMethod)
00031     : _method (iForecastingMethod._method) {
00032   }
00033 
00034   // //////////////////////////////////////////////////////////////////////
00035   ForecastingMethod::
00036   ForecastingMethod (const EN_ForecastingMethod& iForecastingMethod)
00037     : _method (iForecastingMethod) {
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   ForecastingMethod::ForecastingMethod (const char iMethod) {
00042     switch (iMethod) {
00043     case 'A': _method = ADD_PK; break;
00044     case 'M': _method = MUL_PK; break;
00045     default: _method = LAST_VALUE; break;
00046     }
00047 
00048     if (_method == LAST_VALUE) {
00049       const std::string& lLabels = describeLabels();
00050       std::ostringstream oMessage;
00051       oMessage << "The forecasting method '" << iMethod
00052                << "' is not known. Known forecasting methods: " << lLabels;
00053       throw CodeConversionException (oMessage.str());
00054     }
00055   }
00056   
00057   // //////////////////////////////////////////////////////////////////////
00058   const std::string& ForecastingMethod::
00059   getLabel (const EN_ForecastingMethod& iMethod) {
00060     return _labels[iMethod];
00061   }
00062   
00063   // //////////////////////////////////////////////////////////////////////
00064   char ForecastingMethod::getMethodLabel (const EN_ForecastingMethod& iMethod) {
00065     return _methodLabels[iMethod];
00066   }
00067 
00068   // //////////////////////////////////////////////////////////////////////
00069   std::string ForecastingMethod::
00070   getMethodLabelAsString (const EN_ForecastingMethod& iMethod) {
00071     std::ostringstream oStr;
00072     oStr << _methodLabels[iMethod];
00073     return oStr.str();
00074   }
00075 
00076   // //////////////////////////////////////////////////////////////////////
00077   std::string ForecastingMethod::describeLabels() {
00078     std::ostringstream ostr;
00079     for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
00080       if (idx != 0) {
00081         ostr << ", ";
00082       }
00083       ostr << _labels[idx];
00084     }
00085     return ostr.str();
00086   }
00087 
00088   // //////////////////////////////////////////////////////////////////////
00089   ForecastingMethod::EN_ForecastingMethod ForecastingMethod::getMethod() const {
00090     return _method;
00091   }
00092   
00093   // //////////////////////////////////////////////////////////////////////
00094   std::string ForecastingMethod::getMethodAsString() const {
00095     std::ostringstream oStr;
00096     oStr << _methodLabels[_method];
00097     return oStr.str();
00098   }
00099   
00100   // //////////////////////////////////////////////////////////////////////
00101   const std::string ForecastingMethod::describe() const {
00102     std::ostringstream ostr;
00103     ostr << _labels[_method];
00104     return ostr.str();
00105   }
00106 
00107   // //////////////////////////////////////////////////////////////////////
00108   bool ForecastingMethod::
00109   operator== (const EN_ForecastingMethod& iMethod) const {
00110     return (_method == iMethod);
00111   }
00112   
00113 }