Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <sstream>
00007
00008 #include <stdair/bom/BomKeyManager.hpp>
00009 #include <stdair/bom/BomManager.hpp>
00010 #include <stdair/bom/BomRoot.hpp>
00011 #include <stdair/bom/Inventory.hpp>
00012 #include <stdair/bom/FlightDate.hpp>
00013 #include <stdair/bom/LegDate.hpp>
00014 #include <stdair/bom/SegmentDate.hpp>
00015 #include <stdair/bom/LegCabin.hpp>
00016 #include <stdair/bom/SegmentCabin.hpp>
00017 #include <stdair/bom/FareFamily.hpp>
00018 #include <stdair/bom/BookingClass.hpp>
00019 #include <stdair/bom/BomRetriever.hpp>
00020 #include <stdair/bom/ParsedKey.hpp>
00021 #include <stdair/bom/AirportPair.hpp>
00022 #include <stdair/service/Logger.hpp>
00023
00024 namespace stdair {
00025
00026
00027 Inventory* BomRetriever::
00028 retrieveInventoryFromLongKey (const BomRoot& iBomRoot,
00029 const std::string& iFullKeyStr) {
00030 Inventory* oInventory_ptr = NULL;
00031
00032
00033 const InventoryKey& lInventoryKey =
00034 BomKeyManager::extractInventoryKey (iFullKeyStr);
00035
00036 oInventory_ptr = iBomRoot.getInventory (lInventoryKey);
00037
00038 return oInventory_ptr;
00039 }
00040
00041
00042 Inventory* BomRetriever::retrieveInventoryFromKey (const BomRoot& iBomRoot,
00043 const InventoryKey& iKey) {
00044 Inventory* oInventory_ptr = NULL;
00045
00046
00047 oInventory_ptr = iBomRoot.getInventory (iKey);
00048
00049 return oInventory_ptr;
00050 }
00051
00052
00053 Inventory* BomRetriever::
00054 retrieveInventoryFromKey (const BomRoot& iBomRoot,
00055 const AirlineCode_T& iAirlineCode) {
00056 Inventory* oInventory_ptr = NULL;
00057
00058
00059 const InventoryKey lKey (iAirlineCode);
00060 oInventory_ptr = iBomRoot.getInventory (lKey);
00061
00062 return oInventory_ptr;
00063 }
00064
00065
00066 FlightDate* BomRetriever::
00067 retrieveFlightDateFromLongKey (const BomRoot& iBomRoot,
00068 const std::string& iFullKeyStr) {
00069 FlightDate* oFlightDate_ptr = NULL;
00070
00071
00072 Inventory* oInventory_ptr =
00073 BomRetriever::retrieveInventoryFromLongKey (iBomRoot, iFullKeyStr);
00074 if (oInventory_ptr == NULL) {
00075 return oFlightDate_ptr;
00076 }
00077 assert (oInventory_ptr != NULL);
00078
00079
00080 const FlightDateKey& lFlightDateKey =
00081 BomKeyManager::extractFlightDateKey (iFullKeyStr);
00082
00083 oFlightDate_ptr = oInventory_ptr->getFlightDate (lFlightDateKey);
00084
00085 return oFlightDate_ptr;
00086 }
00087
00088
00089 FlightDate* BomRetriever::
00090 retrieveFlightDateFromKeySet (const BomRoot& iBomRoot,
00091 const AirlineCode_T& iAirlineCode,
00092 const FlightNumber_T& iFlightNumber,
00093 const Date_T& iFlightDateDate) {
00094 FlightDate* oFlightDate_ptr = NULL;
00095
00096
00097 Inventory* oInventory_ptr =
00098 BomRetriever::retrieveInventoryFromKey (iBomRoot, iAirlineCode);
00099 if (oInventory_ptr == NULL) {
00100 return oFlightDate_ptr;
00101 }
00102 assert (oInventory_ptr != NULL);
00103
00104
00105 oFlightDate_ptr = retrieveFlightDateFromKey (*oInventory_ptr,
00106 iFlightNumber, iFlightDateDate);
00107
00108 return oFlightDate_ptr;
00109 }
00110
00111
00112 FlightDate* BomRetriever::
00113 retrieveFlightDateFromLongKey (const Inventory& iInventory,
00114 const std::string& iFullKeyStr) {
00115 FlightDate* oFlightDate_ptr = NULL;
00116
00117
00118 const FlightDateKey& lFlightDateKey =
00119 BomKeyManager::extractFlightDateKey (iFullKeyStr);
00120
00121 oFlightDate_ptr = iInventory.getFlightDate (lFlightDateKey);
00122
00123 return oFlightDate_ptr;
00124 }
00125
00126
00127 FlightDate* BomRetriever::
00128 retrieveFlightDateFromKey (const Inventory& iInventory,
00129 const FlightDateKey& iKey) {
00130 FlightDate* oFlightDate_ptr = NULL;
00131
00132
00133 oFlightDate_ptr = iInventory.getFlightDate (iKey);
00134
00135 return oFlightDate_ptr;
00136 }
00137
00138
00139 FlightDate* BomRetriever::
00140 retrieveFlightDateFromKey (const Inventory& iInventory,
00141 const FlightNumber_T& iFlightNumber,
00142 const Date_T& iFlightDateDate) {
00143 FlightDate* oFlightDate_ptr = NULL;
00144
00145
00146 const FlightDateKey lKey (iFlightNumber, iFlightDateDate);
00147 oFlightDate_ptr = iInventory.getFlightDate (lKey);
00148
00149 return oFlightDate_ptr;
00150 }
00151
00152
00153 SegmentDate* BomRetriever::
00154 retrieveSegmentDateFromLongKey (const BomRoot& iBomRoot,
00155 const std::string& iFullKeyStr) {
00156 SegmentDate* oSegmentDate_ptr = NULL;
00157
00158
00159 FlightDate* oFlightDate_ptr =
00160 BomRetriever::retrieveFlightDateFromLongKey (iBomRoot, iFullKeyStr);
00161 if (oFlightDate_ptr == NULL) {
00162 return oSegmentDate_ptr;
00163 }
00164 assert (oFlightDate_ptr != NULL);
00165
00166
00167 const SegmentDateKey& lSegmentDateKey =
00168 BomKeyManager::extractSegmentDateKey (iFullKeyStr);
00169
00170 oSegmentDate_ptr = oFlightDate_ptr->getSegmentDate (lSegmentDateKey);
00171
00172 return oSegmentDate_ptr;
00173 }
00174
00175
00176 SegmentDate* BomRetriever::
00177 retrieveSegmentDateFromLongKey (const Inventory& iInventory,
00178 const std::string& iFullKeyStr) {
00179 SegmentDate* oSegmentDate_ptr = NULL;
00180
00181 ParsedKey lParsedKey = BomKeyManager::extractKeys (iFullKeyStr);
00182
00183 if (iInventory.getAirlineCode() != lParsedKey._airlineCode) {
00184 STDAIR_LOG_DEBUG ("Airline code: " << lParsedKey._airlineCode);
00185 return oSegmentDate_ptr;
00186 }
00187
00188 FlightDate* lFlightDate_ptr =
00189 retrieveFlightDateFromKey (iInventory, lParsedKey.getFlightDateKey());
00190 if (lFlightDate_ptr == NULL) {
00191 STDAIR_LOG_DEBUG ("Flight-date key: "
00192 << lParsedKey.getFlightDateKey().toString());
00193 return oSegmentDate_ptr;
00194 }
00195
00196 oSegmentDate_ptr =
00197 retrieveSegmentDateFromKey (*lFlightDate_ptr, lParsedKey.getSegmentKey());
00198 if (oSegmentDate_ptr == NULL) {
00199 STDAIR_LOG_DEBUG ("Segment-date key: "
00200 << lParsedKey.getSegmentKey().toString());
00201 return oSegmentDate_ptr;
00202 }
00203
00204 return oSegmentDate_ptr;
00205 }
00206
00207
00208 SegmentDate* BomRetriever::
00209 retrieveSegmentDateFromLongKey (const FlightDate& iFlightDate,
00210 const std::string& iFullKeyStr) {
00211 SegmentDate* oSegmentDate_ptr = NULL;
00212
00213
00214 const SegmentDateKey& lSegmentDateKey =
00215 BomKeyManager::extractSegmentDateKey (iFullKeyStr);
00216
00217 oSegmentDate_ptr = iFlightDate.getSegmentDate (lSegmentDateKey);
00218
00219 return oSegmentDate_ptr;
00220 }
00221
00222
00223 SegmentDate* BomRetriever::
00224 retrieveSegmentDateFromKey (const FlightDate& iFlightDate,
00225 const SegmentDateKey& iKey) {
00226 SegmentDate* oSegmentDate_ptr = NULL;
00227
00228
00229 oSegmentDate_ptr = iFlightDate.getSegmentDate (iKey);
00230
00231 return oSegmentDate_ptr;
00232 }
00233
00234
00235 SegmentDate* BomRetriever::
00236 retrieveSegmentDateFromKey (const FlightDate& iFlightDate,
00237 const AirportCode_T& iOrigin,
00238 const AirportCode_T& iDestination) {
00239 SegmentDate* oSegmentDate_ptr = NULL;
00240
00241
00242 const SegmentDateKey lKey (iOrigin, iDestination);
00243 oSegmentDate_ptr = iFlightDate.getSegmentDate (lKey);
00244
00245 return oSegmentDate_ptr;
00246 }
00247
00248
00249 BookingClass* BomRetriever::
00250 retrieveBookingClassFromLongKey (const Inventory& iInventory,
00251 const std::string& iFullKeyStr,
00252 const ClassCode_T& iClassCode) {
00253 BookingClass* oBookingClass_ptr = NULL;
00254
00255 SegmentDate* lSegmentDate_ptr = retrieveSegmentDateFromLongKey (iInventory,
00256 iFullKeyStr);
00257
00258 if (lSegmentDate_ptr == NULL) {
00259 return oBookingClass_ptr;
00260 }
00261 assert (lSegmentDate_ptr != NULL);
00262
00263
00264 oBookingClass_ptr =
00265 BomManager::getObjectPtr<BookingClass> (*lSegmentDate_ptr, iClassCode);
00266
00267 return oBookingClass_ptr;
00268 }
00269
00270
00271 AirportPair* BomRetriever::
00272 retrieveAirportPairFromKeySet (const BomRoot& iBomRoot,
00273 const stdair::AirportCode_T& iOrigin,
00274 const stdair::AirportCode_T& iDestination) {
00275
00276
00277 const AirportPairKey lAirportPairKey (iOrigin, iDestination);
00278
00279
00280
00281 AirportPair* oAirportPair_ptr = BomManager::
00282 getObjectPtr<AirportPair> (iBomRoot, lAirportPairKey.toString());
00283
00284 return oAirportPair_ptr;
00285
00286 }
00287
00288
00289 void BomRetriever::
00290 retrieveDatePeriodListFromKey (const AirportPair& iAirportPair,
00291 const stdair::Date_T& iDepartureDate,
00292 stdair::DatePeriodList_T& ioDatePeriodList) {
00293
00294
00295 const DatePeriodList_T& lFareDatePeriodList =
00296 BomManager::getList<DatePeriod> (iAirportPair);
00297
00298
00299 for (DatePeriodList_T::const_iterator itDateRange =
00300 lFareDatePeriodList.begin();
00301 itDateRange != lFareDatePeriodList.end(); ++itDateRange) {
00302
00303 DatePeriod* lCurrentFareDatePeriod_ptr = *itDateRange ;
00304 assert (lCurrentFareDatePeriod_ptr != NULL);
00305
00306
00307 const bool isDepartureDateValid =
00308 lCurrentFareDatePeriod_ptr->isDepartureDateValid (iDepartureDate);
00309
00310
00311
00312 if (isDepartureDateValid == true) {
00313 ioDatePeriodList.push_back(lCurrentFareDatePeriod_ptr);
00314 }
00315 }
00316
00317 }
00318
00319
00320 void BomRetriever::
00321 retrieveDatePeriodListFromKeySet (const BomRoot& iBomRoot,
00322 const stdair::AirportCode_T& iOrigin,
00323 const stdair::AirportCode_T& iDestination,
00324 const stdair::Date_T& iDepartureDate,
00325 stdair::DatePeriodList_T& ioDatePeriodList) {
00326
00327
00328 AirportPair* oAirportPair_ptr =
00329 BomRetriever::retrieveAirportPairFromKeySet(iBomRoot, iOrigin,
00330 iDestination);
00331 if (oAirportPair_ptr == NULL) {
00332 return;
00333 }
00334 assert (oAirportPair_ptr != NULL);
00335
00336
00337 BomRetriever::retrieveDatePeriodListFromKey (*oAirportPair_ptr, iDepartureDate,
00338 ioDatePeriodList);
00339
00340 }
00341
00342 }