$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/SampleType.hpp> 00010 00011 namespace stdair { 00012 00013 // ////////////////////////////////////////////////////////////////////// 00014 const std::string SampleType::_labels[LAST_VALUE] = 00015 { "All", "AllForPartnerships", "RevenueManagement", "Inventory", "Schedule", 00016 "RevenueAccounting", "FareQuote", "CRS", "DemandGeneration", "EventManagement", 00017 "CustomerChoice" }; 00018 00019 // ////////////////////////////////////////////////////////////////////// 00020 const char SampleType:: 00021 _typeLabels[LAST_VALUE] = { 'A', 'P', 'R', 'I', 'S', 'T', 'F', 'C', 'D', 'E', 'M' }; 00022 00023 00024 // ////////////////////////////////////////////////////////////////////// 00025 SampleType::SampleType() 00026 : _type (LAST_VALUE) { 00027 assert (false); 00028 } 00029 00030 // ////////////////////////////////////////////////////////////////////// 00031 SampleType::SampleType (const SampleType& iSampleType) 00032 : _type (iSampleType._type) { 00033 } 00034 00035 // ////////////////////////////////////////////////////////////////////// 00036 SampleType::SampleType (const EN_SampleType& iSampleType) 00037 : _type (iSampleType) { 00038 } 00039 00040 // ////////////////////////////////////////////////////////////////////// 00041 SampleType::SampleType (const char iType) { 00042 switch (iType) { 00043 case 'A': _type = ALL; break; 00044 case 'P': _type = A4P; break; 00045 case 'R': _type = RMS; break; 00046 case 'I': _type = INV; break; 00047 case 'S': _type = SCH; break; 00048 case 'T': _type = RAC; break; 00049 case 'F': _type = FQT; break; 00050 case 'C': _type = CRS; break; 00051 case 'D': _type = DEM; break; 00052 case 'E': _type = EVT; break; 00053 case 'M': _type = CCM; break; 00054 default: _type = LAST_VALUE; break; 00055 } 00056 00057 if (_type == LAST_VALUE) { 00058 const std::string& lLabels = describeLabels(); 00059 std::ostringstream oMessage; 00060 oMessage << "The sample type '" << iType 00061 << "' is not known. Known sample types: " << lLabels; 00062 throw CodeConversionException (oMessage.str()); 00063 } 00064 } 00065 00066 // ////////////////////////////////////////////////////////////////////// 00067 const std::string& SampleType::getLabel (const EN_SampleType& iType) { 00068 return _labels[iType]; 00069 } 00070 00071 // ////////////////////////////////////////////////////////////////////// 00072 char SampleType::getTypeLabel (const EN_SampleType& iType) { 00073 return _typeLabels[iType]; 00074 } 00075 00076 // ////////////////////////////////////////////////////////////////////// 00077 std::string SampleType::getTypeLabelAsString (const EN_SampleType& iType) { 00078 std::ostringstream oStr; 00079 oStr << _typeLabels[iType]; 00080 return oStr.str(); 00081 } 00082 00083 // ////////////////////////////////////////////////////////////////////// 00084 std::string SampleType::describeLabels() { 00085 std::ostringstream ostr; 00086 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) { 00087 if (idx != 0) { 00088 ostr << ", "; 00089 } 00090 ostr << _labels[idx]; 00091 } 00092 return ostr.str(); 00093 } 00094 00095 // ////////////////////////////////////////////////////////////////////// 00096 SampleType::EN_SampleType SampleType::getType() const { 00097 return _type; 00098 } 00099 00100 // ////////////////////////////////////////////////////////////////////// 00101 std::string SampleType::getTypeAsString() const { 00102 std::ostringstream oStr; 00103 oStr << _typeLabels[_type]; 00104 return oStr.str(); 00105 } 00106 00107 // ////////////////////////////////////////////////////////////////////// 00108 const std::string SampleType::describe() const { 00109 std::ostringstream ostr; 00110 ostr << _labels[_type]; 00111 return ostr.str(); 00112 } 00113 00114 // ////////////////////////////////////////////////////////////////////// 00115 bool SampleType::operator== (const EN_SampleType& iType) const { 00116 return (_type == iType); 00117 } 00118 00119 }