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