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>
14 #include <stdair/basic/BasParserTypes.hpp>
23 namespace FareParserHelper {
31 : _fareRule (ioFareRule) {
42 boost::spirit::qi::unused_type,
43 boost::spirit::qi::unused_type)
const {
48 const stdair::AirlineCode_T lEmptyAirlineCode (
"");
51 const stdair::ClassCode_T lEmptyClassCode (
"");
65 boost::spirit::qi::unused_type,
66 boost::spirit::qi::unused_type)
const {
67 const stdair::AirportCode_T lOrigin (iChar.begin(), iChar.end());
81 boost::spirit::qi::unused_type,
82 boost::spirit::qi::unused_type)
const {
83 const stdair::AirportCode_T lDestination (iChar.begin(), iChar.end());
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") {
104 STDAIR_LOG_ERROR (
"Invalid trip type " << lTripType);
119 boost::spirit::qi::unused_type,
120 boost::spirit::qi::unused_type)
const {
135 boost::spirit::qi::unused_type,
136 boost::spirit::qi::unused_type)
const {
141 const stdair::DateOffset_T oneDay (1);
142 const stdair::Date_T lBoostDateEnd = lDateEnd + oneDay;
156 boost::spirit::qi::unused_type,
157 boost::spirit::qi::unused_type)
const {
174 boost::spirit::qi::unused_type,
175 boost::spirit::qi::unused_type)
const {
192 boost::spirit::qi::unused_type,
193 boost::spirit::qi::unused_type)
const {
194 const stdair::CityCode_T lPOS (iChar.begin(), iChar.end());
197 }
else if (lPOS ==
"ROW") {
198 const stdair::CityCode_T lPOSROW (
"ROW");
200 }
else if (lPOS == stdair::DEFAULT_POS) {
204 STDAIR_LOG_ERROR (
"Invalid point of sale " << lPOS);
218 boost::spirit::qi::unused_type,
219 boost::spirit::qi::unused_type)
const {
220 std::ostringstream ostr;
222 const std::string cabinCodeStr = ostr.str();
223 const stdair::CabinCode_T& lCabinCode (cabinCodeStr);
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) {
245 STDAIR_LOG_ERROR (
"Invalid channel " << lChannel);
260 boost::spirit::qi::unused_type,
261 boost::spirit::qi::unused_type)
const {
262 const stdair::DayDuration_T& lAdancePurchase = iAdancePurchase;
276 boost::spirit::qi::unused_type,
277 boost::spirit::qi::unused_type)
const {
279 if (iSaturdayStay ==
'T') {
282 if (iSaturdayStay !=
'F') {
284 STDAIR_LOG_DEBUG (
"Invalid saturdayStay char " << iSaturdayStay);
287 const stdair::SaturdayStay_T lSaturdayStay (lBool);
301 boost::spirit::qi::unused_type,
302 boost::spirit::qi::unused_type)
const {
305 if (iChangefees ==
'T') {
308 if (iChangefees !=
'F') {
310 STDAIR_LOG_DEBUG (
"Invalid change fees char " << iChangefees);
313 const stdair::ChangeFees_T lChangefees (lBool);
327 boost::spirit::qi::unused_type,
328 boost::spirit::qi::unused_type)
const {
330 if (iNonRefundable ==
'T') {
333 if (iNonRefundable !=
'F') {
335 STDAIR_LOG_DEBUG (
"Invalid non refundable char " << iNonRefundable);
338 const stdair::NonRefundable_T lNonRefundable (lBool);
352 boost::spirit::qi::unused_type,
353 boost::spirit::qi::unused_type)
const {
354 const stdair::DayDuration_T lMinStay = iMinStay;
368 boost::spirit::qi::unused_type,
369 boost::spirit::qi::unused_type)
const {
370 const stdair::PriceValue_T lFare = iFare;
384 boost::spirit::qi::unused_type,
385 boost::spirit::qi::unused_type)
const {
387 const stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end());
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();
410 const std::string classCodeStr = ostr.str();
411 const stdair::ClassCode_T lClassCode (classCodeStr);
423 _bomRoot (ioBomRoot) {
428 boost::spirit::qi::unused_type,
429 boost::spirit::qi::unused_type)
const {
443 namespace bsq = boost::spirit::qi;
444 namespace bsa = boost::spirit::ascii;
502 template <
typename Iterator>
504 public boost::spirit::qi::grammar<Iterator,
505 boost::spirit::ascii::space_type> {
516 comments = (bsq::lexeme[bsq::repeat(2)[bsa::char_(
'/')]
517 >> +(bsa::char_ - bsq::eol)
519 | bsq::lexeme[bsa::char_(
'/') >>bsa::char_(
'*')
520 >> +(bsa::char_ - bsa::char_(
'*'))
521 >> bsa::char_(
'*') >> bsa::char_(
'/')]);
593 BOOST_SPIRIT_DEBUG_NODE (
start);
598 BOOST_SPIRIT_DEBUG_NODE (
fare_id);
599 BOOST_SPIRIT_DEBUG_NODE (
origin);
604 BOOST_SPIRIT_DEBUG_NODE (
date);
606 BOOST_SPIRIT_DEBUG_NODE (
time);
607 BOOST_SPIRIT_DEBUG_NODE (point_of_sale);
609 BOOST_SPIRIT_DEBUG_NODE (
channel);
615 BOOST_SPIRIT_DEBUG_NODE (fare);
616 BOOST_SPIRIT_DEBUG_NODE (
segment);
621 boost::spirit::qi::rule<Iterator,
622 boost::spirit::ascii::space_type>
646 const stdair::Filename_T& iFilename)
647 : _filename (iFilename), _bomRoot (ioBomRoot) {
652 void FareRuleFileParser::init() {
654 const bool doesExistAndIsReadable =
655 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
657 if (doesExistAndIsReadable ==
false) {
658 STDAIR_LOG_ERROR (
"The fare schedule file " << _filename
659 <<
" does not exist or can not be read.");
662 +
" does not exist or can not be read");
669 STDAIR_LOG_DEBUG (
"Parsing fare input file: " << _filename);
672 const std::string* lFileName = &_filename;
673 const char *lChar = (*lFileName).c_str();
674 std::ifstream fileToBeParsed(lChar, std::ios_base::in);
677 if (fileToBeParsed.is_open() ==
false) {
678 STDAIR_LOG_ERROR (
"The fare file " << _filename <<
" can not be open."
682 +
" does not exist or can not be read");
686 stdair::base_iterator_t inputBegin (fileToBeParsed);
690 start (boost::spirit::make_default_multi_pass (inputBegin));
691 stdair::iterator_t end;
698 const bool hasParsingBeenSuccesful =
699 boost::spirit::qi::phrase_parse (start, end, lFPParser,
700 boost::spirit::ascii::space);
702 if (hasParsingBeenSuccesful ==
false) {
703 STDAIR_LOG_ERROR (
"Parsing of fare input file: " << _filename
706 + _filename +
" failed");
710 STDAIR_LOG_ERROR (
"Parsing of fare input file: " << _filename
713 + _filename +
" failed");
716 if (hasParsingBeenSuccesful ==
true && start == end) {
717 STDAIR_LOG_DEBUG (
"Parsing of fare input file: " << _filename