00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <sstream> 00007 // StdAir 00008 #include <stdair/service/Logger.hpp> 00009 // Airinv 00010 #include <airinv/AIRINV_Types.hpp> 00011 #include <airinv/basic/FlightTypeCode.hpp> 00012 00013 namespace AIRINV { 00014 00015 // ////////////////////////////////////////////////////////////////////// 00016 const std::string FlightTypeCode::_labels[LAST_VALUE] = 00017 { "Domestic", "International", "Ground Handling"}; 00018 00019 const std::string FlightTypeCode::_codeLabels[LAST_VALUE] = 00020 { "DOM", "INT", "GRD" }; 00021 00022 00023 // ////////////////////////////////////////////////////////////////////// 00024 FlightTypeCode::FlightTypeCode (const EN_FlightTypeCode& iFlightTypeCode) 00025 : _code (iFlightTypeCode) { 00026 } 00027 00028 // ////////////////////////////////////////////////////////////////////// 00029 FlightTypeCode::FlightTypeCode (const std::string& iCode) { 00030 _code = LAST_VALUE; 00031 00032 if (iCode == "DOM") { 00033 _code = DOMESTIC; 00034 00035 } else if (iCode == "INT") { 00036 _code = INTERNATIONAL; 00037 00038 } else if (iCode == "GRD") { 00039 _code = GROUND_HANDLING; 00040 } 00041 00042 if (_code == LAST_VALUE) { 00043 const std::string& lLabels = describeLabels(); 00044 STDAIR_LOG_ERROR ("The flight type code '" << iCode 00045 << "' is not known. Known flight type codes: " 00046 << lLabels); 00047 throw stdair::CodeConversionException ("The flight type code '" + iCode 00048 + "' is not known. Known flight type codes: " 00049 + lLabels); 00050 } 00051 } 00052 00053 // ////////////////////////////////////////////////////////////////////// 00054 const std::string& FlightTypeCode::getLabel (const EN_FlightTypeCode& iCode) { 00055 return _labels[iCode]; 00056 } 00057 00058 // ////////////////////////////////////////////////////////////////////// 00059 const std::string& FlightTypeCode:: 00060 getCodeLabel (const EN_FlightTypeCode& iCode) { 00061 return _codeLabels[iCode]; 00062 } 00063 00064 // ////////////////////////////////////////////////////////////////////// 00065 std::string FlightTypeCode::describeLabels() { 00066 std::ostringstream ostr; 00067 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) { 00068 if (idx != 0) { 00069 ostr << ", "; 00070 } 00071 ostr << _labels[idx]; 00072 } 00073 return ostr.str(); 00074 } 00075 00076 // ////////////////////////////////////////////////////////////////////// 00077 FlightTypeCode::EN_FlightTypeCode FlightTypeCode::getCode() const { 00078 return _code; 00079 } 00080 00081 // ////////////////////////////////////////////////////////////////////// 00082 const std::string FlightTypeCode::describe() const { 00083 std::ostringstream ostr; 00084 ostr << _labels[_code]; 00085 return ostr.str(); 00086 } 00087 00088 }