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/FlightVisibilityCode.hpp> 00012 00013 namespace AIRINV { 00014 00015 // ////////////////////////////////////////////////////////////////////// 00016 const std::string FlightVisibilityCode::_labels[LAST_VALUE] = 00017 { "Normal", "Hidden", "Pseudo"}; 00018 00019 const std::string FlightVisibilityCode::_codeLabels[LAST_VALUE] = 00020 { "NOR", "HID", "PSD" }; 00021 00022 00023 // ////////////////////////////////////////////////////////////////////// 00024 FlightVisibilityCode:: 00025 FlightVisibilityCode (const EN_FlightVisibilityCode& iFlightVisibilityCode) 00026 : _code (iFlightVisibilityCode) { 00027 } 00028 00029 // ////////////////////////////////////////////////////////////////////// 00030 FlightVisibilityCode::FlightVisibilityCode (const std::string& iCode) { 00031 _code = LAST_VALUE; 00032 00033 if (iCode == "NOR") { 00034 _code = NORMAL; 00035 00036 } else if (iCode == "HID") { 00037 _code = HIDDEN; 00038 00039 } else if (iCode == "PSD") { 00040 _code = PSEUDO; 00041 } 00042 00043 if (_code == LAST_VALUE) { 00044 const std::string& lLabels = describeLabels(); 00045 STDAIR_LOG_ERROR ("The flight visibility code '" << iCode 00046 << "' is not known. Known flight visibility codes: " 00047 << lLabels); 00048 throw stdair::CodeConversionException ("The flight visibility code '" 00049 + iCode 00050 + "' is not known. Known flight visibility codes: " 00051 + lLabels); 00052 } 00053 } 00054 00055 // ////////////////////////////////////////////////////////////////////// 00056 const std::string& FlightVisibilityCode:: 00057 getLabel (const EN_FlightVisibilityCode& iCode) { 00058 return _labels[iCode]; 00059 } 00060 00061 // ////////////////////////////////////////////////////////////////////// 00062 const std::string& FlightVisibilityCode:: 00063 getCodeLabel (const EN_FlightVisibilityCode& iCode) { 00064 return _codeLabels[iCode]; 00065 } 00066 00067 // ////////////////////////////////////////////////////////////////////// 00068 std::string FlightVisibilityCode::describeLabels() { 00069 std::ostringstream ostr; 00070 for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) { 00071 if (idx != 0) { 00072 ostr << ", "; 00073 } 00074 ostr << _labels[idx]; 00075 } 00076 return ostr.str(); 00077 } 00078 00079 // ////////////////////////////////////////////////////////////////////// 00080 FlightVisibilityCode::EN_FlightVisibilityCode FlightVisibilityCode:: 00081 getCode() const { 00082 return _code; 00083 } 00084 00085 // ////////////////////////////////////////////////////////////////////// 00086 const std::string FlightVisibilityCode::describe() const { 00087 std::ostringstream ostr; 00088 ostr << _labels[_code]; 00089 return ostr.str(); 00090 } 00091 00092 }