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>
21 namespace YieldParserHelper {
29 : _yieldRule (ioYieldRule) {
40 boost::spirit::qi::unused_type,
41 boost::spirit::qi::unused_type)
const {
47 const stdair::AirlineCode_T lEmptyAirlineCode (
"");
50 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::YieldValue_T lYield= iYield;
276 boost::spirit::qi::unused_type,
277 boost::spirit::qi::unused_type)
const {
279 const stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end());
296 boost::spirit::qi::unused_type,
297 boost::spirit::qi::unused_type)
const {
298 std::ostringstream ostr;
299 for (std::vector<char>::const_iterator lItVector = iChar.begin();
300 lItVector != iChar.end();
304 const std::string& classCodeStr = ostr.str();
305 const stdair::ClassCode_T lClassCode (classCodeStr);
317 _bomRoot (ioBomRoot) {
322 boost::spirit::qi::unused_type,
323 boost::spirit::qi::unused_type)
const {
337 namespace bsq = boost::spirit::qi;
338 namespace bsa = boost::spirit::ascii;
388 public boost::spirit::qi::grammar<stdair::iterator_t,
389 boost::spirit::ascii::space_type> {
398 comments = (bsq::lexeme[bsq::repeat(2)[bsa::char_(
'/')]
399 >> +(bsa::char_ - bsq::eol)
401 | bsq::lexeme[bsa::char_(
'/') >>bsa::char_(
'*')
402 >> +(bsa::char_ - bsa::char_(
'*'))
403 >> bsa::char_(
'*') >> bsa::char_(
'/')]);
462 BOOST_SPIRIT_DEBUG_NODE (
start);
466 BOOST_SPIRIT_DEBUG_NODE (
origin);
471 BOOST_SPIRIT_DEBUG_NODE (
date);
474 BOOST_SPIRIT_DEBUG_NODE (
time);
475 BOOST_SPIRIT_DEBUG_NODE (point_of_sale);
477 BOOST_SPIRIT_DEBUG_NODE (
channel);
478 BOOST_SPIRIT_DEBUG_NODE (
yield);
479 BOOST_SPIRIT_DEBUG_NODE (
segment);
485 boost::spirit::qi::rule<stdair::iterator_t,
486 boost::spirit::ascii::space_type>
508 const std::string& iFilename)
509 : _filename (iFilename), _bomRoot (ioBomRoot) {
514 void YieldFileParser::init() {
517 const bool doesExistAndIsReadable =
518 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
520 if (doesExistAndIsReadable ==
false) {
521 STDAIR_LOG_ERROR (
"The yield schedule file " << _filename
522 <<
" does not exist or can not be read.");
531 STDAIR_LOG_DEBUG (
"Parsing yield input file: " << _filename);
534 std::ifstream fileToBeParsed (_filename.c_str(), std::ios_base::in);
537 if (fileToBeParsed.is_open() ==
false) {
538 STDAIR_LOG_ERROR (
"The yield store file " << _filename
539 <<
" can not be open."
543 +
" does not exist or can not be read");
547 stdair::base_iterator_t inputBegin (fileToBeParsed);
551 start (boost::spirit::make_default_multi_pass (inputBegin));
552 stdair::iterator_t end;
559 const bool hasParsingBeenSuccesful =
560 boost::spirit::qi::phrase_parse (start, end, lYParser,
561 boost::spirit::ascii::space);
563 if (hasParsingBeenSuccesful ==
false) {
565 STDAIR_LOG_ERROR (
"Parsing of yield input file: " << _filename
568 + _filename +
" failed");
572 STDAIR_LOG_ERROR (
"Parsing of yield input file: " << _filename
575 + _filename +
" failed");
577 if (hasParsingBeenSuccesful ==
true && start == end) {
578 STDAIR_LOG_DEBUG (
"Parsing of yield input file: " << _filename