$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/PassengerType.hpp> 00010 00011 namespace stdair { 00012 00013 // ////////////////////////////////////////////////////////////////////// 00014 const std::string PassengerType::_labels[LAST_VALUE] = 00015 { "Leisure", "Business", "First" }; 00016 00017 const char PassengerType::_typeLabels[LAST_VALUE] = { 'L', 'B', 'F' }; 00018 00019 00020 // ////////////////////////////////////////////////////////////////////// 00021 PassengerType::PassengerType (const EN_PassengerType& iPassengerType) 00022 : _type (iPassengerType) { 00023 } 00024 00025 // ////////////////////////////////////////////////////////////////////// 00026 PassengerType::PassengerType (const char iType) { 00027 switch (iType) { 00028 case 'L': _type = LEISURE; break; 00029 case 'B': _type = BUSINESS; break; 00030 case 'F': _type = FIRST; break; 00031 default: _type = LAST_VALUE; break; 00032 } 00033 00034 if (_type == LAST_VALUE) { 00035 const std::string& lLabels = describeLabels(); 00036 std::ostringstream oMessage; 00037 oMessage << "The passenger type '" << iType 00038 << "' is not known. Known passenger types: " << lLabels; 00039 throw CodeConversionException (oMessage.str()); 00040 } 00041 } 00042 00043 // ////////////////////////////////////////////////////////////////////// 00044 const std::string& PassengerType::getLabel (const EN_PassengerType& iType) { 00045 return _labels[iType]; 00046 } 00047 00048 // ////////////////////////////////////////////////////////////////////// 00049 char PassengerType::getTypeLabel (const EN_PassengerType& iType) { 00050 return _typeLabels[iType]; 00051 } 00052 00053 // ////////////////////////////////////////////////////////////////////// 00054 std::string PassengerType:: 00055 getTypeLabelAsString (const EN_PassengerType& iType) { 00056 std::ostringstream oStr; 00057 oStr << _typeLabels[iType]; 00058 return oStr.str(); 00059 } 00060 00061 // ////////////////////////////////////////////////////////////////////// 00062 std::string PassengerType::describeLabels() { 00063 std::ostringstream ostr; 00064 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) { 00065 if (idx != 0) { 00066 ostr << ", "; 00067 } 00068 ostr << _labels[idx]; 00069 } 00070 return ostr.str(); 00071 } 00072 00073 // ////////////////////////////////////////////////////////////////////// 00074 PassengerType::EN_PassengerType PassengerType::getType() const { 00075 return _type; 00076 } 00077 00078 // ////////////////////////////////////////////////////////////////////// 00079 std::string PassengerType::getTypeAsString() const { 00080 std::ostringstream oStr; 00081 oStr << _typeLabels[_type]; 00082 return oStr.str(); 00083 } 00084 00085 // ////////////////////////////////////////////////////////////////////// 00086 const std::string PassengerType::describe() const { 00087 std::ostringstream ostr; 00088 ostr << _labels[_type]; 00089 return ostr.str(); 00090 } 00091 00092 // ////////////////////////////////////////////////////////////////////// 00093 bool PassengerType::operator== (const EN_PassengerType& iType) const { 00094 return (_type == iType); 00095 } 00096 00097 }