Go to the documentation of this file.00001
00002
00003
00004
00005 #include <cassert>
00006 #include <sstream>
00007
00008 #include <stdair/basic/BasConst_Period_BOM.hpp>
00009 #include <stdair/service/Logger.hpp>
00010
00011 #include <airsched/AIRSCHED_Types.hpp>
00012 #include <airsched/bom/FlightPeriodStruct.hpp>
00013
00014 namespace AIRSCHED {
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
00054
00055
00056
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
00066 const bool insertSuccessful = _airportList.insert (iAirport).second;
00067
00068 if (insertSuccessful == false) {
00069
00070 }
00071
00072
00073 _airportOrderedList.push_back (iAirport);
00074 }
00075 }
00076
00077
00078 void FlightPeriodStruct::buildSegments () {
00079
00080
00081
00082
00083
00084
00085
00086
00087
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
00105 _airportList.clear();
00106 _airportOrderedList.clear();
00107 }
00108
00109
00110 void FlightPeriodStruct::
00111 addSegmentCabin (const SegmentStruct& iSegment,
00112 const SegmentCabinStruct& iCabin) {
00113
00114
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
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
00151
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
00166
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
00194 assert (itSegment != _segmentList.end());
00195 SegmentStruct& lSegment = *itSegment;
00196
00197
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
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
00232
00233
00234 for (SegmentStructList_T::iterator itSegment = _segmentList.begin();
00235 itSegment != _segmentList.end(); ++itSegment) {
00236 SegmentStruct& lSegment = *itSegment;
00237
00238
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
00263 assert (itCabin != lSegment._cabinList.end());
00264 SegmentCabinStruct& lCabin = *itCabin;
00265 lCabin._fareFamilies.push_back(iFareFamily);
00266 }
00267 }
00268
00269 }