SimFQT Logo  0.1.2
C++ Simulated Fare Quote System Library
FareParserHelper.hpp
Go to the documentation of this file.
00001 #ifndef __SIMFQT_CMD_FAREPARSERHELPER_HPP
00002 #define __SIMFQT_CMD_FAREPARSERHELPER_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 #include <string>
00009 //#define BOOST_SPIRIT_DEBUG
00010 // StdAir
00011 #include <stdair/basic/BasParserTypes.hpp>
00012 #include <stdair/command/CmdAbstract.hpp>
00013 // Simfqt
00014 #include <simfqt/SIMFQT_Types.hpp>
00015 #include <simfqt/bom/FareRuleStruct.hpp>
00016 
00017 // Forward declarations
00018 namespace stdair {
00019   class BomRoot;
00020 }
00021 
00022 namespace SIMFQT {
00023 
00024   namespace FareParserHelper {
00025     
00026     // ///////////////////////////////////////////////////////////////////
00027     //  Semantic actions
00028     // ////////////////////////////////////////////////////
00030 
00031     struct ParserSemanticAction {
00033       ParserSemanticAction (FareRuleStruct&);
00035       FareRuleStruct& _fareRule;
00036     };
00037 
00039     struct storeFareId : public ParserSemanticAction {
00041       storeFareId (FareRuleStruct&);
00043       void operator() (unsigned int,
00044                        boost::spirit::qi::unused_type,
00045                        boost::spirit::qi::unused_type) const;
00046     };
00047 
00049     struct storeOrigin : public ParserSemanticAction {
00051       storeOrigin (FareRuleStruct&);
00053       void operator() (std::vector<char>,
00054                        boost::spirit::qi::unused_type,
00055                        boost::spirit::qi::unused_type) const;
00056     };
00057 
00059     struct storeDestination : public ParserSemanticAction {
00061       storeDestination (FareRuleStruct&);
00063       void operator() (std::vector<char>,
00064                        boost::spirit::qi::unused_type,
00065                        boost::spirit::qi::unused_type) const;
00066     };
00067     
00069     struct storeTripType : public ParserSemanticAction {
00071       storeTripType (FareRuleStruct&);
00073       void operator() (std::vector<char>,
00074                        boost::spirit::qi::unused_type,
00075                        boost::spirit::qi::unused_type) const;
00076     };
00077 
00078 
00080     struct storeDateRangeStart : public ParserSemanticAction {
00082       storeDateRangeStart (FareRuleStruct&);
00084       void operator() (boost::spirit::qi::unused_type,
00085                        boost::spirit::qi::unused_type,
00086                        boost::spirit::qi::unused_type) const;
00087     };
00088 
00090     struct storeDateRangeEnd : public ParserSemanticAction {
00092       storeDateRangeEnd (FareRuleStruct&);
00094       void operator() (boost::spirit::qi::unused_type,
00095                        boost::spirit::qi::unused_type,
00096                        boost::spirit::qi::unused_type) const;
00097     };
00098 
00100     struct storeStartRangeTime : public ParserSemanticAction {
00102       storeStartRangeTime (FareRuleStruct&);
00104       void operator() (boost::spirit::qi::unused_type,
00105                        boost::spirit::qi::unused_type,
00106                        boost::spirit::qi::unused_type) const;
00107     };
00108 
00110     struct storeEndRangeTime : public ParserSemanticAction {
00112       storeEndRangeTime (FareRuleStruct&);
00114       void operator() (boost::spirit::qi::unused_type,
00115                        boost::spirit::qi::unused_type,
00116                        boost::spirit::qi::unused_type) const;
00117     };
00118 
00120     struct storePOS : public ParserSemanticAction {
00122       storePOS (FareRuleStruct&);
00124       void operator() (std::vector<char>,
00125                        boost::spirit::qi::unused_type,
00126                        boost::spirit::qi::unused_type) const;
00127     };
00128 
00130     struct storeCabinCode : public ParserSemanticAction {
00132       storeCabinCode  (FareRuleStruct&);
00134       void operator() (char,
00135                        boost::spirit::qi::unused_type,
00136                        boost::spirit::qi::unused_type) const;
00137     };
00138 
00140     struct storeChannel : public ParserSemanticAction {
00142       storeChannel (FareRuleStruct&);
00144       void operator() (std::vector<char>,
00145                        boost::spirit::qi::unused_type,
00146                        boost::spirit::qi::unused_type) const;
00147     };
00148 
00150     struct storeAdvancePurchase : public ParserSemanticAction {
00152       storeAdvancePurchase (FareRuleStruct&);
00154       void operator() (unsigned int,
00155                        boost::spirit::qi::unused_type,
00156                        boost::spirit::qi::unused_type) const;
00157     };
00158 
00160     struct storeSaturdayStay : public ParserSemanticAction {
00162       storeSaturdayStay (FareRuleStruct&);
00164       void operator() (char,
00165                        boost::spirit::qi::unused_type,
00166                        boost::spirit::qi::unused_type) const;
00167     };
00168     
00170     struct storeChangeFees : public ParserSemanticAction {
00172       storeChangeFees (FareRuleStruct&);
00174       void operator() (char,
00175                        boost::spirit::qi::unused_type,
00176                        boost::spirit::qi::unused_type) const;
00177     };
00178 
00180     struct storeNonRefundable : public ParserSemanticAction {
00182       storeNonRefundable (FareRuleStruct&);
00184       void operator() (char,
00185                        boost::spirit::qi::unused_type,
00186                        boost::spirit::qi::unused_type) const;
00187     };
00188     
00190     struct storeMinimumStay : public ParserSemanticAction {
00192       storeMinimumStay (FareRuleStruct&);
00194       void operator() (unsigned int,
00195                        boost::spirit::qi::unused_type,
00196                        boost::spirit::qi::unused_type) const;
00197     };
00198 
00200     struct storeFare : public ParserSemanticAction {
00202       storeFare (FareRuleStruct&);
00204       void operator() (double,
00205                        boost::spirit::qi::unused_type,
00206                        boost::spirit::qi::unused_type) const; 
00207     };
00208     
00210     struct storeAirlineCode : public ParserSemanticAction {
00212       storeAirlineCode (FareRuleStruct&);
00214       void operator() (std::vector<char>,
00215                        boost::spirit::qi::unused_type,
00216                        boost::spirit::qi::unused_type) const;
00217     };
00218 
00220     struct storeClass : public ParserSemanticAction {
00222       storeClass (FareRuleStruct&);
00224       void operator() (std::vector<char>,
00225                        boost::spirit::qi::unused_type,
00226                        boost::spirit::qi::unused_type) const; 
00227     };
00228     
00230     struct doEndFare : public ParserSemanticAction {
00232       doEndFare (stdair::BomRoot&, FareRuleStruct&);
00234       void operator() (boost::spirit::qi::unused_type,
00235                        boost::spirit::qi::unused_type,
00236                        boost::spirit::qi::unused_type) const;
00238       stdair::BomRoot& _bomRoot;
00239     };
00240   
00241 
00243     //
00244     //  (Boost Spirit) Grammar Definition
00245     //
00247 
00276     struct FareRuleParser : 
00277       public boost::spirit::qi::grammar<stdair::iterator_t, 
00278                                         boost::spirit::ascii::space_type> {
00279 
00280       FareRuleParser (stdair::BomRoot&, FareRuleStruct&);
00281 
00282       // Instantiation of rules
00283       boost::spirit::qi::rule<stdair::iterator_t,
00284                               boost::spirit::ascii::space_type>
00285       start, comments, fare_rule, fare_rule_end, fare_key, fare_id, origin,
00286         destination, tripType, dateRangeStart, dateRangeEnd, date,
00287         timeRangeStart, timeRangeEnd, time, point_of_sale, cabinCode, channel,
00288         advancePurchase, saturdayStay, changeFees, nonRefundable, minimumStay,
00289         fare, segment;
00290       
00291       // Parser Context
00292       stdair::BomRoot& _bomRoot;
00293       FareRuleStruct& _fareRule;
00294     };
00295 
00296   }
00297   
00299   //
00300   //  Entry class for the file parser
00301   //
00303 
00309   class FareRuleFileParser : public stdair::CmdAbstract {
00310   public:
00312     FareRuleFileParser (stdair::BomRoot& ioBomRoot,
00313                         const stdair::Filename_T& iFilename);
00314 
00316     void generateFareRules ();
00317       
00318   private:
00320     void init();
00321       
00322   private:
00323     // Attributes
00325     stdair::Filename_T _filename;
00326 
00328     stdair::BomRoot& _bomRoot;
00329 
00331     FareRuleStruct _fareRule;
00332   };
00333     
00334 }
00335 #endif // __SIMFQT_CMD_FAREPARSERHELPER_HPP