AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InventoryParserHelper.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // StdAir
7 #include <stdair/service/Logger.hpp>
8 #include <stdair/stdair_exceptions.hpp>
9 // Airinv
11 //#define BOOST_SPIRIT_DEBUG
13 
14 //
15 namespace bsc = boost::spirit::classic;
16 
17 namespace AIRINV {
18 
19  namespace InventoryParserHelper {
20 
21  // //////////////////////////////////////////////////////////////////
22  // Semantic actions
23  // //////////////////////////////////////////////////////////////////
24 
27  : _flightDate (ioFlightDate) {
28  }
29 
30  // //////////////////////////////////////////////////////////////////
33  : ParserSemanticAction (ioFlightDate) {
34  }
35 
36  // //////////////////////////////////////////////////////////////////
38  iterator_t iStrEnd) const {
40  }
41 
42  // //////////////////////////////////////////////////////////////////
45  : ParserSemanticAction (ioFlightDate) {
46  }
47 
48  // //////////////////////////////////////////////////////////////////
50  iterator_t iStrEnd) const {
51  const stdair::AirlineCode_T lAirlineCode (iStr, iStrEnd);
52  _flightDate._airlineCode = lAirlineCode;
53 
54  // As that's the beginning of a new flight, all the list must be reset
55  // 1. Leg branch of the tree
56  _flightDate._legList.clear();
60 
61  // 2. Segment branch of the tree
62  _flightDate._segmentList.clear();
67  }
68 
69  // //////////////////////////////////////////////////////////////////
71  : ParserSemanticAction (ioFlightDate) {
72  }
73 
74  // //////////////////////////////////////////////////////////////////
75  void storeFlightNumber::operator() (unsigned int iNumber) const {
76  _flightDate._flightNumber = iNumber;
77  }
78 
79  // //////////////////////////////////////////////////////////////////
81  : ParserSemanticAction (ioFlightDate) {
82  }
83 
84  // //////////////////////////////////////////////////////////////////
86  iterator_t iStrEnd) const {
88  }
89 
90  // //////////////////////////////////////////////////////////////////
92  : ParserSemanticAction (ioFlightDate) {
93  }
94 
95  // //////////////////////////////////////////////////////////////////
97  iterator_t iStrEnd) const {
98  const std::string lFlightTypeCodeStr (iStr, iStrEnd);
99  const FlightTypeCode lFlightTypeCode (lFlightTypeCodeStr);
100  _flightDate._flightTypeCode = lFlightTypeCode.getCode();
101  //STDAIR_LOG_DEBUG ("FlightType code: " << lFlightTypeCode);
102  }
103 
104  // //////////////////////////////////////////////////////////////////
107  : ParserSemanticAction (ioFlightDate) {
108  }
109 
110  // //////////////////////////////////////////////////////////////////
112  iterator_t iStrEnd) const {
113  const std::string lFlightVisibilityCodeStr (iStr, iStrEnd);
114  const FlightVisibilityCode lFlightVisibilityCode(lFlightVisibilityCodeStr);
115  _flightDate._flightVisibilityCode = lFlightVisibilityCode.getCode();
116  //STDAIR_LOG_DEBUG ("FlightVisibility code: " << lFlightVisibilityCode);
117  }
118 
119  // //////////////////////////////////////////////////////////////////
122  : ParserSemanticAction (ioFlightDate) {
123  }
124 
125  // //////////////////////////////////////////////////////////////////
127  iterator_t iStrEnd) const {
128  stdair::AirportCode_T lBoardingPoint (iStr, iStrEnd);
129 
130  // ///////////////////
131  // If this is not the first leg-date of the flight-date,
132  // the already parsed leg-date must be added to the flight-date.
133  if (_flightDate._itLeg._cabinList.empty() == false) {
137  }
138 
139  // As that's the beginning of a new leg-date,
140  // (re-)initialise the leg-cabin branch of the tree
141  _flightDate._itLeg._cabinList.clear();
145 
146 
147  // ///////////////////
148  // Set the (new) boarding point
149  _flightDate._itLeg._boardingPoint = lBoardingPoint;
150 
151  // Add the airport code if it is not already stored in the airport lists
152  _flightDate.addAirport (lBoardingPoint);
153  }
154 
155  // //////////////////////////////////////////////////////////////////
158  : ParserSemanticAction (ioFlightDate) {
159  }
160 
161  // //////////////////////////////////////////////////////////////////
163  iterator_t iStrEnd) const {
164  stdair::AirportCode_T lOffPoint (iStr, iStrEnd);
165  _flightDate._itLeg._offPoint = lOffPoint;
166 
167  // Add the airport code if it is not already stored in the airport lists
168  _flightDate.addAirport (lOffPoint);
169  }
170 
171  // //////////////////////////////////////////////////////////////////
173  : ParserSemanticAction (ioFlightDate) {
174  }
175 
176  // //////////////////////////////////////////////////////////////////
178  iterator_t iStrEnd) const {
180  }
181 
182  // //////////////////////////////////////////////////////////////////
184  : ParserSemanticAction (ioFlightDate) {
185  }
186 
187  // //////////////////////////////////////////////////////////////////
189  iterator_t iStrEnd) const {
191 
192  // Reset the number of seconds
194 
195  // Reset the date off-set
197  }
198 
199  // //////////////////////////////////////////////////////////////////
201  : ParserSemanticAction (ioFlightDate) {
202  }
203 
204  // //////////////////////////////////////////////////////////////////
205  void storeOffDate::operator() (iterator_t iStr, iterator_t iStrEnd) const {
207  }
208 
209  // //////////////////////////////////////////////////////////////////
211  : ParserSemanticAction (ioFlightDate) {
212  }
213 
214  // //////////////////////////////////////////////////////////////////
215  void storeOffTime::operator() (iterator_t iStr, iterator_t iStrEnd) const {
217 
218  // Reset the number of seconds
220  }
221 
222  // //////////////////////////////////////////////////////////////////
224  : ParserSemanticAction (ioFlightDate) {
225  }
226 
227  // //////////////////////////////////////////////////////////////////
228  void storeLegCabinCode::operator() (char iChar) const {
229 
230  // ///////////////////
231  // If this is not the first leg-cabin of the leg-date,
232  // the already parsed leg-cabin must be added to the leg-date.
233  if (_flightDate._itLegCabin._cabinCode != "") {
234  if (_flightDate._itLegCabin._bucketList.empty() == false) {
236  }
238  }
239 
240  // (Re-)initialise the leg-cabin branch of the tree
243 
244 
245  // ///////////////////
247  //std::cout << "Cabin code: " << iChar << std::endl;
248  }
249 
250  // //////////////////////////////////////////////////////////////////
253  : ParserSemanticAction (ioFlightDate) {
254  }
255 
256  // //////////////////////////////////////////////////////////////////
257  void storeSaleableCapacity::operator() (double iReal) const {
259  //std::cout << "Saleable capacity: " << iReal << std::endl;
260  }
261 
262  // //////////////////////////////////////////////////////////////////
264  : ParserSemanticAction (ioFlightDate) {
265  }
266 
267  // //////////////////////////////////////////////////////////////////
268  void storeAU::operator() (double iReal) const {
269  _flightDate._itLegCabin._au = iReal;
270  //std::cout << "AU: " << iReal << std::endl;
271  }
272 
273  // //////////////////////////////////////////////////////////////////
275  : ParserSemanticAction (ioFlightDate) {
276  }
277 
278  // //////////////////////////////////////////////////////////////////
279  void storeUPR::operator() (double iReal) const {
280  _flightDate._itLegCabin._upr = iReal;
281  //std::cout << "UPR: " << iReal << std::endl;
282  }
283 
284  // //////////////////////////////////////////////////////////////////
286  : ParserSemanticAction (ioFlightDate) {
287  }
288 
289  // //////////////////////////////////////////////////////////////////
290  void storeBookingCounter::operator() (double iReal) const {
292  //std::cout << "Nb of bookings: " << iReal << std::endl;
293  }
294 
295  // //////////////////////////////////////////////////////////////////
297  : ParserSemanticAction (ioFlightDate) {
298  }
299 
300  // //////////////////////////////////////////////////////////////////
301  void storeNAV::operator() (double iReal) const {
302  _flightDate._itLegCabin._nav = iReal;
303  //std::cout << "NAV: " << iReal << std::endl;
304  }
305 
306  // //////////////////////////////////////////////////////////////////
308  : ParserSemanticAction (ioFlightDate) {
309  }
310 
311  // //////////////////////////////////////////////////////////////////
312  void storeGAV::operator() (double iReal) const {
313  _flightDate._itLegCabin._gav = iReal;
314  //std::cout << "GAV: " << iReal << std::endl;
315  }
316 
317  // //////////////////////////////////////////////////////////////////
319  : ParserSemanticAction (ioFlightDate) {
320  }
321 
322  // //////////////////////////////////////////////////////////////////
323  void storeACP::operator() (double iReal) const {
324  _flightDate._itLegCabin._acp = iReal;
325  //std::cout << "ACP: " << iReal << std::endl;
326  }
327 
328  // //////////////////////////////////////////////////////////////////
330  : ParserSemanticAction (ioFlightDate) {
331  }
332 
333  // //////////////////////////////////////////////////////////////////
334  void storeETB::operator() (double iReal) const {
335  _flightDate._itLegCabin._etb = iReal;
336  //std::cout << "ETB: " << iReal << std::endl;
337  }
338 
339  // //////////////////////////////////////////////////////////////////
341  : ParserSemanticAction (ioFlightDate) {
342  }
343 
344  // //////////////////////////////////////////////////////////////////
345  void storeYieldUpperRange::operator() (double iReal) const {
346  // If this is not the first bucket of the leg-cabin,
347  // the already parsed bucket must be added to the leg-cabin.
350  }
351 
352 
353  // ///////////////////
355  //std::cout << "Yield Upper Range Value: " << iReal << std::endl;
356  }
357 
358  // //////////////////////////////////////////////////////////////////
361  : ParserSemanticAction (ioFlightDate) {
362  }
363 
364  // //////////////////////////////////////////////////////////////////
365  void storeBucketAvaibality::operator() (double iReal) const {
367  //std::cout << "Availability: " << iReal << std::endl;
368  }
369 
370  // //////////////////////////////////////////////////////////////////
372  : ParserSemanticAction (ioFlightDate) {
373  }
374 
375  // //////////////////////////////////////////////////////////////////
376  void storeSeatIndex::operator() (double iReal) const {
378  //std::cout << "Seat Index: " << iReal << std::endl;
379  }
380 
381  // //////////////////////////////////////////////////////////////////
384  : ParserSemanticAction (ioFlightDate) {
385  }
386 
387  // //////////////////////////////////////////////////////////////////
389  iterator_t iStrEnd) const {
390  stdair::AirportCode_T lBoardingPoint (iStr, iStrEnd);
391 
392  // ///////////////////
393  // When the first segment-date is read, it means that the leg section
394  // is over. The parsed leg can therefore be added to the list.
395  if (_flightDate._itLeg._cabinList.empty() == false) {
399 
400  // (Re-)initialise the leg-date branch of the tree
401  _flightDate._itLeg._cabinList.clear();
403  _flightDate._itLeg._cabinList.clear();
405  }
406 
407 
408  // ///////////////////
409  // If this is not the first segment-date of the flight-date,
410  // the already parsed segment-date must be added to the flight-date.
411  if (_flightDate._itSegment._cabinList.empty() == false) {
416  }
417 
418  // As that's the beginning of a new segment-date,
419  // (re-)initialise the segment-cabin branch of the tree
424 
425 
426  // ///////////////////
427  _flightDate._itSegment._boardingPoint = lBoardingPoint;
428  //std::cout << "Board point: " << lBoardingPoint << std::endl;
429  }
430 
431  // //////////////////////////////////////////////////////////////////
433  : ParserSemanticAction (ioFlightDate) {
434  }
435 
436  // //////////////////////////////////////////////////////////////////
438  iterator_t iStrEnd) const {
439  stdair::AirportCode_T lOffPoint (iStr, iStrEnd);
440  _flightDate._itSegment._offPoint = lOffPoint;
441  //std::cout << "Off point: " << lOffPoint << std::endl;
442  }
443 
444  // //////////////////////////////////////////////////////////////////
447  : ParserSemanticAction (ioFlightDate) {
448  }
449 
450  // //////////////////////////////////////////////////////////////////
451  void storeSegmentCabinCode::operator() (char iChar) const {
452 
453  // Reset the list of fare families, as it is a new segment-cabin
455 
456  // ///////////////////
457  // If this is not the first segment-cabin of the segment-date,
458  // the already parsed segment-cabin must be added to the segment-date.
459  if (_flightDate._itSegmentCabin._itFareFamily._classList.empty() == false){
461  push_back (_flightDate._itBookingClass);
465  push_back (_flightDate._itSegmentCabin);
466  }
467 
468  // (Re-)initialise the booking-class branch of the tree
472 
473 
474  // ///////////////////
476  //std::cout << "Segment-cabin code: " << iChar << std::endl;
477  }
478 
479  // //////////////////////////////////////////////////////////////////
482  : ParserSemanticAction (ioFlightDate) {
483  }
484 
485  // //////////////////////////////////////////////////////////////////
488  //std::cout << "Nb of bookings: " << iReal << std::endl;
489  }
490 
491  // //////////////////////////////////////////////////////////////////
493  : ParserSemanticAction (ioFlightDate) {
494  }
495 
496  // //////////////////////////////////////////////////////////////////
497  void storeClassCode::operator() (char iChar) const {
498  // If this is not the first booking-class of the segment-cabin,
499  // the already parsed booking-class must be added to the segment-cabin.
502  push_back (_flightDate._itBookingClass);
503  }
504 
505  // ///////////////////
507  //std::cout << "Booking class code: " << iChar << std::endl;
508  }
509 
510  // //////////////////////////////////////////////////////////////////
512  : ParserSemanticAction (ioFlightDate) {
513  }
514 
515  // //////////////////////////////////////////////////////////////////
516  void storeSubclassCode::operator() (unsigned int iNumber) const {
518  //std::cout << "Sub-class code: " << iNumber << std::endl;
519  }
520 
521  // //////////////////////////////////////////////////////////////////
524  : ParserSemanticAction (ioFlightDate) {
525  }
526 
527  // //////////////////////////////////////////////////////////////////
528  void storeParentClassCode::operator() (char iChar) const {
530  //std::cout << "Parent booking class code: " << iChar << std::endl;
531  }
532 
533  // //////////////////////////////////////////////////////////////////
536  : ParserSemanticAction (ioFlightDate) {
537  }
538 
539  // //////////////////////////////////////////////////////////////////
540  void storeParentSubclassCode::operator() (unsigned int iNumber) const {
542  //std::cout << "Parent sub-class code: " << iNumber << std::endl;
543  }
544 
545  // //////////////////////////////////////////////////////////////////
548  : ParserSemanticAction (ioFlightDate) {
549  }
550 
551  // //////////////////////////////////////////////////////////////////
552  void storeCumulatedProtection::operator() (double iReal) const {
554  //std::cout << "Cumulated protection: " << iReal << std::endl;
555  }
556 
557  // //////////////////////////////////////////////////////////////////
559  : ParserSemanticAction (ioFlightDate) {
560  }
561 
562  // //////////////////////////////////////////////////////////////////
563  void storeProtection::operator() (double iReal) const {
565  //std::cout << "Protection: " << iReal << std::endl;
566  }
567 
568  // //////////////////////////////////////////////////////////////////
570  : ParserSemanticAction (ioFlightDate) {
571  }
572 
573  // //////////////////////////////////////////////////////////////////
574  void storeNego::operator() (double iReal) const {
576  //std::cout << "Negotiated allotment: " << iReal << std::endl;
577  }
578 
579  // //////////////////////////////////////////////////////////////////
581  : ParserSemanticAction (ioFlightDate) {
582  }
583 
584  // //////////////////////////////////////////////////////////////////
585  void storeNoShow::operator() (double iReal) const {
587  //std::cout << "No-Show percentage: " << iReal << std::endl;
588  }
589 
590  // //////////////////////////////////////////////////////////////////
592  : ParserSemanticAction (ioFlightDate) {
593  }
594 
595  // //////////////////////////////////////////////////////////////////
596  void storeOverbooking::operator() (double iReal) const {
598  //std::cout << "Overbooking percentage: " << iReal << std::endl;
599  }
600 
601  // //////////////////////////////////////////////////////////////////
603  : ParserSemanticAction (ioFlightDate) {
604  }
605 
606  // //////////////////////////////////////////////////////////////////
607  void storeNbOfBkgs::operator() (double iReal) const {
609  //std::cout << "Nb of bookings: " << iReal << std::endl;
610  }
611 
612  // //////////////////////////////////////////////////////////////////
614  : ParserSemanticAction (ioFlightDate) {
615  }
616 
617  // //////////////////////////////////////////////////////////////////
618  void storeNbOfGroupBkgs::operator() (double iReal) const {
620  //std::cout << "Nb of group bookings: " << iReal << std::endl;
621  }
622 
623  // //////////////////////////////////////////////////////////////////
626  : ParserSemanticAction (ioFlightDate) {
627  }
628 
629  // //////////////////////////////////////////////////////////////////
630  void storeNbOfPendingGroupBkgs::operator() (double iReal) const {
632  //std::cout << "Nb of pending group bookings: " << iReal << std::endl;
633  }
634 
635  // //////////////////////////////////////////////////////////////////
637  : ParserSemanticAction (ioFlightDate) {
638  }
639 
640  // //////////////////////////////////////////////////////////////////
641  void storeNbOfStaffBkgs::operator() (double iReal) const {
643  //std::cout << "Nb of staff bookings: " << iReal << std::endl;
644  }
645 
646  // //////////////////////////////////////////////////////////////////
648  : ParserSemanticAction (ioFlightDate) {
649  }
650 
651  // //////////////////////////////////////////////////////////////////
652  void storeNbOfWLBkgs::operator() (double iReal) const {
654  //std::cout << "Nb of wait-list bookings: " << iReal << std::endl;
655  }
656 
657  // //////////////////////////////////////////////////////////////////
659  : ParserSemanticAction (ioFlightDate) {
660  }
661 
662  // //////////////////////////////////////////////////////////////////
663  void storeClassETB::operator() (double iReal) const {
665  //std::cout << "Class-level ETB: " << iReal << std::endl;
666  }
667 
668  // //////////////////////////////////////////////////////////////////
671  : ParserSemanticAction (ioFlightDate) {
672  }
673 
674  // //////////////////////////////////////////////////////////////////
675  void storeClassAvailability::operator() (double iReal) const {
677  //std::cout << "Net class availability: " << iReal << std::endl;
678  }
679 
680  // //////////////////////////////////////////////////////////////////
683  : ParserSemanticAction (ioFlightDate) {
684  }
685 
686  // //////////////////////////////////////////////////////////////////
687  void storeSegmentAvailability::operator() (double iReal) const {
689  //std::cout << "Segment availability: " << iReal << std::endl;
690  }
691 
692  // //////////////////////////////////////////////////////////////////
695  : ParserSemanticAction (ioFlightDate) {
696  }
697 
698  // //////////////////////////////////////////////////////////////////
699  void storeRevenueAvailability::operator() (double iReal) const {
701  //std::cout << "Net revenue availability: " << iReal << std::endl;
702  }
703 
704  // //////////////////////////////////////////////////////////////////
706  : ParserSemanticAction (ioFlightDate) {
707  }
708 
709  // //////////////////////////////////////////////////////////////////
710  void storeFamilyCode::operator() (int iCode) const {
711  std::ostringstream ostr;
712  ostr << iCode;
714  }
715 
716  // //////////////////////////////////////////////////////////////////
718  : ParserSemanticAction (ioFlightDate) {
719  }
720 
721  // //////////////////////////////////////////////////////////////////
723  iterator_t iStrEnd) const {
724  std::string lClasses (iStr, iStrEnd);
726 
727  // The list of classes is the last (according to the arrival order
728  // within the schedule input file) detail of the segment cabin. Hence,
729  // when a list of classes is parsed, it means that the full segment
730  // cabin details have already been parsed as well: the segment cabin
731  // can thus be added to the segment.
733  push_back (_flightDate._itBookingClass);
737 
738  // As that's the beginning of a new segment-cabin,
739  // (re-)initialise the segment-cabin branch of the tree
743  }
744 
745  // //////////////////////////////////////////////////////////////////
746  doEndFlightDate::doEndFlightDate (stdair::BomRoot& ioBomRoot,
747  FlightDateStruct& ioFlightDate,
748  unsigned int& ioNbOfFlights)
749  : ParserSemanticAction (ioFlightDate), _bomRoot (ioBomRoot),
750  _nbOfFlights (ioNbOfFlights) {
751  }
752 
753  // //////////////////////////////////////////////////////////////////
754  // void doEndFlightDate::operator() (char iChar) const {
756  iterator_t iStrEnd) const {
757 
758  // ///////////////////
759  // The segment-date section is now over. It means that the
760  // already parsed segment-date must be added to the flight-date.
761  if (_flightDate._itSegment._cabinList.empty() == false) {
763  }
764 
765  // As that's the beginning of a new flight-date,
766  // (re-)initialise the segment-cabin branch of the tree
768 
769 
770  // ///////////////////
771  //if (_nbOfFlights % 1000 == 0) {
772  // DEBUG: Display the result
773  //STDAIR_LOG_DEBUG ("FlightDate #" << _nbOfFlights
774  // << ": " << _flightDate.describe());
775  //}
776 
777  // Build the FlightDate BOM objects
778  InventoryBuilder::buildInventory (_bomRoot, _flightDate);
779 
780  //
781  ++_nbOfFlights;
782  }
783 
784 
785  // ///////////////////////////////////////////////////////////////////
786  //
787  // Utility Parsers
788  //
789  // ///////////////////////////////////////////////////////////////////
792 
795 
798 
801 
804 
807 
809  repeat_p_t airline_code_p (chset_t("0-9A-Z").derived(), 2, 3);
810 
812  bounded1_4_p_t flight_number_p (uint1_4_p.derived(), 0u, 9999u);
813 
815  bounded2_p_t year_p (uint2_p.derived(), 0u, 99u);
816 
818  bounded2_p_t month_p (uint2_p.derived(), 1u, 12u);
819 
821  bounded2_p_t day_p (uint2_p.derived(), 1u, 31u);
822 
824  repeat_p_t dow_p (chset_t("0-1").derived().derived(), 7, 7);
825 
827  repeat_p_t airport_p (chset_t("0-9A-Z").derived(), 3, 3);
828 
830  bounded1_2_p_t hours_p (uint1_2_p.derived(), 0u, 24u);
831 
833  bounded2_p_t minutes_p (uint2_p.derived(), 0u, 59u);
834 
836  bounded2_p_t seconds_p (uint2_p.derived(), 0u, 59u);
837 
839  chset_t cabin_code_p ("A-Z");
840 
842  chset_t class_code_p ("A-Z");
843 
845  chset_t passenger_type_p ("A-Z");
846 
849 
851  repeat_p_t class_code_list_p (chset_t("A-Z").derived(), 1, 26);
852 
854  bounded1_3_p_t stay_duration_p (uint1_3_p.derived(), 0u, 999u);
855 
856 
857  // //////////////////////////////////////////////////////////////////
858  // (Boost Spirit) Grammar Definition
859  // //////////////////////////////////////////////////////////////////
860 
861  // //////////////////////////////////////////////////////////////////
862  InventoryParser::InventoryParser (stdair::BomRoot& ioBomRoot,
863  FlightDateStruct& ioFlightDate,
864  unsigned int& ioNbOfFlights)
865  : _bomRoot (ioBomRoot), _flightDate (ioFlightDate),
866  _nbOfFlights (ioNbOfFlights) {
867  }
868 
869  // //////////////////////////////////////////////////////////////////
870  template<typename ScannerT>
873 
874  flight_date_list = *( not_to_be_parsed | flight_date )
875  ;
876 
877  not_to_be_parsed =
878  bsc::lexeme_d[ bsc::comment_p("//") | bsc::comment_p("/*", "*/")
879  | bsc::space_p ]
880  ;
881 
882  flight_date = flight_key
883  >> leg_list
884  >> segment_list
885  >> flight_date_end[doEndFlightDate (self._bomRoot, self._flightDate,
886  self._nbOfFlights)]
887  ;
888 
889  flight_date_end = bsc::ch_p(';')
890  ;
891 
892  flight_key = date[storeSnapshotDate(self._flightDate)]
893  >> '/' >> airline_code
894  >> '/' >> flight_number
895  >> '/' >> date[storeFlightDate(self._flightDate)]
896  >> '/' >> flight_type_code[storeFlightTypeCode(self._flightDate)]
897  >> !( '/' >> flight_visibility_code[storeFlightVisibilityCode(self._flightDate)])
898  ;
899 
900  airline_code =
901  bsc::lexeme_d[(airline_code_p)[storeAirlineCode(self._flightDate)]]
902  ;
903 
904  flight_number =
905  bsc::lexeme_d[(flight_number_p)[storeFlightNumber(self._flightDate)]]
906  ;
907 
908  date =
909  bsc::lexeme_d[(day_p)[bsc::assign_a(self._flightDate._itDay)]
910  >> (month_p)[bsc::assign_a(self._flightDate._itMonth)]
911  >> (year_p)[bsc::assign_a(self._flightDate._itYear)]]
912  ;
913 
914  flight_type_code =
915  ( bsc::chseq_p("INT") | bsc::chseq_p("DOM") | bsc::chseq_p("GRD") )
916  ;
917 
918  flight_visibility_code =
919  ( bsc::chseq_p("HID") | bsc::chseq_p("PSD") )
920  ;
921 
922  leg_list = +( '/' >> leg )
923  ;
924 
925  leg = leg_key >> ';' >> leg_details >> leg_cabin_list
926  ;
927 
928  leg_key = (airport_p)[storeLegBoardingPoint(self._flightDate)]
929  >> ';' >> (airport_p)[storeLegOffPoint(self._flightDate)]
930  ;
931 
932  leg_details = date[storeBoardingDate(self._flightDate)]
933  >> ';' >> time[storeBoardingTime(self._flightDate)]
934  >> ';' >> date[storeOffDate(self._flightDate)]
935  >> ';' >> time[storeOffTime(self._flightDate)]
936  ;
937 
938  leg_cabin_list = +( ';' >> leg_cabin_details >> !bucket_list )
939  ;
940 
941  leg_cabin_details = (cabin_code_p)[storeLegCabinCode(self._flightDate)]
942  >> ',' >> (bsc::ureal_p)[storeSaleableCapacity(self._flightDate)]
943  >> ',' >> (bsc::real_p)[storeAU(self._flightDate)]
944  >> ',' >> (bsc::real_p)[storeUPR(self._flightDate)]
945  >> ',' >> (bsc::real_p)[storeBookingCounter(self._flightDate)]
946  >> ',' >> (bsc::real_p)[storeNAV(self._flightDate)]
947  >> ',' >> (bsc::real_p)[storeGAV(self._flightDate)]
948  >> ',' >> (bsc::ureal_p)[storeACP(self._flightDate)]
949  >> ',' >> (bsc::real_p)[storeETB(self._flightDate)]
950  ;
951 
952  time =
953  bsc::lexeme_d[
954  (hours_p)[bsc::assign_a(self._flightDate._itHours)]
955  >> (minutes_p)[bsc::assign_a(self._flightDate._itMinutes)]
956  >> !((seconds_p)[bsc::assign_a(self._flightDate._itSeconds)])
957  ]
958  ;
959 
960  bucket_list = +( ',' >> bucket_details )
961  ;
962 
963  bucket_details =
964  (bsc::ureal_p)[storeYieldUpperRange(self._flightDate)]
965  >> ':' >> (bsc::real_p)[storeBucketAvaibality(self._flightDate)]
966  >> ':' >> (uint1_3_p)[storeSeatIndex(self._flightDate)];
967 
968  segment_list = +( '/' >> segment )
969  ;
970 
971  segment = segment_key >> segment_cabin_list
972  ;
973 
974  segment_key = (airport_p)[storeSegmentBoardingPoint(self._flightDate)]
975  >> ';' >> (airport_p)[storeSegmentOffPoint(self._flightDate)]
976  ;
977 
978  segment_cabin_list =
979  +( ';' >> segment_cabin_key >> ','
980  >> segment_cabin_details >> class_list >> family_cabin_list )
981  ;
982 
983  family_cabin_list =
984  +( ';' >> family_cabin_details)
985  ;
986 
987  segment_cabin_key =
988  (cabin_code_p)[storeSegmentCabinCode(self._flightDate)]
989  ;
990 
991  segment_cabin_details =
992  (bsc::ureal_p)[storeSegmentCabinBookingCounter(self._flightDate)]
993  ;
994 
995  class_list = +( ',' >> class_key >> '|' >> class_details )
996  ;
997 
998  class_key = (class_code_p)[storeClassCode(self._flightDate)]
999  ;
1000 
1001  parent_subclass_code =
1002  (class_code_p)[storeParentClassCode(self._flightDate)]
1003  >> (uint1_2_p)[storeParentSubclassCode(self._flightDate)]
1004  ;
1005 
1006  class_protection =
1007  (bsc::ureal_p)[storeProtection(self._flightDate)]
1008  ;
1009 
1010  class_nego =
1011  (bsc::ureal_p)[storeNego(self._flightDate)]
1012  ;
1013 
1014  class_details = (uint1_2_p)[storeSubclassCode(self._flightDate)]
1015  >> ':' >> (bsc::ureal_p)[storeCumulatedProtection(self._flightDate)]
1016  >> ':' >> !( parent_subclass_code )
1017  >> ':' >> !( class_protection )
1018  >> ':' >> (bsc::ureal_p)[storeNoShow(self._flightDate)]
1019  >> ':' >> (bsc::ureal_p)[storeOverbooking(self._flightDate)]
1020  >> ':' >> (bsc::ureal_p)[storeNbOfBkgs(self._flightDate)]
1021  >> ':' >> (bsc::ureal_p)[storeNbOfGroupBkgs(self._flightDate)]
1022  >> ':' >> (bsc::ureal_p)[storeNbOfPendingGroupBkgs(self._flightDate)]
1023  >> ':' >> (bsc::ureal_p)[storeNbOfStaffBkgs(self._flightDate)]
1024  >> ':' >> (bsc::ureal_p)[storeNbOfWLBkgs(self._flightDate)]
1025  >> ':' >> (bsc::ureal_p)[storeClassETB(self._flightDate)]
1026  >> ':' >> !( class_nego )
1027  >> ':' >> (bsc::real_p)[storeClassAvailability(self._flightDate)]
1028  >> ':' >> (bsc::real_p)[storeSegmentAvailability(self._flightDate)]
1029  >> ':' >> (bsc::real_p)[storeRevenueAvailability(self._flightDate)]
1030  ;
1031 
1032  family_cabin_details =
1033  (family_code_p)[storeFamilyCode(self._flightDate)]
1034  >> ';'
1035  >> (class_code_list_p)[storeFClasses(self._flightDate)]
1036  ;
1037 
1038  // BOOST_SPIRIT_DEBUG_NODE (InventoryParser);
1039  BOOST_SPIRIT_DEBUG_NODE (flight_date_list);
1040  BOOST_SPIRIT_DEBUG_NODE (not_to_be_parsed);
1041  BOOST_SPIRIT_DEBUG_NODE (flight_date);
1042  BOOST_SPIRIT_DEBUG_NODE (flight_date_end);
1043  BOOST_SPIRIT_DEBUG_NODE (flight_key);
1044  BOOST_SPIRIT_DEBUG_NODE (airline_code);
1045  BOOST_SPIRIT_DEBUG_NODE (flight_number);
1046  BOOST_SPIRIT_DEBUG_NODE (flight_type_code);
1047  BOOST_SPIRIT_DEBUG_NODE (flight_visibility_code);
1048  BOOST_SPIRIT_DEBUG_NODE (date);
1049  BOOST_SPIRIT_DEBUG_NODE (leg_list);
1050  BOOST_SPIRIT_DEBUG_NODE (leg);
1051  BOOST_SPIRIT_DEBUG_NODE (leg_key);
1052  BOOST_SPIRIT_DEBUG_NODE (leg_details);
1053  BOOST_SPIRIT_DEBUG_NODE (leg_cabin_list);
1054  BOOST_SPIRIT_DEBUG_NODE (leg_cabin_details);
1055  BOOST_SPIRIT_DEBUG_NODE (bucket_list);
1056  BOOST_SPIRIT_DEBUG_NODE (bucket_details);
1057  BOOST_SPIRIT_DEBUG_NODE (time);
1058  BOOST_SPIRIT_DEBUG_NODE (segment_list);
1059  BOOST_SPIRIT_DEBUG_NODE (segment);
1060  BOOST_SPIRIT_DEBUG_NODE (segment_key);
1061  BOOST_SPIRIT_DEBUG_NODE (full_segment_cabin_details);
1062  BOOST_SPIRIT_DEBUG_NODE (segment_cabin_list);
1063  BOOST_SPIRIT_DEBUG_NODE (segment_cabin_key);
1064  BOOST_SPIRIT_DEBUG_NODE (segment_cabin_details);
1065  BOOST_SPIRIT_DEBUG_NODE (class_list);
1066  BOOST_SPIRIT_DEBUG_NODE (class_key);
1067  BOOST_SPIRIT_DEBUG_NODE (parent_subclass_code);
1068  BOOST_SPIRIT_DEBUG_NODE (class_protection);
1069  BOOST_SPIRIT_DEBUG_NODE (class_nego);
1070  BOOST_SPIRIT_DEBUG_NODE (class_details);
1071  BOOST_SPIRIT_DEBUG_NODE (family_cabin_list);
1072  BOOST_SPIRIT_DEBUG_NODE (family_cabin_details);
1073  }
1074 
1075  // //////////////////////////////////////////////////////////////////
1076  template<typename ScannerT>
1077  bsc::rule<ScannerT> const&
1079  return flight_date_list;
1080  }
1081  }
1082 
1083 
1085  //
1086  // Entry class for the file parser
1087  //
1089 
1090  // //////////////////////////////////////////////////////////////////////
1092  InventoryFileParser (stdair::BomRoot& ioBomRoot, const std::string& iFilename)
1093  : _filename (iFilename), _bomRoot (ioBomRoot),
1094  _nbOfFlights (0) {
1095  init();
1096  }
1097 
1098  // //////////////////////////////////////////////////////////////////////
1099  void InventoryFileParser::init() {
1100  // Open the file
1101  _startIterator = iterator_t (_filename);
1102 
1103  // Check the filename exists and can be open
1104  if (!_startIterator) {
1105  std::ostringstream oMessage;
1106  oMessage << "The file " << _filename << " can not be open.";
1107  STDAIR_LOG_ERROR (oMessage.str());
1108  throw InventoryInputFileNotFoundException (oMessage.str());
1109  }
1110 
1111  // Create an EOF iterator
1112  _endIterator = _startIterator.make_end();
1113  }
1114 
1115  // //////////////////////////////////////////////////////////////////////
1117  bool oResult = false;
1118 
1119  STDAIR_LOG_DEBUG ("Parsing inventory input file: " << _filename);
1120 
1121  // Initialise the parser (grammar) with the helper/staging structure.
1122  InventoryParserHelper::InventoryParser lInventoryParser (_bomRoot,
1123  _flightDate,
1124  _nbOfFlights);
1125 
1126  // Launch the parsing of the file and, thanks to the doEndFlightDate
1127  // call-back structure, the building of the whole Inventory BOM
1128  // (i.e., including Inventory, FlightDate, LegDate, SegmentDate, etc.)
1129  bsc::parse_info<iterator_t> info = bsc::parse (_startIterator, _endIterator,
1130  lInventoryParser,
1131  bsc::space_p - bsc::eol_p);
1132 
1133  // Retrieves whether or not the parsing was successful
1134  oResult = info.hit;
1135 
1136  const std::string hasBeenFullyReadStr = (info.full == true)?"":"not ";
1137  if (oResult == true) {
1138  STDAIR_LOG_DEBUG ("Parsing of inventory input file: " << _filename
1139  << " succeeded: read " << info.length
1140  << " characters. The input file has "
1141  << hasBeenFullyReadStr
1142  << "been fully read. Stop point: " << info.stop);
1143 
1144  } else {
1145  STDAIR_LOG_ERROR ("Parsing of inventory input file: " << _filename
1146  << " failed: read " << info.length
1147  << " characters. The input file has "
1148  << hasBeenFullyReadStr
1149  << "been fully read. Stop point: " << info.stop);
1150  throw InventoryFileParsingFailedException("Parsing of inventory input file"
1151  ": " + _filename + " failed");
1152  }
1153 
1154  return oResult;
1155  }
1156 
1157 }