9 #include <stdair/basic/BasFileMgr.hpp>
10 #include <stdair/bom/BomRoot.hpp>
11 #include <stdair/service/Logger.hpp>
13 #include <stdair/basic/BasParserTypes.hpp>
22 namespace FareParserHelper {
30 : _fareRule (ioFareRule) {
41 boost::spirit::qi::unused_type,
42 boost::spirit::qi::unused_type)
const {
47 const stdair::AirlineCode_T lEmptyAirlineCode (
"");
50 const stdair::ClassCode_T lEmptyClassCode (
"");
64 boost::spirit::qi::unused_type,
65 boost::spirit::qi::unused_type)
const {
66 const stdair::AirportCode_T lOrigin (iChar.begin(), iChar.end());
80 boost::spirit::qi::unused_type,
81 boost::spirit::qi::unused_type)
const {
82 const stdair::AirportCode_T lDestination (iChar.begin(), iChar.end());
96 boost::spirit::qi::unused_type,
97 boost::spirit::qi::unused_type)
const {
98 const stdair::TripType_T lTripType (iChar.begin(), iChar.end());
99 if (lTripType ==
"OW" || lTripType ==
"RT") {
103 STDAIR_LOG_ERROR (
"Invalid trip type " << lTripType);
118 boost::spirit::qi::unused_type,
119 boost::spirit::qi::unused_type)
const {
134 boost::spirit::qi::unused_type,
135 boost::spirit::qi::unused_type)
const {
140 const stdair::DateOffset_T oneDay (1);
141 const stdair::Date_T lBoostDateEnd = lDateEnd + oneDay;
155 boost::spirit::qi::unused_type,
156 boost::spirit::qi::unused_type)
const {
173 boost::spirit::qi::unused_type,
174 boost::spirit::qi::unused_type)
const {
191 boost::spirit::qi::unused_type,
192 boost::spirit::qi::unused_type)
const {
193 const stdair::CityCode_T lPOS (iChar.begin(), iChar.end());
196 }
else if (lPOS ==
"ROW") {
197 const stdair::CityCode_T lPOSROW (
"ROW");
201 STDAIR_LOG_ERROR (
"Invalid point of sale " << lPOS);
215 boost::spirit::qi::unused_type,
216 boost::spirit::qi::unused_type)
const {
217 std::ostringstream ostr;
219 const std::string cabinCodeStr = ostr.str();
220 const stdair::CabinCode_T& lCabinCode (cabinCodeStr);
236 boost::spirit::qi::unused_type,
237 boost::spirit::qi::unused_type)
const {
238 const stdair::ChannelLabel_T lChannel (iChar.begin(), iChar.end());
239 if (lChannel !=
"IN" && lChannel !=
"IF"
240 && lChannel !=
"DN" && lChannel !=
"DF") {
242 STDAIR_LOG_ERROR (
"Invalid channel " << lChannel);
257 boost::spirit::qi::unused_type,
258 boost::spirit::qi::unused_type)
const {
259 const stdair::DayDuration_T& lAdancePurchase = iAdancePurchase;
273 boost::spirit::qi::unused_type,
274 boost::spirit::qi::unused_type)
const {
276 if (iSaturdayStay ==
'T') {
279 if (iSaturdayStay !=
'F') {
281 STDAIR_LOG_DEBUG (
"Invalid saturdayStay char " << iSaturdayStay);
284 const stdair::SaturdayStay_T lSaturdayStay (lBool);
298 boost::spirit::qi::unused_type,
299 boost::spirit::qi::unused_type)
const {
302 if (iChangefees ==
'T') {
305 if (iChangefees !=
'F') {
307 STDAIR_LOG_DEBUG (
"Invalid change fees char " << iChangefees);
310 const stdair::ChangeFees_T lChangefees (lBool);
324 boost::spirit::qi::unused_type,
325 boost::spirit::qi::unused_type)
const {
327 if (iNonRefundable ==
'T') {
330 if (iNonRefundable !=
'F') {
332 STDAIR_LOG_DEBUG (
"Invalid non refundable char " << iNonRefundable);
335 const stdair::NonRefundable_T lNonRefundable (lBool);
349 boost::spirit::qi::unused_type,
350 boost::spirit::qi::unused_type)
const {
351 const stdair::DayDuration_T lMinStay = iMinStay;
365 boost::spirit::qi::unused_type,
366 boost::spirit::qi::unused_type)
const {
367 const stdair::PriceValue_T lFare = iFare;
381 boost::spirit::qi::unused_type,
382 boost::spirit::qi::unused_type)
const {
384 const stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end());
399 boost::spirit::qi::unused_type,
400 boost::spirit::qi::unused_type)
const {
401 std::ostringstream ostr;
402 for (std::vector<char>::const_iterator lItVector = iChar.begin();
403 lItVector != iChar.end();
407 const std::string classCodeStr = ostr.str();
408 const stdair::ClassCode_T lClassCode (classCodeStr);
420 _bomRoot (ioBomRoot) {
425 boost::spirit::qi::unused_type,
426 boost::spirit::qi::unused_type)
const {
440 namespace bsq = boost::spirit::qi;
441 namespace bsa = boost::spirit::ascii;
499 template <
typename Iterator>
501 public boost::spirit::qi::grammar<Iterator,
502 boost::spirit::ascii::space_type> {
513 comments = (bsq::lexeme[bsq::repeat(2)[bsa::char_(
'/')]
514 >> +(bsa::char_ - bsq::eol)
516 | bsq::lexeme[bsa::char_(
'/') >>bsa::char_(
'*')
517 >> +(bsa::char_ - bsa::char_(
'*'))
518 >> bsa::char_(
'*') >> bsa::char_(
'/')]);
590 BOOST_SPIRIT_DEBUG_NODE (
start);
595 BOOST_SPIRIT_DEBUG_NODE (
fare_id);
596 BOOST_SPIRIT_DEBUG_NODE (
origin);
601 BOOST_SPIRIT_DEBUG_NODE (
date);
603 BOOST_SPIRIT_DEBUG_NODE (
time);
604 BOOST_SPIRIT_DEBUG_NODE (point_of_sale);
606 BOOST_SPIRIT_DEBUG_NODE (
channel);
612 BOOST_SPIRIT_DEBUG_NODE (fare);
613 BOOST_SPIRIT_DEBUG_NODE (
segment);
618 boost::spirit::qi::rule<Iterator,
619 boost::spirit::ascii::space_type>
643 const stdair::Filename_T& iFilename)
644 : _filename (iFilename), _bomRoot (ioBomRoot) {
649 void FareRuleFileParser::init() {
651 const bool doesExistAndIsReadable =
652 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
654 if (doesExistAndIsReadable ==
false) {
655 STDAIR_LOG_ERROR (
"The fare schedule file " << _filename
656 <<
" does not exist or can not be read.");
659 +
" does not exist or can not be read");
666 STDAIR_LOG_DEBUG (
"Parsing fare input file: " << _filename);
669 const std::string* lFileName = &_filename;
670 const char *lChar = (*lFileName).c_str();
671 std::ifstream fileToBeParsed(lChar, std::ios_base::in);
674 if (fileToBeParsed ==
false) {
675 STDAIR_LOG_ERROR (
"The fare file " << _filename <<
" can not be open."
679 +
" does not exist or can not be read");
683 stdair::base_iterator_t inputBegin (fileToBeParsed);
687 start (boost::spirit::make_default_multi_pass (inputBegin));
688 stdair::iterator_t end;
695 const bool hasParsingBeenSuccesful =
696 boost::spirit::qi::phrase_parse (start, end, lFPParser,
697 boost::spirit::ascii::space);
699 if (hasParsingBeenSuccesful ==
false) {
700 STDAIR_LOG_ERROR (
"Parsing of fare input file: " << _filename
703 + _filename +
" failed");
707 STDAIR_LOG_ERROR (
"Parsing of fare input file: " << _filename
710 + _filename +
" failed");
713 if (hasParsingBeenSuccesful ==
true && start == end) {
714 STDAIR_LOG_DEBUG (
"Parsing of fare input file: " << _filename