$treeview $search $mathjax
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 { "Q Forecasting", "Hybrid Forecasting", "Old QFF", "New QFF", 00016 "Based Forecasting" }; 00017 00018 // ////////////////////////////////////////////////////////////////////// 00019 const char ForecastingMethod:: 00020 _methodLabels[LAST_VALUE] = { 'Q', 'H', 'O' , 'N', 'B'}; 00021 00022 00023 // ////////////////////////////////////////////////////////////////////// 00024 ForecastingMethod::ForecastingMethod() 00025 : _method (LAST_VALUE) { 00026 assert (false); 00027 } 00028 00029 // ////////////////////////////////////////////////////////////////////// 00030 ForecastingMethod:: 00031 ForecastingMethod (const ForecastingMethod& iForecastingMethod) 00032 : _method (iForecastingMethod._method) { 00033 } 00034 00035 // ////////////////////////////////////////////////////////////////////// 00036 ForecastingMethod:: 00037 ForecastingMethod (const EN_ForecastingMethod& iForecastingMethod) 00038 : _method (iForecastingMethod) { 00039 } 00040 00041 // ////////////////////////////////////////////////////////////////////// 00042 ForecastingMethod::ForecastingMethod (const char iMethod) { 00043 switch (iMethod) { 00044 case 'Q': _method = Q_FORECASTING; break; 00045 case 'H': _method = HYBRID_FORECASTING; break; 00046 case 'O': _method = OLD_QFF; break; 00047 case 'N': _method = NEW_QFF; break; 00048 case 'B': _method = BASED_FORECASTING; break; 00049 default: _method = LAST_VALUE; break; 00050 } 00051 00052 if (_method == LAST_VALUE) { 00053 const std::string& lLabels = describeLabels(); 00054 std::ostringstream oMessage; 00055 oMessage << "The forecasting method '" << iMethod 00056 << "' is not known. Known forecasting methods: " << lLabels; 00057 throw CodeConversionException (oMessage.str()); 00058 } 00059 } 00060 00061 // ////////////////////////////////////////////////////////////////////// 00062 const std::string& ForecastingMethod:: 00063 getLabel (const EN_ForecastingMethod& iMethod) { 00064 return _labels[iMethod]; 00065 } 00066 00067 // ////////////////////////////////////////////////////////////////////// 00068 char ForecastingMethod::getMethodLabel (const EN_ForecastingMethod& iMethod) { 00069 return _methodLabels[iMethod]; 00070 } 00071 00072 // ////////////////////////////////////////////////////////////////////// 00073 std::string ForecastingMethod:: 00074 getMethodLabelAsString (const EN_ForecastingMethod& iMethod) { 00075 std::ostringstream oStr; 00076 oStr << _methodLabels[iMethod]; 00077 return oStr.str(); 00078 } 00079 00080 // ////////////////////////////////////////////////////////////////////// 00081 std::string ForecastingMethod::describeLabels() { 00082 std::ostringstream ostr; 00083 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) { 00084 if (idx != 0) { 00085 ostr << ", "; 00086 } 00087 ostr << _labels[idx] << " (" << _methodLabels[idx] << ")"; 00088 } 00089 return ostr.str(); 00090 } 00091 00092 // ////////////////////////////////////////////////////////////////////// 00093 ForecastingMethod::EN_ForecastingMethod ForecastingMethod::getMethod() const { 00094 return _method; 00095 } 00096 00097 // ////////////////////////////////////////////////////////////////////// 00098 std::string ForecastingMethod::getMethodAsString() const { 00099 std::ostringstream oStr; 00100 oStr << _methodLabels[_method]; 00101 return oStr.str(); 00102 } 00103 00104 // ////////////////////////////////////////////////////////////////////// 00105 const std::string ForecastingMethod::describe() const { 00106 std::ostringstream ostr; 00107 ostr << _labels[_method]; 00108 return ostr.str(); 00109 } 00110 00111 // ////////////////////////////////////////////////////////////////////// 00112 bool ForecastingMethod:: 00113 operator== (const EN_ForecastingMethod& iMethod) const { 00114 return (_method == iMethod); 00115 } 00116 00117 }