$treeview $search $mathjax
00001 // ////////////////////////////////////////////////////////////////////// 00002 // Import section 00003 // ////////////////////////////////////////////////////////////////////// 00004 // STL 00005 #include <cassert> 00006 #include <sstream> 00007 // StdAir 00008 #include <stdair/basic/BasConst_Period_BOM.hpp> 00009 #include <stdair/service/Logger.hpp> 00010 // AirTSP 00011 #include <airtsp/AIRTSP_Types.hpp> 00012 #include <airtsp/bom/FlightPeriodStruct.hpp> 00013 00014 namespace AIRTSP { 00015 00016 // //////////////////////////////////////////////////////////////////// 00017 FlightPeriodStruct::FlightPeriodStruct () 00018 : _dateRange (stdair::BOOST_DEFAULT_DATE_PERIOD), 00019 _dow (stdair::DEFAULT_DOW_STRING), 00020 _legAlreadyDefined (false), _itSeconds (0) { 00021 } 00022 00023 // //////////////////////////////////////////////////////////////////// 00024 stdair::Date_T FlightPeriodStruct::getDate() const { 00025 return stdair::Date_T (_itYear, _itMonth, _itDay); 00026 } 00027 00028 // //////////////////////////////////////////////////////////////////// 00029 stdair::Duration_T FlightPeriodStruct::getTime() const { 00030 return boost::posix_time::hours (_itHours) 00031 + boost::posix_time::minutes (_itMinutes) 00032 + boost::posix_time::seconds (_itSeconds); 00033 } 00034 00035 // //////////////////////////////////////////////////////////////////// 00036 const std::string FlightPeriodStruct::describe() const { 00037 std::ostringstream ostr; 00038 ostr << _airlineCode << _flightNumber << ", " << _dateRange 00039 << " - " << _dow << std::endl; 00040 00041 for (LegStructList_T::const_iterator itLeg = _legList.begin(); 00042 itLeg != _legList.end(); ++itLeg) { 00043 const LegStruct& lLeg = *itLeg; 00044 ostr << lLeg.describe(); 00045 } 00046 00047 for (SegmentStructList_T::const_iterator itSegment = _segmentList.begin(); 00048 itSegment != _segmentList.end(); ++itSegment) { 00049 const SegmentStruct& lSegment = *itSegment; 00050 ostr << lSegment.describe(); 00051 } 00052 00053 //ostr << "[Debug] - Staging Leg: "; 00054 //ostr << _itLeg.describe(); 00055 //ostr << "[Debug] - Staging Cabin: "; 00056 //ostr << _itCabin.describe(); 00057 00058 return ostr.str(); 00059 } 00060 00061 // //////////////////////////////////////////////////////////////////// 00062 void FlightPeriodStruct::addAirport (const stdair::AirportCode_T& iAirport) { 00063 AirportList_T::const_iterator itAirport = _airportList.find (iAirport); 00064 if (itAirport == _airportList.end()) { 00065 // Add the airport code to the airport set 00066 const bool insertSuccessful = _airportList.insert (iAirport).second; 00067 00068 if (insertSuccessful == false) { 00069 // TODO: throw an exception 00070 } 00071 00072 // Add the airport code to the airport vector 00073 _airportOrderedList.push_back (iAirport); 00074 } 00075 } 00076 00077 // //////////////////////////////////////////////////////////////////// 00078 void FlightPeriodStruct::buildSegments () { 00079 // The list of airports encompasses all the airports on which 00080 // the flight takes off or lands. Moreover, that list is 00081 // time-ordered: the first airport is the initial departure of 00082 // the flight, and the last airport is the eventual point of 00083 // rest of the flight. 00084 // Be l the size of the ordered list of airports. 00085 // We want to generate all the segment combinations from the legs 00086 // and, hence, from all the possible (time-ordered) airport pairs. 00087 // Thus, we both iterator on i=0...l-1 and j=i+1...l 00088 assert (_airportOrderedList.size() >= 2); 00089 00090 _segmentList.clear(); 00091 for (AirportOrderedList_T::const_iterator itAirport_i = 00092 _airportOrderedList.begin(); 00093 itAirport_i != _airportOrderedList.end()-1; ++itAirport_i) { 00094 for (AirportOrderedList_T::const_iterator itAirport_j = itAirport_i + 1; 00095 itAirport_j != _airportOrderedList.end(); ++itAirport_j) { 00096 SegmentStruct lSegmentStruct; 00097 lSegmentStruct._boardingPoint = *itAirport_i; 00098 lSegmentStruct._offPoint = *itAirport_j; 00099 00100 _segmentList.push_back (lSegmentStruct); 00101 } 00102 } 00103 00104 // Clear the lists of airports, so that it is ready for the next flight 00105 _airportList.clear(); 00106 _airportOrderedList.clear(); 00107 } 00108 00109 // //////////////////////////////////////////////////////////////////// 00110 void FlightPeriodStruct:: 00111 addSegmentCabin (const SegmentStruct& iSegment, 00112 const SegmentCabinStruct& iCabin) { 00113 // Retrieve the Segment structure corresponding to the (boarding, off) point 00114 // pair. 00115 SegmentStructList_T::iterator itSegment = _segmentList.begin(); 00116 for ( ; itSegment != _segmentList.end(); ++itSegment) { 00117 const SegmentStruct& lSegment = *itSegment; 00118 00119 const stdair::AirportCode_T& lBoardingPoint = iSegment._boardingPoint; 00120 const stdair::AirportCode_T& lOffPoint = iSegment._offPoint; 00121 if (lSegment._boardingPoint == lBoardingPoint 00122 && lSegment._offPoint == lOffPoint) { 00123 break; 00124 } 00125 } 00126 00132 if (itSegment == _segmentList.end()) { 00133 std::ostringstream oStr; 00134 oStr << "Within the schedule input file, there is a flight, for which " 00135 << "the airports of segments and those of the legs " 00136 << "do not correspond"; 00137 STDAIR_LOG_ERROR (oStr.str()); 00138 throw SegmentDateNotFoundException (oStr.str()); 00139 } 00140 00141 // Add the Cabin structure to the Segment Cabin structure. 00142 assert (itSegment != _segmentList.end()); 00143 SegmentStruct& lSegment = *itSegment; 00144 lSegment._cabinList.push_back (iCabin); 00145 } 00146 00147 // //////////////////////////////////////////////////////////////////// 00148 void FlightPeriodStruct:: 00149 addSegmentCabin (const SegmentCabinStruct& iCabin) { 00150 // Iterate on all the Segment structures (as they get the same cabin 00151 // definitions) 00152 for (SegmentStructList_T::iterator itSegment = _segmentList.begin(); 00153 itSegment != _segmentList.end(); ++itSegment) { 00154 SegmentStruct& lSegment = *itSegment; 00155 00156 lSegment._cabinList.push_back (iCabin); 00157 } 00158 } 00159 00160 // //////////////////////////////////////////////////////////////////// 00161 void FlightPeriodStruct:: 00162 addFareFamily (const SegmentStruct& iSegment, 00163 const SegmentCabinStruct& iCabin, 00164 const FareFamilyStruct& iFareFamily) { 00165 // Retrieve the Segment structure corresponding to the (boarding, off) point 00166 // pair. 00167 SegmentStructList_T::iterator itSegment = _segmentList.begin(); 00168 for ( ; itSegment != _segmentList.end(); ++itSegment) { 00169 const SegmentStruct& lSegment = *itSegment; 00170 00171 const stdair::AirportCode_T& lBoardingPoint = iSegment._boardingPoint; 00172 const stdair::AirportCode_T& lOffPoint = iSegment._offPoint; 00173 if (lSegment._boardingPoint == lBoardingPoint 00174 && lSegment._offPoint == lOffPoint) { 00175 break; 00176 } 00177 } 00178 00184 if (itSegment == _segmentList.end()) { 00185 std::ostringstream oStr; 00186 oStr << "Within the schedule input file, there is a flight, for which " 00187 << "the airports of segments and those of the legs " 00188 << "do not correspond"; 00189 STDAIR_LOG_ERROR (oStr.str()); 00190 throw SegmentDateNotFoundException (oStr.str()); 00191 } 00192 00193 // Add the Cabin structure to the Segment Cabin structure. 00194 assert (itSegment != _segmentList.end()); 00195 SegmentStruct& lSegment = *itSegment; 00196 00197 // Retrieve the Segment cabin structure given the cabin code 00198 SegmentCabinStructList_T::iterator itCabin = lSegment._cabinList.begin(); 00199 for ( ; itCabin != lSegment._cabinList.end(); ++itCabin) { 00200 const SegmentCabinStruct& lCabin = *itCabin; 00201 00202 const stdair::CabinCode_T& lCabinCode = lCabin._cabinCode; 00203 if (iCabin._cabinCode == lCabinCode) { 00204 break; 00205 } 00206 } 00207 00213 if (itCabin == lSegment._cabinList.end()) { 00214 std::ostringstream oStr; 00215 oStr << "Within the schedule input file, there is a flight " 00216 << "for which the cabin code does not exist."; 00217 STDAIR_LOG_ERROR (oStr.str()); 00218 throw SegmentDateNotFoundException (oStr.str()); 00219 } 00220 00221 // Add the Cabin structure to the Segment Cabin structure. 00222 assert (itCabin != lSegment._cabinList.end()); 00223 SegmentCabinStruct& lCabin = *itCabin; 00224 lCabin._fareFamilies.push_back(iFareFamily); 00225 } 00226 00227 // //////////////////////////////////////////////////////////////////// 00228 void FlightPeriodStruct:: 00229 addFareFamily (const SegmentCabinStruct& iCabin, 00230 const FareFamilyStruct& iFareFamily) { 00231 // Iterate on all the Segment structures (as they get the same cabin 00232 // definitions) 00233 00234 for (SegmentStructList_T::iterator itSegment = _segmentList.begin(); 00235 itSegment != _segmentList.end(); ++itSegment) { 00236 SegmentStruct& lSegment = *itSegment; 00237 00238 // Retrieve the Segment cabin structure given the cabin code 00239 SegmentCabinStructList_T::iterator itCabin = lSegment._cabinList.begin(); 00240 for ( ; itCabin != lSegment._cabinList.end(); ++itCabin) { 00241 const SegmentCabinStruct& lCabin = *itCabin; 00242 00243 const stdair::CabinCode_T& lCabinCode = lCabin._cabinCode; 00244 if (iCabin._cabinCode == lCabinCode) { 00245 break; 00246 } 00247 } 00248 00254 if (itCabin == lSegment._cabinList.end()) { 00255 std::ostringstream oStr; 00256 oStr << "Within the schedule input file, there is a flight " 00257 << "for which the cabin code does not exist."; 00258 STDAIR_LOG_ERROR (oStr.str()); 00259 throw SegmentDateNotFoundException (oStr.str()); 00260 } 00261 00262 // Add the Cabin structure to the Segment Cabin structure. 00263 assert (itCabin != lSegment._cabinList.end()); 00264 SegmentCabinStruct& lCabin = *itCabin; 00265 lCabin._fareFamilies.push_back(iFareFamily); 00266 } 00267 } 00268 00269 }