Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <ostream>
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 #if BOOST_VERSION >= 103400
00013
00014 #include <boost/foreach.hpp>
00015 #endif // BOOST_VERSION >= 103400
00016
00017 #include <stdair/basic/BasConst_BomDisplay.hpp>
00018 #include <stdair/bom/BomManager.hpp>
00019 #include <stdair/bom/BomRoot.hpp>
00020 #include <stdair/bom/Inventory.hpp>
00021 #include <stdair/bom/FlightDate.hpp>
00022 #include <stdair/bom/LegDate.hpp>
00023 #include <stdair/bom/SegmentDate.hpp>
00024 #include <stdair/bom/LegCabin.hpp>
00025 #include <stdair/bom/SegmentCabin.hpp>
00026 #include <stdair/bom/FareFamily.hpp>
00027 #include <stdair/bom/BookingClass.hpp>
00028 #include <stdair/bom/Bucket.hpp>
00029 #include <stdair/bom/BomJSONExport.hpp>
00030
00031 #if BOOST_VERSION >= 104100
00032 namespace bpt = boost::property_tree;
00033 #else // BOOST_VERSION >= 104100
00034 namespace bpt {
00035 typedef char ptree;
00036 }
00037 #endif // BOOST_VERSION >= 104100
00038
00039 namespace stdair {
00040
00046 struct FlagSaver {
00047 public:
00049 FlagSaver (std::ostream& oStream)
00050 : _oStream (oStream), _streamFlags (oStream.flags()) {
00051 }
00052
00054 ~FlagSaver() {
00055
00056 _oStream.flags (_streamFlags);
00057 }
00058
00059 private:
00061 std::ostream& _oStream;
00063 std::ios::fmtflags _streamFlags;
00064 };
00065
00066
00067 void jsonLegDateExport (bpt::ptree& ioPropertyTree,
00068 const FlightDate& iFlightDate) {
00073
00074 if (BomManager::hasList<LegDate> (iFlightDate) == false) {
00075 return;
00076 }
00077
00078
00079 unsigned short idx = 0;
00080 const LegDateList_T& lLegDateList =
00081 BomManager::getList<LegDate> (iFlightDate);
00082 for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
00083 itLD != lLegDateList.end(); ++itLD, ++idx) {
00084 const LegDate* lLD_ptr = *itLD;
00085 assert (lLD_ptr != NULL);
00086
00087 #if BOOST_VERSION >= 104100
00088
00089 bpt::ptree lLegDateArray;
00090
00091
00092 lLegDateArray.put ("board_point", lLD_ptr->getBoardingPoint());
00093
00094 lLegDateArray.put ("off_point", lLD_ptr->getOffPoint());
00095
00096 lLegDateArray.put ("board_date", lLD_ptr->getBoardingDate());
00097
00098 lLegDateArray.put ("off_date", lLD_ptr->getOffDate());
00099
00100 lLegDateArray.put ("board_time", lLD_ptr->getBoardingTime());
00101
00102 lLegDateArray.put ("off_time", lLD_ptr->getOffTime());
00103
00104 lLegDateArray.put ("elapsed_time", lLD_ptr->getElapsedTime());
00105
00106 lLegDateArray.put ("date_offset", lLD_ptr->getDateOffset());
00107
00108 lLegDateArray.put ("time_offset", lLD_ptr->getTimeOffset());
00109
00110 lLegDateArray.put ("distance", lLD_ptr->getDistance());
00111
00112 lLegDateArray.put ("capacity", lLD_ptr->getCapacity());
00113
00114
00115 std::ostringstream oStream;
00116 oStream << "flight_date.legs";
00117 ioPropertyTree.put_child (oStream.str(), lLegDateArray);
00118 #endif // BOOST_VERSION >= 104100
00119 }
00120 }
00121
00122
00123 void jsonSegmentDateExport (bpt::ptree& ioPropertyTree,
00124 const FlightDate& iFlightDate) {
00128 }
00129
00130
00131 void jsonLegCabinExport (bpt::ptree& ioPropertyTree,
00132 const FlightDate& iFlightDate) {
00137
00138 if (BomManager::hasList<LegDate> (iFlightDate) == false) {
00139 return;
00140 }
00141
00142
00143 const LegDateList_T& lLegDateList =
00144 BomManager::getList<LegDate> (iFlightDate);
00145 for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
00146 itLD != lLegDateList.end(); ++itLD) {
00147 const LegDate* lLD_ptr = *itLD;
00148 assert (lLD_ptr != NULL);
00149
00150
00151 const LegCabinList_T& lLegCabinList =
00152 BomManager::getList<LegCabin> (*lLD_ptr);
00153 for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
00154 itLC != lLegCabinList.end(); ++itLC) {
00155 const LegCabin* lLC_ptr = *itLC;
00156 assert (lLC_ptr != NULL);
00157
00158 #if BOOST_VERSION >= 104100
00159
00160 ioPropertyTree.put ("flight_date.leg.cabin.code",
00161 lLC_ptr->getCabinCode());
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 #endif // BOOST_VERSION >= 104100
00184 }
00185 }
00186 }
00187
00188
00189 void jsonSegmentCabinExport (bpt::ptree& ioPropertyTree,
00190 const FlightDate& iFlightDate) {
00194 }
00195
00196
00197 void jsonFareFamilyExport (bpt::ptree& ioPropertyTree,
00198 const FlightDate& iFlightDate) {
00203
00204 if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
00205 return;
00206 }
00207
00208
00209 const SegmentDateList_T& lSegmentDateList =
00210 BomManager::getList<SegmentDate> (iFlightDate);
00211 for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
00212 itSD != lSegmentDateList.end(); ++itSD) {
00213 const SegmentDate* lSD_ptr = *itSD;
00214 assert (lSD_ptr != NULL);
00215
00216
00217 const SegmentCabinList_T& lSegmentCabinList =
00218 BomManager::getList<SegmentCabin> (*lSD_ptr);
00219 for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
00220 itSC != lSegmentCabinList.end(); ++itSC) {
00221 const SegmentCabin* lSC_ptr = *itSC;
00222 assert (lSC_ptr != NULL);
00223
00224
00225 if (BomManager::hasList<FareFamily> (*lSC_ptr) == false) {
00226 continue;
00227 }
00228
00229
00230 unsigned short ffIdx = 0;
00231 const FareFamilyList_T& lFareFamilyList =
00232 BomManager::getList<FareFamily> (*lSC_ptr);
00233 for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
00234 itFF != lFareFamilyList.end(); ++itFF, ++ffIdx) {
00235 const FareFamily* lFF_ptr = *itFF;
00236 assert (lFF_ptr != NULL);
00237
00238 #if BOOST_VERSION >= 104100
00239
00240 bpt::ptree lFFArray;
00241
00242
00243 lFFArray.put ("code", lFF_ptr->getFamilyCode());
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 std::ostringstream oStream;
00257 oStream << "flight_date.segment.cabin.fare_families";
00258 ioPropertyTree.put_child (oStream.str(), lFFArray);
00259 #endif // BOOST_VERSION >= 104100
00260 }
00261 }
00262 }
00263 }
00264
00265
00266 void jsonBucketExport (bpt::ptree& ioPropertyTree,
00267 const FlightDate& iFlightDate) {
00272
00273 if (BomManager::hasList<LegDate> (iFlightDate) == false) {
00274 return;
00275 }
00276
00277
00278 const LegDateList_T& lLegDateList =
00279 BomManager::getList<LegDate> (iFlightDate);
00280 for (LegDateList_T::const_iterator itLD = lLegDateList.begin();
00281 itLD != lLegDateList.end(); ++itLD) {
00282 const LegDate* lLD_ptr = *itLD;
00283 assert (lLD_ptr != NULL);
00284
00285
00286 const LegCabinList_T& lLegCabinList =
00287 BomManager::getList<LegCabin> (*lLD_ptr);
00288 for (LegCabinList_T::const_iterator itLC = lLegCabinList.begin();
00289 itLC != lLegCabinList.end(); ++itLC) {
00290 const LegCabin* lLC_ptr = *itLC;
00291 assert (lLC_ptr != NULL);
00292
00293
00294 if (BomManager::hasList<Bucket> (*lLC_ptr) == false) {
00295 continue;
00296 }
00297
00298
00299 const BucketList_T& lBucketList = BomManager::getList<Bucket> (*lLC_ptr);
00300 for (BucketList_T::const_iterator itBuck = lBucketList.begin();
00301 itBuck != lBucketList.end(); ++itBuck) {
00302 const Bucket* lBucket_ptr = *itBuck;
00303 assert (lBucket_ptr != NULL);
00304
00305 #if BOOST_VERSION >= 104100
00306
00307 ioPropertyTree.put ("flight_date.leg.cabin.bucket.yield_range_upper",
00308 lBucket_ptr->getYieldRangeUpperValue());
00309
00310
00311
00312
00313
00314 #endif // BOOST_VERSION >= 104100
00315 }
00316 }
00317 }
00318 }
00319
00320
00321 void jsonBookingClassExport (bpt::ptree& ioPropertyTree,
00322 const BookingClass& iBookingClass,
00323 const std::string& iLeadingString) {
00330 std::ostringstream oStream;
00331 oStream << iBookingClass.getClassCode();
00332
00333 if (iBookingClass.getSubclassCode() != 0) {
00334 oStream << iBookingClass.getSubclassCode();
00335 }
00336
00337 #if BOOST_VERSION >= 104100
00338
00339 ioPropertyTree.put ("flight_date.segment.cabin.fare_family.booking_class.code",
00340 oStream.str());
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 #endif // BOOST_VERSION >= 104100
00360 }
00361
00362
00363 void jsonBookingClassExport (bpt::ptree& ioPropertyTree,
00364 const FlightDate& iFlightDate) {
00365
00366 if (BomManager::hasList<SegmentDate> (iFlightDate) == false) {
00367 return;
00368 }
00369
00370
00371 const SegmentDateList_T& lSegmentDateList =
00372 BomManager::getList<SegmentDate> (iFlightDate);
00373 for (SegmentDateList_T::const_iterator itSD = lSegmentDateList.begin();
00374 itSD != lSegmentDateList.end(); ++itSD) {
00375 const SegmentDate* lSD_ptr = *itSD;
00376 assert (lSD_ptr != NULL);
00377
00378
00379 const SegmentCabinList_T& lSegmentCabinList =
00380 BomManager::getList<SegmentCabin> (*lSD_ptr);
00381 for (SegmentCabinList_T::const_iterator itSC = lSegmentCabinList.begin();
00382 itSC != lSegmentCabinList.end(); ++itSC) {
00383 const SegmentCabin* lSC_ptr = *itSC;
00384 assert (lSC_ptr != NULL);
00385
00386
00387 std::ostringstream oLeadingStr;
00388
00389
00390 FamilyCode_T lFamilyCode ("NoFF");
00391
00392
00393 if (BomManager::hasList<FareFamily> (*lSC_ptr) == true) {
00394
00395
00396 const FareFamilyList_T& lFareFamilyList =
00397 BomManager::getList<FareFamily> (*lSC_ptr);
00398 for (FareFamilyList_T::const_iterator itFF = lFareFamilyList.begin();
00399 itFF != lFareFamilyList.end(); ++itFF) {
00400 const FareFamily* lFF_ptr = *itFF;
00401 assert (lFF_ptr != NULL);
00402
00403
00404 lFamilyCode = lFF_ptr->getFamilyCode();
00405
00406
00407 oLeadingStr << lFamilyCode << ", ";
00408
00409
00410 const BookingClassList_T& lBookingClassList =
00411 BomManager::getList<BookingClass> (*lFF_ptr);
00412 for (BookingClassList_T::const_iterator itBC =
00413 lBookingClassList.begin();
00414 itBC != lBookingClassList.end(); ++itBC) {
00415 const BookingClass* lBC_ptr = *itBC;
00416 assert (lBC_ptr != NULL);
00417
00418
00419 jsonBookingClassExport (ioPropertyTree, *lBC_ptr,
00420 oLeadingStr.str());
00421 }
00422 }
00423
00424 return;
00425 }
00426 assert (BomManager::hasList<FareFamily> (*lSC_ptr) == false);
00427
00428
00429
00430 oLeadingStr << lFamilyCode << ", ";
00431
00432
00433 const BookingClassList_T& lBookingClassList =
00434 BomManager::getList<BookingClass> (*lSC_ptr);
00435 for (BookingClassList_T::const_iterator itBC =
00436 lBookingClassList.begin();
00437 itBC != lBookingClassList.end(); ++itBC) {
00438 const BookingClass* lBC_ptr = *itBC;
00439 assert (lBC_ptr != NULL);
00440
00441
00442 jsonBookingClassExport (ioPropertyTree, *lBC_ptr, oLeadingStr.str());
00443 }
00444 }
00445 }
00446 }
00447
00448
00449 void BomJSONExport::jsonExport (std::ostream& oStream,
00450 const FlightDate& iFlightDate) {
00451
00452 FlagSaver flagSaver (oStream);
00453
00454
00455 bpt::ptree pt;
00456
00457 #if BOOST_VERSION >= 104100
00458
00461 const AirlineCode_T& lAirlineCode = iFlightDate.getAirlineCode();
00462 const FlightNumber_T& lFlightNumber = iFlightDate.getFlightNumber();
00463 const Date_T& lFlightDateDate = iFlightDate.getDepartureDate();
00464
00465
00466 pt.put ("flight_date.airline_code", lAirlineCode);
00467
00468
00469 pt.put ("flight_date.flight_number", lFlightNumber);
00470
00471
00472 const std::string& lDepartureDateStr =
00473 boost::gregorian::to_simple_string (lFlightDateDate);
00474 pt.put ("flight_date.departure_date", lDepartureDateStr);
00475 #endif // BOOST_VERSION >= 104100
00476
00477
00478 jsonLegDateExport (pt, iFlightDate);
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 #if BOOST_VERSION >= 104100
00493
00494 write_json (oStream, pt);
00495 #endif // BOOST_VERSION >= 104100
00496 }
00497
00498 }