Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <sstream>
00007 #if BOOST_VERSION >= 104100
00008
00009 #include <boost/property_tree/ptree.hpp>
00010 #include <boost/property_tree/json_parser.hpp>
00011 #endif // BOOST_VERSION >= 104100
00012
00013 #include <stdair/bom/BomJSONImport.hpp>
00014
00015 #if BOOST_VERSION >= 104100
00016 namespace bpt = boost::property_tree;
00017 #else // BOOST_VERSION >= 104100
00018 namespace bpt {
00019 typedef char ptree;
00020 }
00021 #endif // BOOST_VERSION >= 104100
00022
00023 namespace stdair {
00024
00025
00026 bool BomJSONImport::jsonImportInventoryKey (const std::string& iBomTree,
00027 AirlineCode_T& ioAirlineCode) {
00028 bool hasKeyBeenSuccessfullyRetrieved = true;
00029
00030 #if BOOST_VERSION >= 104100
00031
00032 bpt::ptree pt;
00033
00034 try {
00035
00036
00037
00038
00039 std::istringstream iStr (iBomTree);
00040 read_json (iStr, pt);
00041
00042
00043
00044
00045 ioAirlineCode = pt.get<AirlineCode_T> ("flight_date.airline_code");
00046
00047 } catch (bpt::ptree_error& bptException) {
00048 hasKeyBeenSuccessfullyRetrieved = false;
00049 }
00050 #endif // BOOST_VERSION >= 104100
00051
00052 return hasKeyBeenSuccessfullyRetrieved;
00053 }
00054
00055
00056 bool BomJSONImport::jsonImportFlightDateKey (const std::string& iBomTree,
00057 FlightNumber_T& ioFlightNumber,
00058 Date_T& ioDepartureDate) {
00059 bool hasKeyBeenSuccessfullyRetrieved = false;
00060
00061 #if BOOST_VERSION >= 104100
00062
00063 bpt::ptree pt;
00064
00065 try {
00066
00067
00068
00069
00070 std::istringstream iStr (iBomTree);
00071 read_json (iStr, pt);
00072
00073
00074
00075 ioFlightNumber = pt.get<FlightNumber_T> ("flight_date.flight_number");
00076
00077 const std::string& lDepartureDateStr =
00078 pt.get<std::string> ("flight_date.departure_date");
00079 ioDepartureDate = boost::gregorian::from_simple_string (lDepartureDateStr);
00080
00081 } catch (bpt::ptree_error& bptException) {
00082 hasKeyBeenSuccessfullyRetrieved = false;
00083 }
00084 #endif // BOOST_VERSION >= 104100
00085
00086 return hasKeyBeenSuccessfullyRetrieved;
00087 }
00088
00089 }