Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <string>
00007 #include <sstream>
00008
00009 #include <stdair/basic/BasConst_BomDisplay.hpp>
00010 #include <stdair/bom/BomManager.hpp>
00011 #include <stdair/bom/BomRoot.hpp>
00012 #include <stdair/bom/Inventory.hpp>
00013 #include <stdair/bom/FlightPeriod.hpp>
00014 #include <stdair/bom/SegmentPeriod.hpp>
00015 #include <stdair/bom/BookingRequestStruct.hpp>
00016 #include <stdair/bom/TravelSolutionStruct.hpp>
00017 #include <stdair/service/Logger.hpp>
00018
00019 #include <airsched/bom/ReachableUniverse.hpp>
00020 #include <airsched/bom/OriginDestinationSet.hpp>
00021 #include <airsched/bom/SegmentPathPeriod.hpp>
00022 #include <airsched/command/SegmentPathProvider.hpp>
00023
00024 namespace AIRSCHED {
00025
00026
00027 void SegmentPathProvider::
00028 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00029 const stdair::BomRoot& iBomRoot,
00030 const stdair::BookingRequestStruct& iBookingRequest) {
00031
00032
00033 const stdair::AirportCode_T& lOrigin = iBookingRequest.getOrigin ();
00034 const ReachableUniverse* lReachableUniverse_ptr =
00035 stdair::BomManager::getObjectPtr<ReachableUniverse> (iBomRoot, lOrigin);
00036 if (lReachableUniverse_ptr != NULL) {
00037 buildSegmentPathList (ioTravelSolutionList, *lReachableUniverse_ptr,
00038 iBookingRequest);
00039 }
00040 }
00041
00042
00043 void SegmentPathProvider::
00044 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00045 const ReachableUniverse& iReachableUniverse,
00046 const stdair::BookingRequestStruct& iBookingRequest) {
00047
00048
00049 const stdair::AirportCode_T& lDestination = iBookingRequest.getDestination();
00050 const OriginDestinationSet* lOriginDestinationSet_ptr =
00051 stdair::BomManager::getObjectPtr<OriginDestinationSet> (iReachableUniverse,
00052 lDestination);
00053 if (lOriginDestinationSet_ptr != NULL) {
00054 buildSegmentPathList (ioTravelSolutionList, *lOriginDestinationSet_ptr,
00055 iBookingRequest);
00056 }
00057 }
00058
00059
00060 void SegmentPathProvider::
00061 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00062 const OriginDestinationSet& iOriginDestinationSet,
00063 const stdair::BookingRequestStruct& iBookingRequest) {
00064
00065 const stdair::Date_T& lPreferedDepartureDate =
00066 iBookingRequest.getPreferedDepartureDate ();
00067
00068
00069
00070 const SegmentPathPeriodList_T& lSegmentPathPeriodList =
00071 stdair::BomManager::getList<SegmentPathPeriod> (iOriginDestinationSet);
00072 for (SegmentPathPeriodList_T::const_iterator itSegmentPath =
00073 lSegmentPathPeriodList.begin ();
00074 itSegmentPath != lSegmentPathPeriodList.end (); ++itSegmentPath) {
00075 const SegmentPathPeriod* lCurrentSegmentPath_ptr = *itSegmentPath;
00076 assert (lCurrentSegmentPath_ptr != NULL);
00077 if (lCurrentSegmentPath_ptr->isDepartureDateValid(lPreferedDepartureDate)){
00078 buildSegmentPathList (ioTravelSolutionList, *lCurrentSegmentPath_ptr,
00079 iBookingRequest);
00080 }
00081 }
00082 }
00083
00084
00085 void SegmentPathProvider::
00086 buildSegmentPathList (stdair::TravelSolutionList_T& ioTravelSolutionList,
00087 const SegmentPathPeriod& iSegmentPathPeriod,
00088 const stdair::BookingRequestStruct& iBookingRequest) {
00089
00090 stdair::TravelSolutionStruct lTravelSolution;
00091
00092
00093
00094 const stdair::Date_T& lPreferedDepartureDate =
00095 iBookingRequest.getPreferedDepartureDate ();
00096 const stdair::SegmentPeriodList_T& lSegmentPeriodList =
00097 stdair::BomManager::getList<stdair::SegmentPeriod> (iSegmentPathPeriod);
00098 const DateOffsetList_T& lBoardingDateOffsetList =
00099 iSegmentPathPeriod.getBoardingDateOffsetList ();
00100 assert (lSegmentPeriodList.size() == lBoardingDateOffsetList.size());
00101 DateOffsetList_T::const_iterator itOffset = lBoardingDateOffsetList.begin();
00102 for (stdair::SegmentPeriodList_T::const_iterator itSegment =
00103 lSegmentPeriodList.begin();
00104 itSegment != lSegmentPeriodList.end(); ++itSegment) {
00105 const stdair::SegmentPeriod* lSegmentPeriod_ptr = *itSegment;
00106 assert (lSegmentPeriod_ptr != NULL);
00107 const stdair::DateOffset_T& lBoardingDateOffset = *itOffset;
00108
00109
00110 const stdair::DateOffset_T& lSegmentBoardingDateOffset =
00111 lSegmentPeriod_ptr->getBoardingDateOffset();
00112 const stdair::Date_T& lReferenceFlightDate = lPreferedDepartureDate
00113 + lBoardingDateOffset - lSegmentBoardingDateOffset;
00114
00115
00116 const stdair::FlightPeriod& lFlightPeriod =
00117 stdair::BomManager::getParent<stdair::FlightPeriod>(*lSegmentPeriod_ptr);
00118 const stdair::Inventory& lInventory =
00119 stdair::BomManager::getParent<stdair::Inventory> (lFlightPeriod);
00120 const stdair::Duration_T lBoardingTime = lSegmentPeriod_ptr->getBoardingTime();
00121 std::ostringstream oStr;
00122 oStr << lInventory.getAirlineCode()
00123 << stdair::DEFAULT_KEY_FLD_DELIMITER
00124 << lFlightPeriod.getFlightNumber()
00125 << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
00126 << boost::gregorian::to_simple_string (lReferenceFlightDate)
00127 << stdair::DEFAULT_KEY_FLD_DELIMITER
00128 << lSegmentPeriod_ptr->getBoardingPoint()
00129 << stdair::DEFAULT_KEY_SUB_FLD_DELIMITER
00130 << lSegmentPeriod_ptr->getOffPoint()
00131 << stdair::DEFAULT_KEY_FLD_DELIMITER
00132 << lBoardingTime;
00133
00134 lTravelSolution.addSegment (oStr.str());
00135
00136 ++itOffset;
00137 }
00138 ioTravelSolutionList.push_back (lTravelSolution);
00139 }
00140
00141 }