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/DemandGenerationMethod.hpp> 00010 00011 namespace stdair { 00012 00013 // ////////////////////////////////////////////////////////////////////// 00014 const std::string DemandGenerationMethod::_labels[LAST_VALUE] = 00015 { "PoissonProcess", "SatisticsOrder" }; 00016 00017 // ////////////////////////////////////////////////////////////////////// 00018 const char DemandGenerationMethod::_methodLabels[LAST_VALUE] = { 'P', 'S' }; 00019 00020 00021 // ////////////////////////////////////////////////////////////////////// 00022 DemandGenerationMethod::DemandGenerationMethod() : _method (LAST_VALUE) { 00023 assert (false); 00024 } 00025 00026 // ////////////////////////////////////////////////////////////////////// 00027 DemandGenerationMethod:: 00028 DemandGenerationMethod (const DemandGenerationMethod& iDemandGenerationMethod) 00029 : _method (iDemandGenerationMethod._method) { 00030 } 00031 00032 // ////////////////////////////////////////////////////////////////////// 00033 DemandGenerationMethod:: 00034 DemandGenerationMethod (const EN_DemandGenerationMethod& iDemandGenerationMethod) 00035 : _method (iDemandGenerationMethod) { 00036 } 00037 00038 // ////////////////////////////////////////////////////////////////////// 00039 DemandGenerationMethod::EN_DemandGenerationMethod 00040 DemandGenerationMethod::getMethod (const char iMethodChar) { 00041 EN_DemandGenerationMethod oMethod; 00042 switch (iMethodChar) { 00043 case 'P': oMethod = POI_PRO; break; 00044 case 'S': oMethod = STA_ORD; break; 00045 default: oMethod = LAST_VALUE; break; 00046 } 00047 00048 if (oMethod == LAST_VALUE) { 00049 const std::string& lLabels = describeLabels(); 00050 std::ostringstream oMessage; 00051 oMessage << "The demand (booking request) generation method '" 00052 << iMethodChar 00053 << "' is not known. Known demand (booking request) generation " 00054 << "methods: " << lLabels; 00055 throw CodeConversionException (oMessage.str()); 00056 } 00057 00058 return oMethod; 00059 } 00060 00061 // ////////////////////////////////////////////////////////////////////// 00062 DemandGenerationMethod::DemandGenerationMethod (const char iMethodChar) 00063 : _method (getMethod (iMethodChar)) { 00064 } 00065 00066 // ////////////////////////////////////////////////////////////////////// 00067 DemandGenerationMethod:: 00068 DemandGenerationMethod (const std::string& iMethodStr) { 00069 // 00070 const size_t lSize = iMethodStr.size(); 00071 assert (lSize == 1); 00072 const char lMethodChar = iMethodStr[0]; 00073 _method = getMethod (lMethodChar); 00074 } 00075 00076 // ////////////////////////////////////////////////////////////////////// 00077 const std::string& DemandGenerationMethod:: 00078 getLabel (const EN_DemandGenerationMethod& iMethod) { 00079 return _labels[iMethod]; 00080 } 00081 00082 // ////////////////////////////////////////////////////////////////////// 00083 char DemandGenerationMethod:: 00084 getMethodLabel (const EN_DemandGenerationMethod& iMethod) { 00085 return _methodLabels[iMethod]; 00086 } 00087 00088 // ////////////////////////////////////////////////////////////////////// 00089 std::string DemandGenerationMethod:: 00090 getMethodLabelAsString (const EN_DemandGenerationMethod& iMethod) { 00091 std::ostringstream oStr; 00092 oStr << _methodLabels[iMethod]; 00093 return oStr.str(); 00094 } 00095 00096 // ////////////////////////////////////////////////////////////////////// 00097 std::string DemandGenerationMethod::describeLabels() { 00098 std::ostringstream ostr; 00099 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) { 00100 if (idx != 0) { 00101 ostr << ", "; 00102 } 00103 ostr << _labels[idx]; 00104 } 00105 return ostr.str(); 00106 } 00107 00108 // ////////////////////////////////////////////////////////////////////// 00109 DemandGenerationMethod::EN_DemandGenerationMethod 00110 DemandGenerationMethod::getMethod() const { 00111 return _method; 00112 } 00113 00114 // ////////////////////////////////////////////////////////////////////// 00115 char DemandGenerationMethod::getMethodAsChar() const { 00116 const char oMethodChar = _methodLabels[_method]; 00117 return oMethodChar; 00118 } 00119 00120 // ////////////////////////////////////////////////////////////////////// 00121 std::string DemandGenerationMethod::getMethodAsString() const { 00122 std::ostringstream oStr; 00123 oStr << _methodLabels[_method]; 00124 return oStr.str(); 00125 } 00126 00127 // ////////////////////////////////////////////////////////////////////// 00128 const std::string DemandGenerationMethod::describe() const { 00129 std::ostringstream ostr; 00130 ostr << _labels[_method]; 00131 return ostr.str(); 00132 } 00133 00134 // ////////////////////////////////////////////////////////////////////// 00135 bool DemandGenerationMethod:: 00136 operator== (const EN_DemandGenerationMethod& iMethod) const { 00137 return (_method == iMethod); 00138 } 00139 00140 }