10 #include <stdair/basic/BasFileMgr.hpp> 
   11 #include <stdair/bom/BomRoot.hpp> 
   12 #include <stdair/service/Logger.hpp> 
   14 #include <airinv/command/DCPParserHelper.hpp> 
   15 #include <airinv/command/DCPRuleGenerator.hpp> 
   19   namespace DCPParserHelper {
 
   26       : _DCPRule (ioDCPRule) {
 
   36                                   boost::spirit::qi::unused_type,
 
   37                                   boost::spirit::qi::unused_type)
 const {
 
   48       _DCPRule._classCodeListOfList.clear();
 
   60                                   boost::spirit::qi::unused_type,
 
   61                                   boost::spirit::qi::unused_type)
 const {
 
   62        stdair::AirportCode_T lOrigin (iChar.begin(), iChar.end());
 
   76                                        boost::spirit::qi::unused_type,
 
   77                                        boost::spirit::qi::unused_type)
 const {
 
   78        stdair::AirportCode_T lDestination (iChar.begin(), iChar.end());
 
   81        _DCPRule._destination = lDestination;
 
   92                                           boost::spirit::qi::unused_type,
 
   93                                           boost::spirit::qi::unused_type)
 const {
 
  107                                         boost::spirit::qi::unused_type,
 
  108                                         boost::spirit::qi::unused_type)
 const {
 
  122                                           boost::spirit::qi::unused_type,
 
  123                                           boost::spirit::qi::unused_type)
 const {
 
  139                                         boost::spirit::qi::unused_type,
 
  140                                         boost::spirit::qi::unused_type)
 const {
 
  156                                boost::spirit::qi::unused_type,
 
  157                                boost::spirit::qi::unused_type)
 const {
 
  158       stdair::AirlineCode_T lPOS (iChar.begin(), iChar.end());
 
  172                                      boost::spirit::qi::unused_type,
 
  173                                      boost::spirit::qi::unused_type)
 const {
 
  174       std::ostringstream ostr;
 
  176       std::string cabinCodeStr = ostr.str();
 
  177       const stdair::CabinCode_T lCabinCode (cabinCodeStr);
 
  193                                    boost::spirit::qi::unused_type,
 
  194                                    boost::spirit::qi::unused_type)
 const {
 
  195       stdair::ChannelLabel_T lChannel (iChar.begin(), iChar.end());
 
  196       if (lChannel != 
"IN" && lChannel != 
"IF" 
  197           && lChannel != 
"DN" && lChannel != 
"DF") {
 
  199         STDAIR_LOG_DEBUG (
"Invalid channel " << lChannel);
 
  214                                            boost::spirit::qi::unused_type,
 
  215                                            boost::spirit::qi::unused_type)
 const {
 
  216       _DCPRule._advancePurchase = iAdancePurchase;
 
  229                                         boost::spirit::qi::unused_type,
 
  230                                         boost::spirit::qi::unused_type)
 const {
 
  232       if (iSaturdayStay == 
'T') {
 
  235         if (iSaturdayStay != 
'F') {
 
  237           STDAIR_LOG_DEBUG (
"Invalid saturdayStay char " << iSaturdayStay);
 
  240       stdair::SaturdayStay_T lSaturdayStay (lBool);
 
  241       _DCPRule._saturdayStay = lSaturdayStay;
 
  254                                       boost::spirit::qi::unused_type,
 
  255                                       boost::spirit::qi::unused_type)
 const {
 
  258       if (iChangefees == 
'T') {
 
  261         if (iChangefees != 
'F') {
 
  263           STDAIR_LOG_DEBUG (
"Invalid change fees char " << iChangefees);
 
  266       stdair::ChangeFees_T lChangefees (lBool);
 
  280                                          boost::spirit::qi::unused_type,
 
  281                                          boost::spirit::qi::unused_type)
 const {
 
  283        if (iNonRefundable == 
'T') {
 
  286          if (iNonRefundable != 
'F') {
 
  288            STDAIR_LOG_DEBUG (
"Invalid non refundable char " << iNonRefundable);
 
  291        stdair::NonRefundable_T lNonRefundable (lBool);
 
  292        _DCPRule._nonRefundable = lNonRefundable;
 
  305                                        boost::spirit::qi::unused_type,
 
  306                                        boost::spirit::qi::unused_type)
 const {
 
  320                                 boost::spirit::qi::unused_type,
 
  321                                 boost::spirit::qi::unused_type)
 const {
 
  335                                        boost::spirit::qi::unused_type,
 
  336                                        boost::spirit::qi::unused_type)
 const {
 
  338       bool lAlreadyInTheList = 
false;
 
  339       stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end());
 
  341       _DCPRule._airlineCode = lAirlineCode;
 
  343       if (
_DCPRule._airlineCodeList.size() > 0) {
 
  347         std::vector<stdair::AirlineCode_T>::iterator Airline_iterator;
 
  348         for (Airline_iterator = 
_DCPRule._airlineCodeList.begin();
 
  349              Airline_iterator != 
_DCPRule._airlineCodeList.end();
 
  350              ++Airline_iterator) {
 
  351           stdair::AirlineCode_T lPreviousAirlineCode =
 
  353           if (lPreviousAirlineCode == lAirlineCode) {
 
  354             lAlreadyInTheList = 
true;
 
  359         if (lAlreadyInTheList == 
false) {
 
  362           _DCPRule._airlineCodeList.push_back(lAirlineCode);
 
  368         _DCPRule._airlineCodeList.push_back (lAirlineCode);
 
  382                                  boost::spirit::qi::unused_type,
 
  383                                  boost::spirit::qi::unused_type)
 const {
 
  384       std::ostringstream ostr;
 
  385       for (std::vector<char>::const_iterator lItVector = iChar.begin();
 
  386          lItVector != iChar.end();
 
  390       std::string classCodeStr = ostr.str();
 
  392       _DCPRule._classCodeList.push_back(classCodeStr);
 
  400                DCPRuleStruct& ioDCPRule)
 
  402         _bomRoot (ioBomRoot) {
 
  407                                 boost::spirit::qi::unused_type,
 
  408                                 boost::spirit::qi::unused_type)
 const {
 
  414       STDAIR_LOG_DEBUG(
_DCPRule.describe());
 
  423     namespace bsq = boost::spirit::qi;
 
  424     namespace bsa = boost::spirit::ascii;
 
  454                                     DCPRuleStruct& ioDCPRule) :
 
  456       _bomRoot(ioBomRoot), _DCPRule(ioDCPRule) {
 
  460       comments = (bsq::lexeme[bsq::repeat(2)[bsa::char_(
'/')]
 
  461                               >> +(bsa::char_ - bsq::eol)
 
  463                   | bsq::lexeme[bsa::char_(
'/') >>bsa::char_(
'*') 
 
  464                                 >> +(bsa::char_ - bsa::char_(
'*')) 
 
  465                                 >> bsa::char_(
'*') >> bsa::char_(
'/')]);
 
  498         >> 
day_p[boost::phoenix::ref(
_DCPRule._itDay) = bsq::labels::_1] ];
 
  508         >> - (
':' >> 
second_p[boost::phoenix::ref(
_DCPRule._itSeconds) = bsq::labels::_1]) ];
 
  536       BOOST_SPIRIT_DEBUG_NODE (
start);
 
  540       BOOST_SPIRIT_DEBUG_NODE (
DCP_key);
 
  541       BOOST_SPIRIT_DEBUG_NODE (
DCP_id);
 
  542       BOOST_SPIRIT_DEBUG_NODE (
origin);
 
  546       BOOST_SPIRIT_DEBUG_NODE (
date);
 
  549       BOOST_SPIRIT_DEBUG_NODE (
time);
 
  550       BOOST_SPIRIT_DEBUG_NODE (position);
 
  552       BOOST_SPIRIT_DEBUG_NODE (
channel);
 
  558       BOOST_SPIRIT_DEBUG_NODE (DCP);
 
  559       BOOST_SPIRIT_DEBUG_NODE (
segment);
 
  573                       const stdair::Filename_T& iFilename)
 
  574     : _filename (iFilename), _bomRoot (ioBomRoot) {
 
  579   void DCPRuleFileParser::init() {
 
  581     const bool doesExistAndIsReadable =
 
  582       stdair::BasFileMgr::doesExistAndIsReadable (_filename);
 
  584     if (doesExistAndIsReadable == 
false) {
 
  585       STDAIR_LOG_ERROR (
"The DCP schedule file " << _filename
 
  586                         << 
" does not exist or can not be  read.");
 
  588       throw DCPInputFileNotFoundException (
"The DCP file " + _filename + 
" does not exist or can not be read");
 
  595     STDAIR_LOG_DEBUG (
"Parsing DCP input file: " << _filename);
 
  598     const std::string* lFileName = &_filename;
 
  599     const char *lChar = (*lFileName).c_str();
 
  600     std::ifstream fileToBeParsed(lChar, std::ios_base::in);
 
  603     if (fileToBeParsed == 
false) {
 
  604       STDAIR_LOG_ERROR (
"The DCP file " << _filename << 
" can not be open." 
  607       throw DCPInputFileNotFoundException (
"The file " + _filename + 
" does not exist or can not be read");
 
  611     stdair::base_iterator_t inputBegin (fileToBeParsed);
 
  615       start (boost::spirit::make_default_multi_pass (inputBegin));
 
  624     const bool hasParsingBeenSuccesful = 
 
  625        boost::spirit::qi::phrase_parse (start, end, lFPParser,
 
  626                                         boost::spirit::ascii::space);
 
  628     if (hasParsingBeenSuccesful == 
false) {
 
  630       STDAIR_LOG_ERROR (
"Parsing of DCP input file: " << _filename
 
  635       STDAIR_LOG_ERROR (
"Parsing of DCP input file: " << _filename
 
  638     if (hasParsingBeenSuccesful == 
true && start == end) {
 
  639       STDAIR_LOG_DEBUG (
"Parsing of DCP input file: " << _filename
 
  642     return hasParsingBeenSuccesful;