SimFQT Logo  1.00.9
C++ Simulated Fare Quote System Library
Loading...
Searching...
No Matches
FareParserHelper.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2// Import section
3// //////////////////////////////////////////////////////////////////////
4// STL
5#include <cassert>
6#include <vector>
7#include <fstream>
8// StdAir
9#include <stdair/basic/BasFileMgr.hpp>
10#include <stdair/basic/BasConst_Request.hpp>
11#include <stdair/bom/BomRoot.hpp>
12#include <stdair/service/Logger.hpp>
13//#define BOOST_SPIRIT_DEBUG
14#include <stdair/basic/BasParserTypes.hpp>
15// SIMFQT
18
19
20
21namespace SIMFQT {
22
23 namespace FareParserHelper {
24
25 // //////////////////////////////////////////////////////////////////
26 // Semantic actions
27 // //////////////////////////////////////////////////////////////////
28
31 : _fareRule (ioFareRule) {
32 }
33
34 // //////////////////////////////////////////////////////////////////
36 storeFareId (FareRuleStruct& ioFareRule)
37 : ParserSemanticAction (ioFareRule) {
38 }
39
40 // //////////////////////////////////////////////////////////////////
41 void storeFareId::operator() (unsigned int iFareId,
42 boost::spirit::qi::unused_type,
43 boost::spirit::qi::unused_type) const {
44 _fareRule.setFareID (iFareId);
45
46 // DEBUG
47 //STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule.getFareID ());
48 const stdair::AirlineCode_T lEmptyAirlineCode ("");
49 _fareRule.setAirlineCode(lEmptyAirlineCode);
50 _fareRule.clearAirlineCodeList();
51 const stdair::ClassCode_T lEmptyClassCode ("");
52 _fareRule.setClassCode(lEmptyClassCode);
53 _fareRule.clearClassCodeList();
54 _fareRule._itSeconds = 0;
55 }
56
57 // //////////////////////////////////////////////////////////////////
58 storeOrigin ::
59 storeOrigin (FareRuleStruct& ioFareRule)
60 : ParserSemanticAction (ioFareRule) {
61 }
62
63 // //////////////////////////////////////////////////////////////////
64 void storeOrigin::operator() (std::vector<char> iChar,
65 boost::spirit::qi::unused_type,
66 boost::spirit::qi::unused_type) const {
67 const stdair::AirportCode_T lOrigin (iChar.begin(), iChar.end());
68 _fareRule.setOrigin (lOrigin);
69 // DEBUG
70 //STDAIR_LOG_DEBUG ( "Origin: " << _fareRule.getOrigin ());
71 }
72
73 // //////////////////////////////////////////////////////////////////
74 storeDestination ::
75 storeDestination (FareRuleStruct& ioFareRule)
76 : ParserSemanticAction (ioFareRule) {
77 }
78
79 // //////////////////////////////////////////////////////////////////
80 void storeDestination::operator() (std::vector<char> iChar,
81 boost::spirit::qi::unused_type,
82 boost::spirit::qi::unused_type) const {
83 const stdair::AirportCode_T lDestination (iChar.begin(), iChar.end());
84 _fareRule.setDestination (lDestination);
85 // DEBUG
86 //STDAIR_LOG_DEBUG ( "Destination: " << _fareRule.getDestination ());
87 }
88
89 // //////////////////////////////////////////////////////////////////
90 storeTripType ::
91 storeTripType (FareRuleStruct& ioFareRule)
92 : ParserSemanticAction (ioFareRule) {
93 }
94
95 // //////////////////////////////////////////////////////////////////
96 void storeTripType::operator() (std::vector<char> iChar,
97 boost::spirit::qi::unused_type,
98 boost::spirit::qi::unused_type) const {
99 const stdair::TripType_T lTripType (iChar.begin(), iChar.end());
100 if (lTripType == "OW" || lTripType == "RT") {
101 _fareRule.setTripType (lTripType);
102 } else {
103 // ERROR
104 STDAIR_LOG_ERROR ("Invalid trip type " << lTripType);
105 }
106 // DEBUG
107 //STDAIR_LOG_DEBUG ("TripType: " << _fareRule.getTripType ());
108 }
109
110
111 // //////////////////////////////////////////////////////////////////
116
117 // //////////////////////////////////////////////////////////////////
118 void storeDateRangeStart::operator() (boost::spirit::qi::unused_type,
119 boost::spirit::qi::unused_type,
120 boost::spirit::qi::unused_type) const {
121 const stdair::Date_T& lDateStart = _fareRule.calculateDate ();
122 _fareRule.setDateRangeStart (lDateStart);
123 // DEBUG
124 //STDAIR_LOG_DEBUG ("Date Range Start: " << _fareRule.getDateRangeStart ());
125 }
126
127 // //////////////////////////////////////////////////////////////////
132
133 // //////////////////////////////////////////////////////////////////
134 void storeDateRangeEnd::operator() (boost::spirit::qi::unused_type,
135 boost::spirit::qi::unused_type,
136 boost::spirit::qi::unused_type) const {
137 const stdair::Date_T& lDateEnd = _fareRule.calculateDate ();
138 // As a Boost date period (DatePeriod_T) defines the last day of
139 // the period to be end-date - one day, we have to add one day to that
140 // end date before.
141 const stdair::DateOffset_T oneDay (1);
142 const stdair::Date_T lBoostDateEnd = lDateEnd + oneDay;
143 _fareRule.setDateRangeEnd (lBoostDateEnd);
144 // DEBUG
145 //STDAIR_LOG_DEBUG ("Date Range End: " << _fareRule.getDateRangeEnd ());
146 }
147
148 // //////////////////////////////////////////////////////////////////
153
154 // //////////////////////////////////////////////////////////////////
155 void storeStartRangeTime::operator() (boost::spirit::qi::unused_type,
156 boost::spirit::qi::unused_type,
157 boost::spirit::qi::unused_type) const {
158 const stdair::Duration_T& lTimeStart = _fareRule.calculateTime ();
159 _fareRule.setTimeRangeStart (lTimeStart);
160 // DEBUG
161 //STDAIR_LOG_DEBUG ("Time Range Start: " << _fareRule.getTimeRangeStart ());
162 // Reset the number of seconds
163 _fareRule._itSeconds = 0;
164 }
165
166 // //////////////////////////////////////////////////////////////////
171
172 // //////////////////////////////////////////////////////////////////
173 void storeEndRangeTime::operator() (boost::spirit::qi::unused_type,
174 boost::spirit::qi::unused_type,
175 boost::spirit::qi::unused_type) const {
176 const stdair::Duration_T& lTimeEnd = _fareRule.calculateTime ();
177 _fareRule.setTimeRangeEnd (lTimeEnd);
178 // DEBUG
179 //STDAIR_LOG_DEBUG ("Time Range End: " << _fareRule.getTimeRangeEnd ());
180 // Reset the number of seconds
181 _fareRule._itSeconds = 0;
182 }
183
184 // //////////////////////////////////////////////////////////////////
185 storePOS ::
186 storePOS (FareRuleStruct& ioFareRule)
187 : ParserSemanticAction (ioFareRule) {
188 }
189
190 // //////////////////////////////////////////////////////////////////
191 void storePOS::operator() (std::vector<char> iChar,
192 boost::spirit::qi::unused_type,
193 boost::spirit::qi::unused_type) const {
194 const stdair::CityCode_T lPOS (iChar.begin(), iChar.end());
195 if (lPOS == _fareRule.getOrigin() || lPOS == _fareRule.getDestination()) {
196 _fareRule.setPOS (lPOS);
197 } else if (lPOS == "ROW") {
198 const stdair::CityCode_T lPOSROW ("ROW");
199 _fareRule.setPOS (lPOSROW);
200 } else if (lPOS == stdair::DEFAULT_POS) {
201 _fareRule.setPOS (stdair::DEFAULT_POS);
202 } else {
203 // ERROR
204 STDAIR_LOG_ERROR ("Invalid point of sale " << lPOS);
205 }
206 // DEBUG
207 //STDAIR_LOG_DEBUG ("POS: " << _fareRule.getPOS ());
208 }
209
210 // //////////////////////////////////////////////////////////////////
211 storeCabinCode ::
212 storeCabinCode (FareRuleStruct& ioFareRule)
213 : ParserSemanticAction (ioFareRule) {
214 }
215
216 // //////////////////////////////////////////////////////////////////
218 boost::spirit::qi::unused_type,
219 boost::spirit::qi::unused_type) const {
220 std::ostringstream ostr;
221 ostr << iChar;
222 const std::string cabinCodeStr = ostr.str();
223 const stdair::CabinCode_T& lCabinCode (cabinCodeStr);
224 _fareRule.setCabinCode (lCabinCode);
225
226 // DEBUG
227 //STDAIR_LOG_DEBUG ("Cabin Code: " << _fareRule.getCabinCode ());
228
229 }
230
231 // //////////////////////////////////////////////////////////////////
232 storeChannel ::
233 storeChannel (FareRuleStruct& ioFareRule)
234 : ParserSemanticAction (ioFareRule) {
235 }
236
237 // //////////////////////////////////////////////////////////////////
238 void storeChannel::operator() (std::vector<char> iChar,
239 boost::spirit::qi::unused_type,
240 boost::spirit::qi::unused_type) const {
241 const stdair::ChannelLabel_T lChannel (iChar.begin(), iChar.end());
242 if (lChannel != "IN" && lChannel != "IF" && lChannel != "DN"
243 && lChannel != "DF" && lChannel != stdair::DEFAULT_CHANNEL) {
244 // ERROR
245 STDAIR_LOG_ERROR ("Invalid channel " << lChannel);
246 }
247 _fareRule.setChannel (lChannel);
248 // DEBUG
249 //STDAIR_LOG_DEBUG ("Channel: " << _fareRule.getChannel ());
250 }
251
252 // //////////////////////////////////////////////////////////////////
253 storeAdvancePurchase ::
254 storeAdvancePurchase (FareRuleStruct& ioFareRule)
255 : ParserSemanticAction (ioFareRule) {
256 }
257
258 // //////////////////////////////////////////////////////////////////
259 void storeAdvancePurchase::operator() (unsigned int iAdancePurchase,
260 boost::spirit::qi::unused_type,
261 boost::spirit::qi::unused_type) const {
262 const stdair::DayDuration_T& lAdancePurchase = iAdancePurchase;
263 _fareRule.setAdvancePurchase (lAdancePurchase);
264 // DEBUG
265 //STDAIR_LOG_DEBUG ( "Advance Purchase: " << _fareRule.getAdvancePurchase ());
266 }
267
268 // //////////////////////////////////////////////////////////////////
269 storeSaturdayStay ::
270 storeSaturdayStay (FareRuleStruct& ioFareRule)
271 : ParserSemanticAction (ioFareRule) {
272 }
273
274 // //////////////////////////////////////////////////////////////////
275 void storeSaturdayStay::operator() (char iSaturdayStay,
276 boost::spirit::qi::unused_type,
277 boost::spirit::qi::unused_type) const {
278 bool lBool = false;
279 if (iSaturdayStay == 'T') {
280 lBool = true;
281 } else {
282 if (iSaturdayStay != 'F') {
283 // DEBUG
284 STDAIR_LOG_DEBUG ("Invalid saturdayStay char " << iSaturdayStay);
285 }
286 }
287 const stdair::SaturdayStay_T lSaturdayStay (lBool);
288 _fareRule.setSaturdayStay (lSaturdayStay);
289 // DEBUG
290 //STDAIR_LOG_DEBUG ("Saturday Stay: " << _fareRule.getSaturdayStay ());
291 }
292
293 // //////////////////////////////////////////////////////////////////
294 storeChangeFees ::
295 storeChangeFees (FareRuleStruct& ioFareRule)
296 : ParserSemanticAction (ioFareRule) {
297 }
298
299 // //////////////////////////////////////////////////////////////////
300 void storeChangeFees::operator() (char iChangefees,
301 boost::spirit::qi::unused_type,
302 boost::spirit::qi::unused_type) const {
303
304 bool lBool = false;
305 if (iChangefees == 'T') {
306 lBool = true;
307 } else {
308 if (iChangefees != 'F') {
309 // DEBUG
310 STDAIR_LOG_DEBUG ("Invalid change fees char " << iChangefees);
311 }
312 }
313 const stdair::ChangeFees_T lChangefees (lBool);
314 _fareRule.setChangeFees (lChangefees);
315 // DEBUG
316 //STDAIR_LOG_DEBUG ("Change fees: " << _fareRule.getChangeFees ());
317 }
318
319 // //////////////////////////////////////////////////////////////////
320 storeNonRefundable ::
321 storeNonRefundable (FareRuleStruct& ioFareRule)
322 : ParserSemanticAction (ioFareRule) {
323 }
324
325 // //////////////////////////////////////////////////////////////////
326 void storeNonRefundable::operator() (char iNonRefundable,
327 boost::spirit::qi::unused_type,
328 boost::spirit::qi::unused_type) const {
329 bool lBool = false;
330 if (iNonRefundable == 'T') {
331 lBool = true;
332 } else {
333 if (iNonRefundable != 'F') {
334 // DEBUG
335 STDAIR_LOG_DEBUG ("Invalid non refundable char " << iNonRefundable);
336 }
337 }
338 const stdair::NonRefundable_T lNonRefundable (lBool);
339 _fareRule.setNonRefundable (lNonRefundable);
340 // DEBUG
341 //STDAIR_LOG_DEBUG ("Non refundable: " << _fareRule.getNonRefundable ());
342 }
343
344 // //////////////////////////////////////////////////////////////////
345 storeMinimumStay ::
346 storeMinimumStay (FareRuleStruct& ioFareRule)
347 : ParserSemanticAction (ioFareRule) {
348 }
349
350 // //////////////////////////////////////////////////////////////////
351 void storeMinimumStay::operator() (unsigned int iMinStay,
352 boost::spirit::qi::unused_type,
353 boost::spirit::qi::unused_type) const {
354 const stdair::DayDuration_T lMinStay = iMinStay;
355 _fareRule.setMinimumStay (lMinStay);
356 // DEBUG
357 //STDAIR_LOG_DEBUG ("Minimum Stay: " << _fareRule.getMinimumStay ());
358 }
359
360 // //////////////////////////////////////////////////////////////////
361 storeFare ::
362 storeFare (FareRuleStruct& ioFareRule)
363 : ParserSemanticAction (ioFareRule) {
364 }
365
366 // //////////////////////////////////////////////////////////////////
367 void storeFare::operator() (double iFare,
368 boost::spirit::qi::unused_type,
369 boost::spirit::qi::unused_type) const {
370 const stdair::PriceValue_T lFare = iFare;
371 _fareRule.setFare (lFare);
372 // DEBUG
373 //STDAIR_LOG_DEBUG ("Fare: " << _fareRule.getFare ());
374 }
375
376 // //////////////////////////////////////////////////////////////////
377 storeAirlineCode ::
378 storeAirlineCode (FareRuleStruct& ioFareRule)
379 : ParserSemanticAction (ioFareRule) {
380 }
381
382 // //////////////////////////////////////////////////////////////////
383 void storeAirlineCode::operator() (std::vector<char> iChar,
384 boost::spirit::qi::unused_type,
385 boost::spirit::qi::unused_type) const {
386
387 const stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end());
388 // Insertion of this airline Code list in the whole AirlineCode name
389 _fareRule.addAirlineCode (lAirlineCode);
390 // DEBUG
391 //STDAIR_LOG_DEBUG ( "Airline code: " << lAirlineCode);
392 }
393
394 // //////////////////////////////////////////////////////////////////
395 storeClass ::
396 storeClass (FareRuleStruct& ioFareRule)
397 : ParserSemanticAction (ioFareRule) {
398 }
399
400 // //////////////////////////////////////////////////////////////////
401 void storeClass::operator() (std::vector<char> iChar,
402 boost::spirit::qi::unused_type,
403 boost::spirit::qi::unused_type) const {
404 std::ostringstream ostr;
405 for (std::vector<char>::const_iterator lItVector = iChar.begin();
406 lItVector != iChar.end();
407 lItVector++) {
408 ostr << *lItVector;
409 }
410 const std::string classCodeStr = ostr.str();
411 const stdair::ClassCode_T lClassCode (classCodeStr);
412 // Insertion of this class Code list in the whole classCode name
413 _fareRule.addClassCode (lClassCode);
414 // DEBUG
415 //STDAIR_LOG_DEBUG ("Class Code: " << lClassCode);
416 }
417
418 // //////////////////////////////////////////////////////////////////
420 doEndFare (stdair::BomRoot& ioBomRoot,
421 FareRuleStruct& ioFareRule)
422 : ParserSemanticAction (ioFareRule),
423 _bomRoot (ioBomRoot) {
424 }
425
426 // //////////////////////////////////////////////////////////////////
427 void doEndFare::operator() (boost::spirit::qi::unused_type,
428 boost::spirit::qi::unused_type,
429 boost::spirit::qi::unused_type) const {
430 // DEBUG
431 //STDAIR_LOG_DEBUG ("Do End");
432 // Generation of the fare rule object.
433 FareRuleGenerator::createAirportPair (_bomRoot, _fareRule);
434 STDAIR_LOG_DEBUG(_fareRule.describe());
435 }
436
437 // ///////////////////////////////////////////////////////////////////
438 //
439 // Utility Parsers
440 //
441 // ///////////////////////////////////////////////////////////////////
443 namespace bsq = boost::spirit::qi;
444 namespace bsa = boost::spirit::ascii;
445
447 stdair::int1_p_t int1_p;
448
450 stdair::uint2_p_t uint2_p;
451
453 stdair::uint4_p_t uint4_p;
454
456 stdair::uint1_4_p_t uint1_4_p;
457
459 stdair::hour_p_t hour_p;
460 stdair::minute_p_t minute_p;
461 stdair::second_p_t second_p;
462
464 stdair::year_p_t year_p;
465 stdair::month_p_t month_p;
466 stdair::day_p_t day_p;
467
469 //
470 // (Boost Spirit) Grammar Definition
471 //
473
500
502 template <typename Iterator>
504 public boost::spirit::qi::grammar<Iterator,
505 boost::spirit::ascii::space_type> {
506
507 FareRuleParser (stdair::BomRoot& ioBomRoot,
508 FareRuleStruct& iofareRule) :
509
510 FareRuleParser::base_type(start),
511 _bomRoot(ioBomRoot), _fareRule(iofareRule) {
512
513
514 start = *(comments | fare_rule);
515
516 comments = (bsq::lexeme[bsq::repeat(2)[bsa::char_('/')]
517 >> +(bsa::char_ - bsq::eol)
518 >> bsq::eol]
519 | bsq::lexeme[bsa::char_('/') >>bsa::char_('*')
520 >> +(bsa::char_ - bsa::char_('*'))
521 >> bsa::char_('*') >> bsa::char_('/')]);
522
524 >> +( ';' >> segment )
526
527 fare_rule_end = bsa::char_(';');
528
530 >> ';' >> origin >> ';' >> destination
531 >> ';' >> tripType
532 >> ';' >> dateRangeStart >> ';' >> dateRangeEnd
533 >> ';' >> timeRangeStart >> ';' >> timeRangeEnd
534 >> ';' >> point_of_sale >> ';' >> cabinCode >> ';' >> channel
535 >> ';' >> advancePurchase >> ';' >> saturdayStay
536 >> ';' >> changeFees >> ';' >> nonRefundable
537 >> ';' >> minimumStay >> ';' >> fare;
538
540
541 origin = bsq::repeat(3)[bsa::char_("A-Z")][storeOrigin(_fareRule)];
542
543 destination =
544 bsq::repeat(3)[bsa::char_("A-Z")][storeDestination(_fareRule)];
545
546 tripType =
547 bsq::repeat(2)[bsa::char_("A-Z")][storeTripType(_fareRule)];
548
550
552
553 date = bsq::lexeme
554 [year_p[boost::phoenix::ref(_fareRule._itYear) = bsq::labels::_1]
555 >> '-'
556 >> month_p[boost::phoenix::ref(_fareRule._itMonth) = bsq::labels::_1]
557 >> '-'
558 >> day_p[boost::phoenix::ref(_fareRule._itDay) = bsq::labels::_1] ];
559
561
563
564 time = bsq::lexeme
565 [hour_p[boost::phoenix::ref(_fareRule._itHours) = bsq::labels::_1]
566 >> ':'
567 >> minute_p[boost::phoenix::ref(_fareRule._itMinutes) = bsq::labels::_1]
568 >> - (':' >> second_p[boost::phoenix::ref(_fareRule._itSeconds) = bsq::labels::_1]) ];
569
570 point_of_sale = bsq::repeat(3)[bsa::char_("A-Z")][storePOS(_fareRule)];
571
572 cabinCode = bsa::char_("A-Z")[storeCabinCode(_fareRule)];
573
574 channel = bsq::repeat(2)[bsa::char_("A-Z")][storeChannel(_fareRule)];
575
577
578 saturdayStay = bsa::char_("A-Z")[storeSaturdayStay(_fareRule)];
579
580 changeFees = bsa::char_("A-Z")[storeChangeFees(_fareRule)];
581
582 nonRefundable = bsa::char_("A-Z")[storeNonRefundable(_fareRule)];
583
585
586 fare = bsq::double_[storeFare(_fareRule)];
587
588 segment = bsq::repeat(2)[bsa::char_("A-Z")][storeAirlineCode(_fareRule)]
589 >> ';'
590 >> bsq::repeat(1,bsq::inf)[bsa::char_("A-Z")][storeClass(_fareRule)];
591
592 //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser);
593 BOOST_SPIRIT_DEBUG_NODE (start);
594 BOOST_SPIRIT_DEBUG_NODE (comments);
595 BOOST_SPIRIT_DEBUG_NODE (fare_rule);
596 BOOST_SPIRIT_DEBUG_NODE (fare_rule_end);
597 BOOST_SPIRIT_DEBUG_NODE (fare_key);
598 BOOST_SPIRIT_DEBUG_NODE (fare_id);
599 BOOST_SPIRIT_DEBUG_NODE (origin);
600 BOOST_SPIRIT_DEBUG_NODE (destination);
601 BOOST_SPIRIT_DEBUG_NODE (tripType);
602 BOOST_SPIRIT_DEBUG_NODE (dateRangeStart);
603 BOOST_SPIRIT_DEBUG_NODE (dateRangeEnd);
604 BOOST_SPIRIT_DEBUG_NODE (date);
605 BOOST_SPIRIT_DEBUG_NODE (timeRangeStart);
606 BOOST_SPIRIT_DEBUG_NODE (time);
607 BOOST_SPIRIT_DEBUG_NODE (point_of_sale);
608 BOOST_SPIRIT_DEBUG_NODE (cabinCode);
609 BOOST_SPIRIT_DEBUG_NODE (channel);
610 BOOST_SPIRIT_DEBUG_NODE (advancePurchase);
611 BOOST_SPIRIT_DEBUG_NODE (saturdayStay);
612 BOOST_SPIRIT_DEBUG_NODE (changeFees);
613 BOOST_SPIRIT_DEBUG_NODE (nonRefundable);
614 BOOST_SPIRIT_DEBUG_NODE (minimumStay);
615 BOOST_SPIRIT_DEBUG_NODE (fare);
616 BOOST_SPIRIT_DEBUG_NODE (segment);
617
618 }
619
620 // Instantiation of rules
621 boost::spirit::qi::rule<Iterator,
622 boost::spirit::ascii::space_type>
628
629 // Parser Context
630 stdair::BomRoot& _bomRoot;
632 };
633
634 }
635
636
638 //
639 // Entry class for the file parser
640 //
642
643 // //////////////////////////////////////////////////////////////////////
645 FareRuleFileParser (stdair::BomRoot& ioBomRoot,
646 const stdair::Filename_T& iFilename)
647 : _filename (iFilename), _bomRoot (ioBomRoot) {
648 init();
649 }
650
651 // //////////////////////////////////////////////////////////////////////
652 void FareRuleFileParser::init() {
653 // Check that the file exists and is readable
654 const bool doesExistAndIsReadable =
655 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
656
657 if (doesExistAndIsReadable == false) {
658 STDAIR_LOG_ERROR ("The fare schedule file " << _filename
659 << " does not exist or can not be read.");
660
661 throw FareInputFileNotFoundException ("The fare file " + _filename
662 + " does not exist or can not be read");
663 }
664 }
665
666 // //////////////////////////////////////////////////////////////////////
668
669 STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename);
670
671 // File to be parsed
672 const std::string* lFileName = &_filename;
673 const char *lChar = (*lFileName).c_str();
674 std::ifstream fileToBeParsed(lChar, std::ios_base::in);
675
676 // Check if the filename exist and can be open
677 if (fileToBeParsed.is_open() == false) {
678 STDAIR_LOG_ERROR ("The fare file " << _filename << " can not be open."
679 << std::endl);
680
681 throw FareInputFileNotFoundException ("The file " + _filename
682 + " does not exist or can not be read");
683 }
684
685 // Create an input iterator
686 stdair::base_iterator_t inputBegin (fileToBeParsed);
687
688 // Convert input iterator to an iterator usable by spirit parser
689 stdair::iterator_t
690 start (boost::spirit::make_default_multi_pass (inputBegin));
691 stdair::iterator_t end;
692
693 // Initialise the parser (grammar) with the helper/staging structure.
694 FareParserHelper::FareRuleParser<stdair::iterator_t> lFPParser(_bomRoot, _fareRule);
695
696 // Launch the parsing of the file and, thanks to the doEndFare
697 // call-back structure, the building of the whole BomRoot BOM
698 const bool hasParsingBeenSuccesful =
699 boost::spirit::qi::phrase_parse (start, end, lFPParser,
700 boost::spirit::ascii::space);
701
702 if (hasParsingBeenSuccesful == false) {
703 STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename
704 << " failed");
705 throw FareFileParsingFailedException ("Parsing of fare input file: "
706 + _filename + " failed");
707 }
708
709 if (start != end) {
710 STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename
711 << " failed");
712 throw FareFileParsingFailedException ("Parsing of fare input file: "
713 + _filename + " failed");
714 }
715
716 if (hasParsingBeenSuccesful == true && start == end) {
717 STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename
718 << " succeeded");
719 }
720
721 }
722
723}
FareRuleFileParser(stdair::BomRoot &ioBomRoot, const stdair::Filename_T &iFilename)
stdair::uint1_4_p_t uint1_4_p
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > segment
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > destination
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > channel
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > dateRangeStart
FareRuleParser(stdair::BomRoot &ioBomRoot, FareRuleStruct &iofareRule)
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > origin
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > tripType
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > fare_rule
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > timeRangeStart
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > nonRefundable
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > fare_id
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > comments
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > start
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > point_of_sale
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > fare_rule_end
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > minimumStay
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > time
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > dateRangeEnd
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > cabinCode
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > changeFees
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > fare
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > fare_key
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > timeRangeEnd
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > date
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > saturdayStay
boost::spirit::qi::rule< Iterator, boost::spirit::ascii::space_type > advancePurchase
doEndFare(stdair::BomRoot &, FareRuleStruct &)
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(char, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(char, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(double, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(unsigned int, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(char, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(char, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const
void operator()(std::vector< char >, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const