AirSched Logo  0.1.4
C++ Simulated Airline Schedule Manager Library
OnDParserHelper.hpp
Go to the documentation of this file.
00001 #ifndef __AIRSCHED_CMD_ONDPARSERHELPER_HPP
00002 #define __AIRSCHED_CMD_ONDPARSERHELPER_HPP
00003 
00004 // //////////////////////////////////////////////////////////////////////
00005 // Import section
00006 // //////////////////////////////////////////////////////////////////////
00007 // STL
00008 #include <string>
00009 // Boost (Extended STL)
00010 #include <boost/date_time/posix_time/posix_time.hpp>
00011 #include <boost/date_time/gregorian/gregorian.hpp>
00012 // StdAir
00013 #include <stdair/command/CmdAbstract.hpp>
00014 // AirSched
00015 #include <airsched/AIRSCHED_Types.hpp>
00016 #include <airsched/basic/BasParserTypes.hpp>
00017 #include <airsched/bom/OnDPeriodStruct.hpp>
00018 
00019 // Forward declarations
00020 namespace stdair {
00021   class BomRoot;
00022 }
00023 
00024 namespace AIRSCHED {
00025 
00026   namespace OnDParserHelper {
00027            
00028     // ///////////////////////////////////////////////////////////////////////
00029     //
00030     //  Semantic actions
00031     //
00032     // ///////////////////////////////////////////////////////////////////////
00034     struct ParserSemanticAction {
00036       ParserSemanticAction (OnDPeriodStruct&);
00038       OnDPeriodStruct& _onDPeriod;
00039     };
00040 
00042     struct storeOrigin : public ParserSemanticAction {
00044       storeOrigin (OnDPeriodStruct&);
00046       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00047     };
00048   
00050     struct storeDestination : public ParserSemanticAction {
00052       storeDestination (OnDPeriodStruct&);
00054       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00055     };
00056 
00058     struct storeDateRangeStart : public ParserSemanticAction {
00060       storeDateRangeStart (OnDPeriodStruct&);
00062       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00063     };
00064 
00066     struct storeDateRangeEnd : public ParserSemanticAction {
00068       storeDateRangeEnd (OnDPeriodStruct&);
00070       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00071     };
00072 
00074     struct storeStartRangeTime : public ParserSemanticAction {
00076       storeStartRangeTime (OnDPeriodStruct&);
00078       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00079     };
00080 
00082     struct storeEndRangeTime : public ParserSemanticAction {
00084       storeEndRangeTime (OnDPeriodStruct&);
00086       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00087     };
00088 
00090     struct storeAirlineCode : public ParserSemanticAction {
00092       storeAirlineCode (OnDPeriodStruct&);
00094       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00095     };
00096 
00098     struct storeClassCode : public ParserSemanticAction {
00100       storeClassCode (OnDPeriodStruct&);
00102       void operator() (char iChar) const;
00103     };
00104 
00106     struct doEndOnD : public ParserSemanticAction {
00108       doEndOnD (stdair::BomRoot&, OnDPeriodStruct&);
00110       void operator() (iterator_t iStr, iterator_t iStrEnd) const;
00112       stdair::BomRoot& _bomRoot;
00113     };
00114 
00116     //
00117     //  (Boost Spirit) Grammar Definition
00118     //
00120 
00127     struct OnDParser : 
00128       public boost::spirit::classic::grammar<OnDParser> {
00129 
00130       OnDParser (stdair::BomRoot&, OnDPeriodStruct&);
00131 
00132       template <typename ScannerT>
00133       struct definition {
00134         definition (OnDParser const& self);
00135 
00136         // Instantiation of rules
00137         boost::spirit::classic::rule<ScannerT> ond_list, ond, segment,
00138           ond_key, ond_end, date, time;
00139 
00141         boost::spirit::classic::rule<ScannerT> const& start() const;
00142       };
00143 
00144       // Parser Context
00145       stdair::BomRoot& _bomRoot;
00146       OnDPeriodStruct& _onDPeriod;
00147     };
00148   }
00149     
00151   //
00152   //  Entry class for the file parser
00153   //
00155 
00161   class OnDPeriodFileParser : public stdair::CmdAbstract {
00162   public:
00164     OnDPeriodFileParser (const stdair::Filename_T& iFilename,
00165                          stdair::BomRoot& ioBomRoot);
00166       
00168     bool generateOnDPeriods ();
00169       
00170   private:
00172     void init();
00173       
00174   private:
00175     // Attributes
00177     stdair::Filename_T _filename;
00178       
00180     iterator_t _startIterator;
00181       
00183     iterator_t _endIterator;
00184       
00186     stdair::BomRoot& _bomRoot;
00187       
00189     OnDPeriodStruct _onDPeriod;
00190   };
00191   
00192 }
00193 #endif // __AIRSCHED_CMD_ONDPARSERHELPER_HPP