TraDemGen Logo  0.2.2
C++ Simulated Travel Demand Generation Library
DemandParserHelper.hpp
Go to the documentation of this file.
00001 #ifndef __TRADEMGEN_CMD_DEMANDPARSERHELPER_HPP
00002 #define __TRADEMGEN_CMD_DEMANDPARSERHELPER_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 #include <string>
00009 // STDAIR
00010 #include <stdair/command/CmdAbstract.hpp>
00011 // TRADEMGEN
00012 #include <trademgen/TRADEMGEN_Types.hpp>
00013 #include <trademgen/basic/BasParserTypes.hpp>
00014 #include <trademgen/bom/DemandStruct.hpp>
00015 
00016 // Forward declarations
00017 namespace stdair {
00018   class EventQueue;
00019   struct RandomGeneration;
00020 }
00021 
00022 namespace TRADEMGEN {
00023 
00024   namespace DemandParserHelper {
00025     
00026     // ///////////////////////////////////////////////////////////////////
00027     //  Semantic actions
00028     // ///////////////////////////////////////////////////////////////////
00030     struct ParserSemanticAction {
00032       ParserSemanticAction (DemandStruct&);
00034       DemandStruct& _demand;
00035     };
00036   
00038     struct storePrefDepDateRangeStart : public ParserSemanticAction {
00040       storePrefDepDateRangeStart (DemandStruct&);
00042       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00043     };
00044 
00046     struct storePrefDepDateRangeEnd : public ParserSemanticAction {
00048       storePrefDepDateRangeEnd (DemandStruct&);
00050       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00051     };
00052 
00054     struct storeDow : public ParserSemanticAction {
00056       storeDow (DemandStruct&);
00058       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00059     };
00060 
00062     struct storeOrigin : public ParserSemanticAction {
00064       storeOrigin (DemandStruct&);
00066       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00067     };
00068   
00070     struct storeDestination : public ParserSemanticAction {
00072       storeDestination (DemandStruct&);
00074       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00075     };
00076 
00078     struct storePrefCabin : public ParserSemanticAction {
00080       storePrefCabin (DemandStruct&);
00082       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00083     };
00084 
00086     struct storeDemandMean : public ParserSemanticAction {
00088       storeDemandMean (DemandStruct&);
00090       void operator() (double iReal) const;
00091     };
00092   
00094     struct storeDemandStdDev : public ParserSemanticAction {
00096       storeDemandStdDev (DemandStruct&);
00098       void operator() (double iReal) const;
00099     };
00100   
00102     struct storePosCode : public ParserSemanticAction {
00104       storePosCode (DemandStruct&);
00106       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00107     };
00108   
00110     struct storePosProbMass : public ParserSemanticAction {
00112       storePosProbMass (DemandStruct&);
00114       void operator() (double iReal) const;
00115     };
00116   
00118     struct storeChannelCode : public ParserSemanticAction {
00120       storeChannelCode (DemandStruct&);
00122       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00123     };
00124   
00126     struct storeChannelProbMass : public ParserSemanticAction {
00128       storeChannelProbMass (DemandStruct&);
00130       void operator() (double iReal) const;
00131     };
00132   
00134     struct storeTripCode : public ParserSemanticAction {
00136       storeTripCode (DemandStruct&);
00138       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00139     };
00140   
00142     struct storeTripProbMass : public ParserSemanticAction {
00144       storeTripProbMass (DemandStruct&);
00146       void operator() (double iReal) const;
00147     };
00148   
00150     struct storeStayCode : public ParserSemanticAction {
00152       storeStayCode (DemandStruct&);
00154       void operator() (unsigned int iInteger) const;
00155     };
00156   
00158     struct storeStayProbMass : public ParserSemanticAction {
00160       storeStayProbMass (DemandStruct&);
00162       void operator() (double iReal) const;
00163     };
00164   
00166     struct storeFFCode : public ParserSemanticAction {
00168       storeFFCode (DemandStruct&);
00170       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00171     };
00172   
00174     struct storeFFProbMass : public ParserSemanticAction {
00176       storeFFProbMass (DemandStruct&);
00178       void operator() (double iReal) const;
00179     };
00180   
00183     struct storePrefDepTime : public ParserSemanticAction {
00185       storePrefDepTime (DemandStruct&);
00187       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00188     };    
00189     
00192     struct storePrefDepTimeProbMass : public ParserSemanticAction {
00194       storePrefDepTimeProbMass (DemandStruct&);
00196       void operator() (double iReal) const;
00197     };
00198   
00200     struct storeWTP : public ParserSemanticAction {
00202       storeWTP (DemandStruct&);
00204       void operator() (double iReal) const;
00205     };
00206     
00208     struct storeTimeValue : public ParserSemanticAction {
00210       storeTimeValue (DemandStruct&);
00212       void operator() (double iReal) const;
00213     };
00214   
00216     struct storeTimeValueProbMass : public ParserSemanticAction {
00218       storeTimeValueProbMass (DemandStruct&);
00220       void operator() (double iReal) const;
00221     };
00222   
00225     struct storeDTD : public ParserSemanticAction {
00227       storeDTD (DemandStruct&);
00229       void operator() (unsigned int iInteger) const;
00230     };    
00231     
00234     struct storeDTDProbMass : public ParserSemanticAction {
00236       storeDTDProbMass (DemandStruct&);
00238       void operator() (double iReal) const;
00239     };
00240   
00242     struct doEndDemand : public ParserSemanticAction {
00244       doEndDemand (stdair::EventQueue&, stdair::RandomGeneration&,
00245                    const POSProbabilityMass_T&, DemandStruct&);
00247       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00249       stdair::EventQueue& _eventQueue;
00250       stdair::RandomGeneration& _uniformGenerator;
00251       const POSProbabilityMass_T& _posProbabilityMass;
00252     };
00253   
00254 
00256     //
00257     //  (Boost Spirit) Grammar Definition
00258     //
00260 
00345     struct DemandParser : 
00346       public boost::spirit::classic::grammar<DemandParser> {
00347 
00348       DemandParser (stdair::EventQueue&, stdair::RandomGeneration&,
00349                     const POSProbabilityMass_T&, DemandStruct&);
00350 
00351       template <typename ScannerT>
00352       struct definition {
00353         definition (DemandParser const& self);
00354         
00355         // Instantiation of rules
00356         boost::spirit::classic::rule<ScannerT> demand_list,
00357           not_to_be_parsed, demand, demand_end, pref_dep_date_range,
00358           date, dow, origin, destination, pref_cabin, demand_params,
00359           pos_dist, pos_pair, pos_code, pos_share,
00360           channel_dist, channel_pair, channel_code, channel_share,
00361           trip_dist, trip_pair, trip_code, trip_share,
00362           stay_dist, stay_pair, stay_share,
00363           ff_dist, ff_pair, ff_code, ff_share,
00364           pref_dep_time_dist, pref_dep_time_pair, pref_dep_time_share, time,
00365           wtp,
00366           time_value_dist, time_value_pair, time_value_share,
00367           dtd_dist, dtd_pair, dtd_share;
00368 
00370         boost::spirit::classic::rule<ScannerT> const& start() const;
00371       };
00372 
00373       // Parser Context
00374       stdair::EventQueue& _eventQueue;
00375       stdair::RandomGeneration& _uniformGenerator;
00376       const POSProbabilityMass_T& _posProbabilityMass;
00377       DemandStruct& _demand;
00378     };
00379 
00380   }
00381 
00382 
00384   //
00385   //  Entry class for the file parser
00386   //
00388 
00393   class DemandFileParser : public stdair::CmdAbstract {
00394   public:
00396     DemandFileParser (stdair::EventQueue&, stdair::RandomGeneration&,
00397                       const POSProbabilityMass_T&,
00398                       const stdair::Filename_T& iDemandInputFilename);
00399 
00401     bool generateDemand ();
00402       
00403   private:
00405     void init();
00406       
00407   private:
00408     // Attributes
00410     stdair::Filename_T _filename;
00411 
00413     iterator_t _startIterator;
00414       
00416     iterator_t _endIterator;
00417       
00419     stdair::EventQueue& _eventQueue;
00420 
00422     stdair::RandomGeneration& _uniformGenerator;
00423 
00425     const POSProbabilityMass_T& _posProbabilityMass;
00426 
00428     DemandStruct _demand;
00429   };
00430     
00431 }
00432 #endif // __TRADEMGEN_CMD_DEMANDPARSERHELPER_HPP