From: <den...@us...> - 2010-01-20 17:33:39
|
Revision: 3 http://simfqt.svn.sourceforge.net/simfqt/?rev=3&view=rev Author: denis_arnaud Date: 2010-01-20 17:33:33 +0000 (Wed, 20 Jan 2010) Log Message: ----------- [Dev] Removed the BasChronometer class, as it is now given by the StdAir library. Modified Paths: -------------- trunk/simfqt/simfqt/basic/sources.mk trunk/simfqt/simfqt/core/Makefile.am trunk/simfqt/simfqt/service/SIMFQT_Service.cpp Removed Paths: ------------- trunk/simfqt/simfqt/basic/BasChronometer.cpp trunk/simfqt/simfqt/basic/BasChronometer.hpp Deleted: trunk/simfqt/simfqt/basic/BasChronometer.cpp =================================================================== --- trunk/simfqt/simfqt/basic/BasChronometer.cpp 2009-12-31 10:45:52 UTC (rev 2) +++ trunk/simfqt/simfqt/basic/BasChronometer.cpp 2010-01-20 17:33:33 UTC (rev 3) @@ -1,50 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <cassert> -// Simfqt -#include <simfqt/basic/BasChronometer.hpp> -#include <simfqt/service/Logger.hpp> - -namespace SIMFQT { - - // ////////////////////////////////////////////////////////////////////// - BasChronometer::BasChronometer () : _startTimeLaunched (false) { - } - - // ////////////////////////////////////////////////////////////////////// - void BasChronometer::start () { - // Get the time-stamp of now, and store it for later use - _startTime = boost::posix_time::microsec_clock::local_time(); - - // Update the boolean which states whether the chronometer - // is launched - _startTimeLaunched = true; - } - - // ////////////////////////////////////////////////////////////////////// - double BasChronometer::elapsed () const { - assert (_startTimeLaunched == true); - - // Get the time-stamp of now - const boost::posix_time::ptime lStopTime = - boost::posix_time::microsec_clock::local_time(); - - // Calculate the time elapsed since the last time-stamp - const boost::posix_time::time_duration lElapsedTime = - lStopTime - _startTime; - - // Derived the corresponding number of milliseconds - const double lElapsedTimeInMicroSeconds = - static_cast<const double> (lElapsedTime.total_microseconds()); - - /*SIMFQT_LOG_DEBUG ("Elapsed: " << lElapsedTime - << "; (micros): " - << lElapsedTimeInMicroSeconds / 1e6);*/ - - // The elapsed time given in return is expressed in seconds - return (lElapsedTimeInMicroSeconds / 1e6); - } - -} Deleted: trunk/simfqt/simfqt/basic/BasChronometer.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasChronometer.hpp 2009-12-31 10:45:52 UTC (rev 2) +++ trunk/simfqt/simfqt/basic/BasChronometer.hpp 2010-01-20 17:33:33 UTC (rev 3) @@ -1,40 +0,0 @@ -#ifndef __SIMFQT_COM_BAS_BASCHRONOMETER_HPP -#define __SIMFQT_COM_BAS_BASCHRONOMETER_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// Boost Date-Time (http://boost.org/doc/html/date_time/posix_time.html) -#include <boost/date_time/posix_time/posix_time.hpp> - -namespace SIMFQT { - - /** Structure allowing measuring the time elapsed between two events. */ - struct BasChronometer { - /** Constructor. */ - BasChronometer(); - - /** Start the chronometer from the local time - <br>The elapsed time given is the one elapsed since the start - is launched. */ - void start (); - - /** Get the start time. */ - std::string getStart () const { - return boost::posix_time::to_simple_string (_startTime); - } - - /** Return the time elapsed since the structure has been instanciated. - <br>That elapsed time is expressed in seconds. */ - double elapsed () const; - - private: - /** Start time. */ - boost::posix_time::ptime _startTime; - - /** Boolean which states whether the chronometer is started or not.*/ - bool _startTimeLaunched; - }; - -} -#endif // __SIMFQT_COM_BAS_BASCHRONOMETER_HPP Modified: trunk/simfqt/simfqt/basic/sources.mk =================================================================== --- trunk/simfqt/simfqt/basic/sources.mk 2009-12-31 10:45:52 UTC (rev 2) +++ trunk/simfqt/simfqt/basic/sources.mk 2010-01-20 17:33:33 UTC (rev 3) @@ -1,5 +1,3 @@ bas_h_sources = $(top_srcdir)/simfqt/basic/BasConst_General.hpp \ - $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp \ - $(top_srcdir)/simfqt/basic/BasChronometer.hpp -bas_cc_sources = $(top_srcdir)/simfqt/basic/BasConst.cpp \ - $(top_srcdir)/simfqt/basic/BasChronometer.cpp + $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp +bas_cc_sources = $(top_srcdir)/simfqt/basic/BasConst.cpp Modified: trunk/simfqt/simfqt/core/Makefile.am =================================================================== --- trunk/simfqt/simfqt/core/Makefile.am 2009-12-31 10:45:52 UTC (rev 2) +++ trunk/simfqt/simfqt/core/Makefile.am 2010-01-20 17:33:33 UTC (rev 3) @@ -21,6 +21,7 @@ $(top_builddir)/simfqt/service/libsvc.la libsimfqt_la_LDFLAGS = \ $(BOOST_DATE_TIME_LIB) $(BOOST_PROGRAM_OPTIONS_LIB) \ + $(top_builddir)/stdair/core/libstdair.la \ -version-info $(GENERIC_LIBRARY_VERSION) # Header files Modified: trunk/simfqt/simfqt/service/SIMFQT_Service.cpp =================================================================== --- trunk/simfqt/simfqt/service/SIMFQT_Service.cpp 2009-12-31 10:45:52 UTC (rev 2) +++ trunk/simfqt/simfqt/service/SIMFQT_Service.cpp 2010-01-20 17:33:33 UTC (rev 3) @@ -6,9 +6,10 @@ // Boost #include <boost/date_time/gregorian/gregorian.hpp> #include <boost/date_time/posix_time/ptime.hpp> +// StdAir +#include <stdair/basic/BasChronometer.hpp> // Simfqt #include <simfqt/basic/BasConst_SIMFQT_Service.hpp> -#include <simfqt/basic/BasChronometer.hpp> #include <simfqt/command/FareQuoter.hpp> #include <simfqt/factory/FacSimfqtServiceContext.hpp> #include <simfqt/service/SIMFQT_ServiceContext.hpp> @@ -82,10 +83,9 @@ lSIMFQT_ServiceContext.getFareQuoteID(); // Delegate the price quotation to the dedicated command - BasChronometer lPriceQuotingChronometer; + stdair::BasChronometer lPriceQuotingChronometer; lPriceQuotingChronometer.start(); - oPrice = - FareQuoter::priceQuote (lFareQuoteID, iAirlineCode, iPartySize); + oPrice = FareQuoter::priceQuote (lFareQuoteID, iAirlineCode, iPartySize); const double lPriceQuotingMeasure = lPriceQuotingChronometer.elapsed(); // DEBUG This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <den...@us...> - 2010-01-21 19:34:17
|
Revision: 5 http://simfqt.svn.sourceforge.net/simfqt/?rev=5&view=rev Author: denis_arnaud Date: 2010-01-21 19:34:10 +0000 (Thu, 21 Jan 2010) Log Message: ----------- [Dev] The log output stream initialisation has been moved into the StdAir library. Modified Paths: -------------- trunk/simfqt/simfqt/SIMFQT_Service.hpp trunk/simfqt/simfqt/command/FareQuoter.cpp trunk/simfqt/simfqt/factory/FacSupervisor.cpp trunk/simfqt/simfqt/factory/FacSupervisor.hpp trunk/simfqt/simfqt/service/SIMFQT_Service.cpp trunk/simfqt/simfqt/service/sources.mk Removed Paths: ------------- trunk/simfqt/simfqt/service/Logger.cpp trunk/simfqt/simfqt/service/Logger.hpp Modified: trunk/simfqt/simfqt/SIMFQT_Service.hpp =================================================================== --- trunk/simfqt/simfqt/SIMFQT_Service.hpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/SIMFQT_Service.hpp 2010-01-21 19:34:10 UTC (rev 5) @@ -4,10 +4,10 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// STL -#include <iosfwd> -#include <string> -// Simfqt +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/BasLogParams.hpp> +// SimFQT #include <simfqt/SIMFQT_Types.hpp> namespace SIMFQT { @@ -26,10 +26,26 @@ // ////////// Constructors and destructors ////////// /** Constructor. - @param std::ostream& Output log stream (for instance, std::cout) + <br>The init() method is called; see the corresponding documentation + for more details. + <br>Moreover, a reference on an output stream is given, so + that log outputs can be directed onto that stream. + @param const stdair::BasLogParams& Parameters for the output log stream. @param FareQuoteID_T& ID of the Fare Quote system. */ - SIMFQT_Service (std::ostream& ioLogStream, const FareQuoteID_T&); + SIMFQT_Service (const stdair::BasLogParams&, const FareQuoteID_T&); + /** Constructor. + <br>The init() method is called; see the corresponding documentation + for more details. + <br>Moreover, as no reference on any output stream is given, + it is assumed that the StdAir log service has already been + initialised with the proper log output stream by some other + methods in the calling chain (for instance, when the AIRINV_Service + is itself being initialised by another library service such as + SIMCRS_Service). + @param FareQuoteID_T& ID of the Fare Quote system. */ + SIMFQT_Service (const FareQuoteID_T&); + /** Destructor. */ ~SIMFQT_Service(); @@ -41,9 +57,13 @@ /** Default copy constructor. */ SIMFQT_Service (const SIMFQT_Service&); - /** Initialise. */ - void init (std::ostream& ioLogStream, const FareQuoteID_T&); + /** Initialise the log. */ + void logInit (const stdair::BasLogParams&); + /** Initialise. + @param const FareQuoteID_T& ID of the owner of the FareQuote system. */ + void init (const FareQuoteID_T&); + /** Finalise. */ void finalise (); Modified: trunk/simfqt/simfqt/command/FareQuoter.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareQuoter.cpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/command/FareQuoter.cpp 2010-01-21 19:34:10 UTC (rev 5) @@ -2,10 +2,11 @@ // Import section // ////////////////////////////////////////////////////////////////////// // STL -#include <exception> +#include <cassert> +// StdAir +#include <stdair/service/Logger.hpp> // Simfqt #include <simfqt/command/FareQuoter.hpp> -#include <simfqt/service/Logger.hpp> namespace SIMFQT { @@ -18,13 +19,13 @@ try { // DEBUG - SIMFQT_LOG_DEBUG ("The price is " << oPrice + STDAIR_LOG_DEBUG ("The price is " << oPrice << " EUR for the travel request for the airline " << iAirlineCode << " for " << iPartySize << " passengers."); } catch (const std::exception& lStdError) { - SIMFQT_LOG_ERROR ("Error: " << lStdError.what()); + STDAIR_LOG_ERROR ("Error: " << lStdError.what()); throw QuotingException(); } Modified: trunk/simfqt/simfqt/factory/FacSupervisor.cpp =================================================================== --- trunk/simfqt/simfqt/factory/FacSupervisor.cpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/factory/FacSupervisor.cpp 2010-01-21 19:34:10 UTC (rev 5) @@ -7,15 +7,13 @@ #include <simfqt/factory/FacBomAbstract.hpp> #include <simfqt/factory/FacServiceAbstract.hpp> #include <simfqt/factory/FacSupervisor.hpp> -#include <simfqt/service/Logger.hpp> namespace SIMFQT { FacSupervisor* FacSupervisor::_instance = NULL; // ////////////////////////////////////////////////////////////////////// - FacSupervisor::FacSupervisor () : - _logger (NULL) { + FacSupervisor::FacSupervisor () { } // ////////////////////////////////////////////////////////////////////// @@ -40,15 +38,9 @@ } // ////////////////////////////////////////////////////////////////////// - void FacSupervisor::registerLoggerService (Logger* ioLogger_ptr) { - _logger = ioLogger_ptr; - } - - // ////////////////////////////////////////////////////////////////////// FacSupervisor::~FacSupervisor() { cleanBomLayer(); cleanServiceLayer(); - cleanLoggerService(); } // ////////////////////////////////////////////////////////////////////// @@ -80,16 +72,10 @@ } // ////////////////////////////////////////////////////////////////////// - void FacSupervisor::cleanLoggerService() { - delete _logger; _logger = NULL; - } - - // ////////////////////////////////////////////////////////////////////// void FacSupervisor::cleanFactory () { if (_instance != NULL) { _instance->cleanBomLayer(); _instance->cleanServiceLayer(); - _instance->cleanLoggerService(); } delete (_instance); _instance = NULL; } Modified: trunk/simfqt/simfqt/factory/FacSupervisor.hpp =================================================================== --- trunk/simfqt/simfqt/factory/FacSupervisor.hpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/factory/FacSupervisor.hpp 2010-01-21 19:34:10 UTC (rev 5) @@ -12,7 +12,6 @@ // Forward declarations class FacBomAbstract; class FacServiceAbstract; - class Logger; /** Singleton class to register and clean all Factories. */ class FacSupervisor { @@ -39,16 +38,6 @@ @param FacServiceAbstract& the concrete Factory to register. */ void registerServiceFactory (FacServiceAbstract*); - /** Register a newly instantiated concrete factory for the - Logger object. In fact, as the Logger object - follows the singleton pattern, the concrete factory is the - Logger object itself. - <br>When a concrete Factory is firstly instantiated this - factory have to register itself to the FacSupervisor. - @param FacServiceAbstract& the concrete Factory to - register. */ - void registerLoggerService (Logger*); - /** Clean all created object. <br>Call the clean method of all the instantiated factories for the Bom layer. */ @@ -59,9 +48,6 @@ for the Service layer. */ void cleanServiceLayer(); - /** Delete the Logger object. */ - void cleanLoggerService(); - /** Clean the static instance. <br> The singleton is deleted.*/ static void cleanFactory (); @@ -84,9 +70,6 @@ /** The unique instance.*/ static FacSupervisor* _instance; - /** Logger (singleton) instance. */ - Logger* _logger; - /** List of instantiated factories for the Bom layer. */ BomFactoryPool_T _bomPool; Deleted: trunk/simfqt/simfqt/service/Logger.cpp =================================================================== --- trunk/simfqt/simfqt/service/Logger.cpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/service/Logger.cpp 2010-01-21 19:34:10 UTC (rev 5) @@ -1,64 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <iostream> -// Simfqt Logger -#include <simfqt/factory/FacSupervisor.hpp> -#include <simfqt/service/Logger.hpp> - -namespace SIMFQT { - - Logger* Logger::_instance = NULL; - - // ////////////////////////////////////////////////////////////////////// - Logger::Logger () : _logStream (&std::cout) { - assert (false); - } - - // ////////////////////////////////////////////////////////////////////// - Logger::Logger (const Logger&) : _logStream (&std::cout) { - assert (false); - } - - // ////////////////////////////////////////////////////////////////////// - Logger::Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream) - : _level (iLevel), _logStream (&ioLogStream) { - } - - // ////////////////////////////////////////////////////////////////////// - Logger::~Logger () { - _logStream = NULL; - } - - // ////////////////////////////////////////////////////////////////////// - LOG::EN_LogLevel Logger::getLogLevel() { - return _level; - } - - // ////////////////////////////////////////////////////////////////////// - std::ostream& Logger::getLogStream() { - assert (_logStream != NULL); - return *_logStream; - } - - // ////////////////////////////////////////////////////////////////////// - void Logger::setLogParameters (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogStream) { - _level = iLogLevel; - _logStream = &ioLogStream; - } - - // ////////////////////////////////////////////////////////////////////// - Logger& Logger::instance() { - if (_instance == NULL) { - _instance = new Logger (LOG::DEBUG, std::cout); - - assert (_instance != NULL); - - FacSupervisor::instance().registerLoggerService (_instance); - } - return *_instance; - } - -} Deleted: trunk/simfqt/simfqt/service/Logger.hpp =================================================================== --- trunk/simfqt/simfqt/service/Logger.hpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/service/Logger.hpp 2010-01-21 19:34:10 UTC (rev 5) @@ -1,94 +0,0 @@ -#ifndef __SIMFQT_SVC_LOGGER_HPP -#define __SIMFQT_SVC_LOGGER_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <cassert> -#include <sstream> -#include <string> -// SIMFQT -#include <simfqt/SIMFQT_Types.hpp> - -// /////////////// LOG MACROS ///////////////// -#define SIMFQT_LOG_CORE(iLevel, iToBeLogged) \ - { std::ostringstream ostr; ostr << iToBeLogged; \ - SIMFQT::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); } - -#define SIMFQT_LOG_CRITICAL(iToBeLogged) \ - SIMFQT_LOG_CORE (SIMFQT::LOG::CRITICAL, iToBeLogged) - -#define SIMFQT_LOG_ERROR(iToBeLogged) \ - SIMFQT_LOG_CORE (SIMFQT::LOG::ERROR, iToBeLogged) - -#define SIMFQT_LOG_NOTIFICATION(iToBeLogged) \ - SIMFQT_LOG_CORE (SIMFQT::LOG::NOTIFICATION, iToBeLogged) - -#define SIMFQT_LOG_WARNING(iToBeLogged) \ - SIMFQT_LOG_CORE (SIMFQT::LOG::WARNING, iToBeLogged) - -#define SIMFQT_LOG_DEBUG(iToBeLogged) \ - SIMFQT_LOG_CORE (SIMFQT::LOG::DEBUG, iToBeLogged) - -#define SIMFQT_LOG_VERBOSE(iToBeLogged) \ - SIMFQT_LOG_CORE (SIMFQT::LOG::VERBOSE, iToBeLogged) -// /////////// (END OF) LOG MACROS ///////////// - - -namespace SIMFQT { - - /** Class holding the stream for logs. - <br>Note that the error logs are seen as standard output logs, - but with a higher level of visibility. */ - class Logger { - // Friend classes - friend class FacSupervisor; - public: - - /** Main log entry. */ - template <typename T> - void log (const LOG::EN_LogLevel iLevel, const int iLineNumber, - const std::string& iFileName, const T& iToBeLogged) { - if (iLevel <= _level) { - assert (_logStream != NULL); - *_logStream << iFileName << ":" << iLineNumber - << ": " << iToBeLogged << std::endl; - } - } - - /** Get the log level. */ - LOG::EN_LogLevel getLogLevel(); - - /** get the log stream. */ - std::ostream& getLogStream(); - - /** Set the logger parameters (level and stream). */ - void setLogParameters (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogStream); - - /** Returns a current Logger instance.*/ - static Logger& instance(); - - private: - /** Default constructors are private so that only the required - constructor can be used. */ - Logger (); - Logger (const Logger&); - Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream); - /** Destructor. */ - ~Logger (); - - private: - /** Log level. */ - LOG::EN_LogLevel _level; - - /** Stream dedicated to the logs. */ - std::ostream* _logStream; - - /** Instance object.*/ - static Logger* _instance; - }; - -} -#endif // __SIMFQT_SVC_LOGGER_HPP Modified: trunk/simfqt/simfqt/service/SIMFQT_Service.cpp =================================================================== --- trunk/simfqt/simfqt/service/SIMFQT_Service.cpp 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/service/SIMFQT_Service.cpp 2010-01-21 19:34:10 UTC (rev 5) @@ -3,29 +3,20 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <cassert> -// Boost -#include <boost/date_time/gregorian/gregorian.hpp> -#include <boost/date_time/posix_time/ptime.hpp> // StdAir #include <stdair/basic/BasChronometer.hpp> +#include <stdair/bom/BomManager.hpp> // for display() +#include <stdair/service/Logger.hpp> // Simfqt #include <simfqt/basic/BasConst_SIMFQT_Service.hpp> #include <simfqt/command/FareQuoter.hpp> #include <simfqt/factory/FacSimfqtServiceContext.hpp> #include <simfqt/service/SIMFQT_ServiceContext.hpp> -#include <simfqt/service/Logger.hpp> #include <simfqt/SIMFQT_Service.hpp> namespace SIMFQT { // ////////////////////////////////////////////////////////////////////// - SIMFQT_Service:: - SIMFQT_Service (std::ostream& ioLogStream, const FareQuoteID_T& iFareQuoteID) - : _simfqtServiceContext (NULL) { - init (ioLogStream, iFareQuoteID); - } - - // ////////////////////////////////////////////////////////////////////// SIMFQT_Service::SIMFQT_Service () : _simfqtServiceContext (NULL) { assert (false); @@ -37,23 +28,38 @@ } // ////////////////////////////////////////////////////////////////////// + SIMFQT_Service::SIMFQT_Service (const FareQuoteID_T& iFareQuoteID) + : _simfqtServiceContext (NULL) { + + // Initialise the context + init (iFareQuoteID); + } + + // ////////////////////////////////////////////////////////////////////// + SIMFQT_Service::SIMFQT_Service (const stdair::BasLogParams& iLogParams, + const FareQuoteID_T& iFareQuoteID) + : _simfqtServiceContext (NULL) { + + // Set the log file + logInit (iLogParams); + + // Initialise the (remaining of the) context + init (iFareQuoteID); + } + + // ////////////////////////////////////////////////////////////////////// SIMFQT_Service::~SIMFQT_Service () { // Delete/Clean all the objects from memory finalise(); } // ////////////////////////////////////////////////////////////////////// - void logInit (const LOG::EN_LogLevel iLogLevel, - std::ostream& ioLogOutputFile) { - Logger::instance().setLogParameters (iLogLevel, ioLogOutputFile); + void SIMFQT_Service::logInit (const stdair::BasLogParams& iLogParams) { + stdair::Logger::init (iLogParams); } // ////////////////////////////////////////////////////////////////////// - void SIMFQT_Service::init (std::ostream& ioLogStream, - const FareQuoteID_T& iFareQuoteID) { - // Set the log file - logInit (LOG::DEBUG, ioLogStream); - + void SIMFQT_Service::init (const FareQuoteID_T& iFareQuoteID) { // Initialise the context SIMFQT_ServiceContext& lSIMFQT_ServiceContext = FacSimfqtServiceContext::instance().create (iFareQuoteID); @@ -89,11 +95,11 @@ const double lPriceQuotingMeasure = lPriceQuotingChronometer.elapsed(); // DEBUG - SIMFQT_LOG_DEBUG ("Price quoting: " << lPriceQuotingMeasure << " - " + STDAIR_LOG_DEBUG ("Price quoting: " << lPriceQuotingMeasure << " - " << lSIMFQT_ServiceContext.display()); } catch (const std::exception& error) { - SIMFQT_LOG_ERROR ("Exception: " << error.what()); + STDAIR_LOG_ERROR ("Exception: " << error.what()); throw QuotingException(); } Modified: trunk/simfqt/simfqt/service/sources.mk =================================================================== --- trunk/simfqt/simfqt/service/sources.mk 2010-01-20 21:54:46 UTC (rev 4) +++ trunk/simfqt/simfqt/service/sources.mk 2010-01-21 19:34:10 UTC (rev 5) @@ -1,7 +1,5 @@ svc_h_sources = $(top_srcdir)/simfqt/service/ServiceAbstract.hpp \ - $(top_srcdir)/simfqt/service/SIMFQT_ServiceContext.hpp \ - $(top_srcdir)/simfqt/service/Logger.hpp + $(top_srcdir)/simfqt/service/SIMFQT_ServiceContext.hpp svc_cc_sources = $(top_srcdir)/simfqt/service/ServiceAbstract.cpp \ $(top_srcdir)/simfqt/service/SIMFQT_ServiceContext.cpp \ - $(top_srcdir)/simfqt/service/Logger.cpp \ $(top_srcdir)/simfqt/service/SIMFQT_Service.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qua...@us...> - 2010-10-13 13:31:25
|
Revision: 15 http://simfqt.svn.sourceforge.net/simfqt/?rev=15&view=rev Author: quannaus Date: 2010-10-13 13:31:19 +0000 (Wed, 13 Oct 2010) Log Message: ----------- [dev] Added input file. Modified Paths: -------------- trunk/simfqt/simfqt/SIMFQT_Service.hpp trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.cpp trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.hpp trunk/simfqt/simfqt/service/SIMFQT_Service.cpp trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.cpp trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.hpp Modified: trunk/simfqt/simfqt/SIMFQT_Service.hpp =================================================================== --- trunk/simfqt/simfqt/SIMFQT_Service.hpp 2010-09-07 09:57:32 UTC (rev 14) +++ trunk/simfqt/simfqt/SIMFQT_Service.hpp 2010-10-13 13:31:19 UTC (rev 15) @@ -6,10 +6,17 @@ // ////////////////////////////////////////////////////////////////////// // StdAir #include <stdair/STDAIR_Types.hpp> -#include <stdair/basic/BasLogParams.hpp> // SimFQT #include <simfqt/SIMFQT_Types.hpp> +// Forward declarations. +namespace stdair { + class STDAIR_Service; + struct BasLogParams; + struct BasDBParams; +} + + namespace SIMFQT { // Forward declaration @@ -24,15 +31,30 @@ Price_T priceQuote (const AirlineCode_T&, const PartySize_T&); - // ////////// Constructors and destructors ////////// + // ////////////////// Constructors and Destructors ////////////////// /** Constructor. <br>The init() method is called; see the corresponding documentation for more details. + <br>A reference on an output stream is given, so that log + outputs can be directed onto that stream. + <br>Moreover, database connection parameters are given, so that a + session can be created on the corresponding database. + @param const stdair::BasLogParams& Parameters for the output log stream. + @param const stdair::BasDBParams& Parameters for the database access. + @param const stdair::Filename_T& Filename of the input fare file. */ + SIMFQT_Service (const stdair::BasLogParams&, const stdair::BasDBParams&, + const stdair::Filename_T& iFareInputFilename); + + /** Constructor. + <br>The init() method is called; see the corresponding documentation + for more details. <br>Moreover, a reference on an output stream is given, so that log outputs can be directed onto that stream. @param const stdair::BasLogParams& Parameters for the output log stream. - @param FareQuoteID_T& ID of the Fare Quote system. */ - SIMFQT_Service (const stdair::BasLogParams&, const FareQuoteID_T&); + @param const stdair::Date_T& Date for the beginning of analysis. + @param const stdair::Filename_T& Filename of the input fare file. */ + SIMFQT_Service (const stdair::BasLogParams&, + const stdair::Filename_T& iFareInputFilename); /** Constructor. <br>The init() method is called; see the corresponding documentation @@ -40,11 +62,13 @@ <br>Moreover, as no reference on any output stream is given, it is assumed that the StdAir log service has already been initialised with the proper log output stream by some other - methods in the calling chain (for instance, when the AIRINV_Service + methods in the calling chain (for instance, when the SIMFQT_Service is itself being initialised by another library service such as SIMCRS_Service). - @param FareQuoteID_T& ID of the Fare Quote system. */ - SIMFQT_Service (const FareQuoteID_T&); + @param const stdair::Date_T& Date for the beginning of analysis. + @param const stdair::Filename_T& Filename of the input fare file. */ + SIMFQT_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_ServicePtr, + const stdair::Filename_T& iFareInputFilename); /** Destructor. */ ~SIMFQT_Service(); @@ -57,12 +81,31 @@ /** Default copy constructor. */ SIMFQT_Service (const SIMFQT_Service&); - /** Initialise the log. */ - void logInit (const stdair::BasLogParams&); + /** Initialise the (SIMFQT) service context (i.e., the + SIMFQT_ServiceContext object). */ + void initServiceContext (); + + /** Initialise the STDAIR service (including the log service). + <br>A reference on the root of the BOM tree, namely the BomRoot object, + is stored within the service context for later use. + @param const stdair::BasLogParams& Parameters for the output log stream. + @param const stdair::BasDBParams& Parameters for the database access. */ + void initStdAirService (const stdair::BasLogParams&, + const stdair::BasDBParams&); + + /** Initialise the STDAIR service (including the log service). + <br>A reference on the root of the BOM tree, namely the BomRoot object, + is stored within the service context for later use. + @param const stdair::BasLogParams& Parameters for the output log + stream. */ + void initStdAirService (const stdair::BasLogParams&); + /** Initialise. - @param const FareQuoteID_T& ID of the owner of the FareQuote system. */ - void init (const FareQuoteID_T&); + <br>The CSV file, describing the airline fares for the + simulator, is parsed and the inventories are generated accordingly. + @param const stdair::Filename_T& Filename of the input fare file. */ + void init (const stdair::Filename_T& iFareInputFilename); /** Finalise. */ void finalise (); Modified: trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.cpp =================================================================== --- trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.cpp 2010-09-07 09:57:32 UTC (rev 14) +++ trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.cpp 2010-10-13 13:31:19 UTC (rev 15) @@ -30,12 +30,11 @@ } // ////////////////////////////////////////////////////////////////////// - SIMFQT_ServiceContext& FacSimfqtServiceContext:: - create (const std::string& iTravelDatabaseName) { + SIMFQT_ServiceContext& FacSimfqtServiceContext::create () { SIMFQT_ServiceContext* aSIMFQT_ServiceContext_ptr = NULL; aSIMFQT_ServiceContext_ptr = - new SIMFQT_ServiceContext (iTravelDatabaseName); + new SIMFQT_ServiceContext (); assert (aSIMFQT_ServiceContext_ptr != NULL); // The new object is added to the Bom pool Modified: trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.hpp =================================================================== --- trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.hpp 2010-09-07 09:57:32 UTC (rev 14) +++ trunk/simfqt/simfqt/factory/FacSimfqtServiceContext.hpp 2010-10-13 13:31:19 UTC (rev 15) @@ -32,7 +32,7 @@ /** Create a new SIMFQT_ServiceContext object. <br>This new object is added to the list of instantiated objects. @return SIMFQT_ServiceContext& The newly created object. */ - SIMFQT_ServiceContext& create (const std::string& iTravelDatabaseName); + SIMFQT_ServiceContext& create (); protected: Modified: trunk/simfqt/simfqt/service/SIMFQT_Service.cpp =================================================================== --- trunk/simfqt/simfqt/service/SIMFQT_Service.cpp 2010-09-07 09:57:32 UTC (rev 14) +++ trunk/simfqt/simfqt/service/SIMFQT_Service.cpp 2010-10-13 13:31:19 UTC (rev 15) @@ -3,10 +3,14 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <cassert> +// Boost +#include <boost/make_shared.hpp> // StdAir #include <stdair/basic/BasChronometer.hpp> -#include <stdair/bom/BomManager.hpp> // for display() +#include <stdair/basic/BasFileMgr.hpp> +#include <stdair/bom/BomManager.hpp> #include <stdair/service/Logger.hpp> +#include <stdair/STDAIR_Service.hpp> // Simfqt #include <simfqt/basic/BasConst_SIMFQT_Service.hpp> #include <simfqt/command/FareQuoter.hpp> @@ -27,50 +31,147 @@ assert (false); } - // ////////////////////////////////////////////////////////////////////// - SIMFQT_Service::SIMFQT_Service (const FareQuoteID_T& iFareQuoteID) + // //////////////////////////////////////////////////////////////////// + SIMFQT_Service:: + SIMFQT_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_ServicePtr, + const stdair::Filename_T& iFareInputFilename) : _simfqtServiceContext (NULL) { + // Initialise the service context + initServiceContext (); + + // Retrieve the Simfqt service context + assert (_simfqtServiceContext != NULL); + SIMFQT_ServiceContext& lSIMFQT_ServiceContext = + *_simfqtServiceContext; + + // Store the STDAIR service object within the (SIMFQT) service context + lSIMFQT_ServiceContext.setSTDAIR_Service (ioSTDAIR_ServicePtr); + // Initialise the context - init (iFareQuoteID); + init (iFareInputFilename); } - // ////////////////////////////////////////////////////////////////////// - SIMFQT_Service::SIMFQT_Service (const stdair::BasLogParams& iLogParams, - const FareQuoteID_T& iFareQuoteID) + // //////////////////////////////////////////////////////////////////// + SIMFQT_Service:: + SIMFQT_Service (const stdair::BasLogParams& iLogParams, + const stdair::BasDBParams& iDBParams, + const stdair::Filename_T& iFareInputFilename) : _simfqtServiceContext (NULL) { - // Set the log file - logInit (iLogParams); + // Initialise the service context + initServiceContext (); + + // Initialise the STDAIR service handler + initStdAirService (iLogParams, iDBParams); + + // Initialise the (remaining of the) context + init (iFareInputFilename); + } + // //////////////////////////////////////////////////////////////////// + SIMFQT_Service:: + SIMFQT_Service (const stdair::BasLogParams& iLogParams, + const stdair::Filename_T& iFareInputFilename) + : _simfqtServiceContext (NULL) { + + // Initialise the service context + initServiceContext (); + + // Initialise the STDAIR service handler + initStdAirService (iLogParams); + // Initialise the (remaining of the) context - init (iFareQuoteID); + init (iFareInputFilename); } + // ////////////////////////////////////////////////////////////////////// SIMFQT_Service::~SIMFQT_Service () { // Delete/Clean all the objects from memory finalise(); } - + // ////////////////////////////////////////////////////////////////////// - void SIMFQT_Service::logInit (const stdair::BasLogParams& iLogParams) { - stdair::Logger::init (iLogParams); + void SIMFQT_Service::finalise () { + assert (_simfqtServiceContext != NULL); } // ////////////////////////////////////////////////////////////////////// - void SIMFQT_Service::init (const FareQuoteID_T& iFareQuoteID) { - // Initialise the context + void SIMFQT_Service::initServiceContext () { + // Initialise the service context SIMFQT_ServiceContext& lSIMFQT_ServiceContext = - FacSimfqtServiceContext::instance().create (iFareQuoteID); + FacSimfqtServiceContext::instance().create (); _simfqtServiceContext = &lSIMFQT_ServiceContext; } + + // ////////////////////////////////////////////////////////////////////// + void SIMFQT_Service:: + initStdAirService (const stdair::BasLogParams& iLogParams, + const stdair::BasDBParams& iDBParams) { + + // Retrieve the Simfqt service context + assert (_simfqtServiceContext != NULL); + SIMFQT_ServiceContext& lSIMFQT_ServiceContext = + *_simfqtServiceContext; + + // Initialise the STDAIR service handler + // Note that the track on the object memory is kept thanks to the Boost + // Smart Pointers component. + stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = + boost::make_shared<stdair::STDAIR_Service> (iLogParams, iDBParams); + + // Store the STDAIR service object within the (SIMFQT) service context + lSIMFQT_ServiceContext.setSTDAIR_Service (lSTDAIR_Service_ptr); + } // ////////////////////////////////////////////////////////////////////// - void SIMFQT_Service::finalise () { + void SIMFQT_Service:: + initStdAirService (const stdair::BasLogParams& iLogParams) { + + // Retrieve the Simfqt service context assert (_simfqtServiceContext != NULL); + SIMFQT_ServiceContext& lSIMFQT_ServiceContext = + *_simfqtServiceContext; + + // Initialise the STDAIR service handler + // Note that the track on the object memory is kept thanks to the Boost + // Smart Pointers component. + stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = + boost::make_shared<stdair::STDAIR_Service> (iLogParams); + + // Store the STDAIR service object within the (SIMFQT) service context + lSIMFQT_ServiceContext.setSTDAIR_Service (lSTDAIR_Service_ptr); } + + // //////////////////////////////////////////////////////////////////// + void SIMFQT_Service:: + init (const stdair::Filename_T& iFareInputFilename) { + // Check that the file path given as input corresponds to an actual file + const bool doesExistAndIsReadable = + stdair::BasFileMgr::doesExistAndIsReadable (iFareInputFilename); + if (doesExistAndIsReadable == false) { + STDAIR_LOG_ERROR ("The fare input file, '" << iFareInputFilename + << "', can not be retrieved on the file-system"); + throw stdair::FileNotFoundException(); + } + + // Retrieve the Simfqt service context + assert (_simfqtServiceContext != NULL); + SIMFQT_ServiceContext& lSIMFQT_ServiceContext = + *_simfqtServiceContext; + + // Retrieve the StdAir service context + stdair::STDAIR_ServicePtr_T lSTDAIR_Service_ptr = + lSIMFQT_ServiceContext.getSTDAIR_Service(); + assert (lSTDAIR_Service_ptr != NULL); + + // Get the root of the BOM tree, on which all of the other BOM objects + // will be attached + stdair::BomRoot& lBomRoot = lSTDAIR_Service_ptr->getBomRoot(); + } + // ////////////////////////////////////////////////////////////////////// Price_T SIMFQT_Service::priceQuote (const AirlineCode_T& iAirlineCode, const PartySize_T& iPartySize) { @@ -84,19 +185,15 @@ try { - // Retrieve the Fare Quote system ID - const FareQuoteID_T& lFareQuoteID = - lSIMFQT_ServiceContext.getFareQuoteID(); - // Delegate the price quotation to the dedicated command stdair::BasChronometer lPriceQuotingChronometer; lPriceQuotingChronometer.start(); - oPrice = FareQuoter::priceQuote (lFareQuoteID, iAirlineCode, iPartySize); - const double lPriceQuotingMeasure = lPriceQuotingChronometer.elapsed(); + // oPrice = FareQuoter::priceQuote (iAirlineCode, iPartySize); + // const double lPriceQuotingMeasure = lPriceQuotingChronometer.elapsed(); - // DEBUG - STDAIR_LOG_DEBUG ("Price quoting: " << lPriceQuotingMeasure << " - " - << lSIMFQT_ServiceContext.display()); + // // DEBUG + // STDAIR_LOG_DEBUG ("Price quoting: " << lPriceQuotingMeasure << " - " + // << lSIMFQT_ServiceContext.display()); } catch (const std::exception& error) { STDAIR_LOG_ERROR ("Exception: " << error.what()); Modified: trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.cpp =================================================================== --- trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.cpp 2010-09-07 09:57:32 UTC (rev 14) +++ trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.cpp 2010-10-13 13:31:19 UTC (rev 15) @@ -10,16 +10,15 @@ #include <simfqt/service/SIMFQT_ServiceContext.hpp> namespace SIMFQT { - + // ////////////////////////////////////////////////////////////////////// - SIMFQT_ServiceContext::SIMFQT_ServiceContext () - : _fareQuoteID (DEFAULT_FARE_QUOTER_ID) { + SIMFQT_ServiceContext:: + SIMFQT_ServiceContext (const SIMFQT_ServiceContext&) { + assert (false); } // ////////////////////////////////////////////////////////////////////// - SIMFQT_ServiceContext:: - SIMFQT_ServiceContext (const FareQuoteID_T& iFareQuoteID) - : _fareQuoteID (iFareQuoteID) { + SIMFQT_ServiceContext::SIMFQT_ServiceContext () { } // ////////////////////////////////////////////////////////////////////// @@ -29,9 +28,7 @@ // ////////////////////////////////////////////////////////////////////// const std::string SIMFQT_ServiceContext::shortDisplay() const { std::ostringstream oStr; - oStr << "SIMFQT_ServiceContext: " << std::endl - << "Fare Quote system ID: " << _fareQuoteID - << std::endl; + oStr << "SIMFQT_ServiceContext: " << std::endl; return oStr.str(); } Modified: trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.hpp =================================================================== --- trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.hpp 2010-09-07 09:57:32 UTC (rev 14) +++ trunk/simfqt/simfqt/service/SIMFQT_ServiceContext.hpp 2010-10-13 13:31:19 UTC (rev 15) @@ -6,6 +6,8 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> +// STDAIR +#include <stdair/STDAIR_Types.hpp> // Simfqt #include <simfqt/SIMFQT_Types.hpp> #include <simfqt/service/ServiceAbstract.hpp> @@ -17,26 +19,23 @@ friend class FacSimfqtServiceContext; public: // ///////// Getters ////////// - /** Get the Fare Quote system ID. */ - const FareQuoteID_T& getFareQuoteID () const { - return _fareQuoteID; + /** Get the pointer on the STDAIR service handler. */ + stdair::STDAIR_ServicePtr_T getSTDAIR_Service () const { + return _stdairService; } + + // ///////////////// Setters /////////////////// + /** Set the pointer on the STDAIR service handler. */ + void setSTDAIR_Service (stdair::STDAIR_ServicePtr_T ioSTDAIR_ServicePtr) { + _stdairService = ioSTDAIR_ServicePtr; + } - - // ///////// Setters ////////// - /** Set the Fare Quote system ID. */ - void setAirlineCode (const FareQuoteID_T& iFareQuoteID) { - _fareQuoteID = iFareQuoteID; - } - - // ///////// Display Methods ////////// /** Display the short SIMFQT_ServiceContext content. */ const std::string shortDisplay() const; /** Display the full SIMFQT_ServiceContext content. */ const std::string display() const; - private: // /////// Construction / initialisation //////// @@ -50,8 +49,8 @@ private: // //////////// Attributes ////////////////// - /** Fare Quote system ID. */ - FareQuoteID_T _fareQuoteID; + /** Standard Airline (StdAir) Service Handler. */ + stdair::STDAIR_ServicePtr_T _stdairService; }; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gsa...@us...> - 2010-11-02 16:01:35
|
Revision: 18 http://simfqt.svn.sourceforge.net/simfqt/?rev=18&view=rev Author: gsabatier Date: 2010-11-02 16:01:27 +0000 (Tue, 02 Nov 2010) Log Message: ----------- The simfqt parser files are now committed Modified Paths: -------------- trunk/simfqt/simfqt/SIMFQT_Service.hpp trunk/simfqt/simfqt/SIMFQT_Types.hpp trunk/simfqt/simfqt/batches/Makefile.am trunk/simfqt/simfqt/batches/sources.mk trunk/simfqt/simfqt/bom/Makefile.am trunk/simfqt/simfqt/bom/sources.mk trunk/simfqt/simfqt/command/FareQuoter.cpp trunk/simfqt/simfqt/command/FareQuoter.hpp trunk/simfqt/simfqt/command/sources.mk trunk/simfqt/simfqt/factory/FacSupervisor.cpp trunk/simfqt/simfqt/factory/FacSupervisor.hpp trunk/simfqt/simfqt/factory/sources.mk trunk/simfqt/simfqt/service/SIMFQT_Service.cpp Added Paths: ----------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp trunk/simfqt/simfqt/batches/simfqt.cpp trunk/simfqt/simfqt/batches/simfqt.log trunk/simfqt/simfqt/bom/FareRuleStruct.cpp trunk/simfqt/simfqt/bom/FareRuleStruct.hpp trunk/simfqt/simfqt/command/FareParser.cpp trunk/simfqt/simfqt/command/FareParser.hpp trunk/simfqt/simfqt/command/FareParserHelper.cpp trunk/simfqt/simfqt/command/FareParserHelper.hpp trunk/simfqt/simfqt/command/FareRuleGenerator.cpp trunk/simfqt/simfqt/command/FareRuleGenerator.hpp Removed Paths: ------------- trunk/simfqt/simfqt/bom/BomAbstract.cpp trunk/simfqt/simfqt/bom/BomAbstract.hpp trunk/simfqt/simfqt/factory/FacBomAbstract.cpp trunk/simfqt/simfqt/factory/FacBomAbstract.hpp Property Changed: ---------------- trunk/simfqt/simfqt/batches/ Modified: trunk/simfqt/simfqt/SIMFQT_Service.hpp =================================================================== --- trunk/simfqt/simfqt/SIMFQT_Service.hpp 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/SIMFQT_Service.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -26,11 +26,7 @@ /** Interface for the SIMFQT Services. */ class SIMFQT_Service { public: - // /////////// Business Methods ///////////// - /** Perform a price quotation for the travel request. */ - Price_T priceQuote (const AirlineCode_T&, const PartySize_T&); - - + // /////////// Business Methods ///////////// // ////////////////// Constructors and Destructors ////////////////// /** Constructor. <br>The init() method is called; see the corresponding documentation Modified: trunk/simfqt/simfqt/SIMFQT_Types.hpp =================================================================== --- trunk/simfqt/simfqt/SIMFQT_Types.hpp 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/SIMFQT_Types.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -5,13 +5,25 @@ // Import section // ////////////////////////////////////////////////////////////////////// // STL -#include <exception> +#include <vector> #include <string> +// StdAir namespace SIMFQT { // ///////// Exceptions /////////// class RootException : public std::exception { + public: + /** Constructors. */ + RootException (const std::string& iWhat) : _what (iWhat) {} + RootException () : _what ("No more details") {} + /** Destructor. */ + virtual ~RootException() throw() {} + /** Give the details of the exception. */ + const char* what() const throw() { return _what.c_str(); } + protected: + /** Details for the exception. */ + std::string _what; }; class NonInitialisedServiceException : public RootException { @@ -32,7 +44,20 @@ class QuotingException : public RootException { }; + class FileException : public RootException { + public: + /** Constructor. */ + FileException (const std::string& iWhat) : RootException (iWhat) {} + }; + class FareInputFileNotFoundException : public FileException { + public: + /** Constructor. */ + FareInputFileNotFoundException (const std::string& iWhat) + : FileException (iWhat) {} + }; + + // /////////////// Log ///////////// /** Level of logs. */ namespace LOG { @@ -50,14 +75,11 @@ // //////// Type definitions ///////// /** ID for the Fare Quote system. */ - typedef std::string FareQuoteID_T; + typedef unsigned int FareQuoteID_T; - /** Price, in Euros. */ + /** Price in euros. */ typedef double Price_T; - /** IATA code of an airline. */ - typedef std::string AirlineCode_T; - /** Number of passengers (in a group) for a booking. */ typedef unsigned short PartySize_T; Added: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp (rev 0) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,71 @@ +#ifndef __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP +#define __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +// Boost +//#define BOOST_SPIRIT_DEBUG +#include <boost/spirit/home/classic/core.hpp> +#include <boost/spirit/home/classic/attribute.hpp> +#include <boost/spirit/home/classic/utility/functor_parser.hpp> +#include <boost/spirit/home/classic/utility/loops.hpp> +#include <boost/spirit/home/classic/utility/chset.hpp> +#include <boost/spirit/home/classic/utility/confix.hpp> +#include <boost/spirit/home/classic/iterator/file_iterator.hpp> +#include <boost/spirit/home/classic/actor/push_back_actor.hpp> +#include <boost/spirit/home/classic/actor/assign_actor.hpp> + +namespace SIMFQT { + + // /////////////////////////////////////////////////////////////////////// + // + // Definition of Basic Types + // + // /////////////////////////////////////////////////////////////////////// + // For a file, the parsing unit is the character (char). For a string, + // it is a "char const *". + // typedef char const* iterator_t; + typedef char char_t; + + // The types of iterator, scanner and rule are then derived from + // the parsing unit. + typedef boost::spirit::classic::file_iterator<char_t> iterator_t; + typedef boost::spirit::classic::scanner<iterator_t> scanner_t; + typedef boost::spirit::classic::rule<scanner_t> rule_t; + + // /////////////////////////////////////////////////////////////////////// + // + // Parser related types + // + // /////////////////////////////////////////////////////////////////////// + /** 1-digit-integer parser */ + typedef boost::spirit::classic::int_parser<unsigned int, 10, 1, 1> int1_p_t; + + /** 2-digit-integer parser */ + typedef boost::spirit::classic::uint_parser<unsigned int, 10, 2, 2> uint2_p_t; + + /** 4-digit-integer parser */ + typedef boost::spirit::classic::uint_parser<unsigned int, 10, 4, 4> uint4_p_t; + + /** Up-to-4-digit-integer parser */ + typedef boost::spirit::classic::uint_parser<unsigned int, 10, 1, 4> uint1_4_p_t; + + /** character set */ + typedef boost::spirit::classic::chset<char_t> chset_t; + + /** (Repeating) sequence of a given number of characters: + repeat_p(min, max) */ + typedef boost::spirit::classic::impl::loop_traits<chset_t, + unsigned int, + unsigned int>::type repeat_p_t; + + /** Bounded-number-of-integers parser */ + typedef boost::spirit::classic::bounded<uint2_p_t, unsigned int> bounded2_p_t; + typedef boost::spirit::classic::bounded<uint4_p_t, unsigned int> bounded4_p_t; + typedef boost::spirit::classic::bounded<uint1_4_p_t, unsigned int> bounded1_4_p_t; + +} +#endif // __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP Property changes on: trunk/simfqt/simfqt/batches ___________________________________________________________________ Modified: svn:ignore - .deps .libs Makefile.in Makefile + .deps .libs Makefile.in Makefile .log Modified: trunk/simfqt/simfqt/batches/Makefile.am =================================================================== --- trunk/simfqt/simfqt/batches/Makefile.am 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/batches/Makefile.am 2010-11-02 16:01:27 UTC (rev 18) @@ -7,9 +7,10 @@ MAINTAINERCLEANFILES = Makefile.in # Binaries (batches) -bin_PROGRAMS = +bin_PROGRAMS = simfqt -#simfqt_SOURCES = $(batches_h_sources) $(batches_cc_sources) -#simfqt_CXXFLAGS = $(BOOST_CFLAGS) $(STDAIR_CFLAGS) -#simfqt_LDADD = -#simfqt_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LIB) $(STDAIR_LIBS) $(top_builddir)/simfqt/core/libsimfqt.la +simfqt_SOURCES = $(simfqt_batches_h_sources) $(simfqt_batches_cc_sources) +simfqt_CXXFLAGS = $(BOOST_CFLAGS) $(STDAIR_CFLAGS) +simfqt_LDADD = +simfqt_LDFLAGS = $(BOOST_PROGRAM_OPTIONS_LIB) $(STDAIR_LIBS) \ + $(top_builddir)/simfqt/core/libsimfqt.la Added: trunk/simfqt/simfqt/batches/simfqt.cpp =================================================================== --- trunk/simfqt/simfqt/batches/simfqt.cpp (rev 0) +++ trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,212 @@ +// STL +#include <cassert> +#include <iostream> +#include <sstream> +#include <fstream> +#include <vector> +#include <list> +#include <string> +// Boost (Extended STL) +#include <boost/date_time/posix_time/posix_time.hpp> +#include <boost/date_time/gregorian/gregorian.hpp> +#include <boost/tokenizer.hpp> +#include <boost/program_options.hpp> +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/STDAIR_Service.hpp> +#include <stdair/service/Logger.hpp> +// Simfqt +#include <simfqt/SIMFQT_Service.hpp> + +// //////// Type definitions /////// +typedef std::vector<std::string> WordList_T; + + +// //////// Constants ////// +/** Default name and location for the log file. */ +const std::string K_SIMFQT_DEFAULT_LOG_FILENAME ("simfqt.log"); + +/** Default name and location for the (CSV) input file. */ +const std::string K_SIMFQT_DEFAULT_INPUT_FILENAME ("../../test/samples/fare01.csv"); + +/** Default query string. */ +const std::string K_SIMFQT_DEFAULT_QUERY_STRING ("my good old query"); + + +// ////////////////////////////////////////////////////////////////////// +void tokeniseStringIntoWordList (const std::string& iPhrase, + WordList_T& ioWordList) { + // Empty the word list + ioWordList.clear(); + + // Boost Tokeniser + typedef boost::tokenizer<boost::char_separator<char> > Tokeniser_T; + + // Define the separators + const boost::char_separator<char> lSepatorList(" .,;:|+-*/_=!@#$%`~^&(){}[]?'<>\""); + + // Initialise the phrase to be tokenised + Tokeniser_T lTokens (iPhrase, lSepatorList); + for (Tokeniser_T::const_iterator tok_iter = lTokens.begin(); + tok_iter != lTokens.end(); ++tok_iter) { + const std::string& lTerm = *tok_iter; + ioWordList.push_back (lTerm); + } + +} + +// ////////////////////////////////////////////////////////////////////// +std::string createStringFromWordList (const WordList_T& iWordList) { + std::ostringstream oStr; + + unsigned short idx = iWordList.size(); + for (WordList_T::const_iterator itWord = iWordList.begin(); + itWord != iWordList.end(); ++itWord, --idx) { + const std::string& lWord = *itWord; + oStr << lWord; + if (idx > 1) { + oStr << " "; + } + } + + return oStr.str(); +} + + +// ///////// Parsing of Options & Configuration ///////// +// A helper function to simplify the main part. +template<class T> std::ostream& operator<< (std::ostream& os, + const std::vector<T>& v) { + std::copy (v.begin(), v.end(), std::ostream_iterator<T> (std::cout, " ")); + return os; +} + +/** Early return status (so that it can be differentiated from an error). */ +const int K_SIMFQT_EARLY_RETURN_STATUS = 99; + +/** Read and parse the command line options. */ +int readConfiguration (int argc, char* argv[], + std::string& ioQueryString, + stdair::Filename_T& ioInputFilename, + std::string& ioLogFilename) { + + // Initialise the travel query string, if that one is empty + if (ioQueryString.empty() == true) { + ioQueryString = K_SIMFQT_DEFAULT_QUERY_STRING; + } + + // Transform the query string into a list of words (STL strings) + WordList_T lWordList; + tokeniseStringIntoWordList (ioQueryString, lWordList); + + // Declare a group of options that will be allowed only on command line + boost::program_options::options_description generic ("Generic options"); + generic.add_options() + ("prefix", "print installation prefix") + ("version,v", "print version string") + ("help,h", "produce help message"); + + // Declare a group of options that will be allowed both on command + // line and in config file + boost::program_options::options_description config ("Configuration"); + config.add_options() + ("input,i", + boost::program_options::value< std::string >(&ioInputFilename)->default_value(K_SIMFQT_DEFAULT_INPUT_FILENAME), + "(CVS) input file for the demand distributions") + ("log,l", + boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_SIMFQT_DEFAULT_LOG_FILENAME), + "Filepath for the logs") + ("query,q", + boost::program_options::value< WordList_T >(&lWordList)->multitoken(), + "Query word list") + ; + + // Hidden options, will be allowed both on command line and + // in config file, but will not be shown to the user. + boost::program_options::options_description hidden ("Hidden options"); + hidden.add_options() + ("copyright", + boost::program_options::value< std::vector<std::string> >(), + "Show the copyright (license)"); + + boost::program_options::options_description cmdline_options; + cmdline_options.add(generic).add(config).add(hidden); + + boost::program_options::options_description config_file_options; + config_file_options.add(config).add(hidden); + + boost::program_options::options_description visible ("Allowed options"); + visible.add(generic).add(config); + + boost::program_options::positional_options_description p; + p.add ("copyright", -1); + + boost::program_options::variables_map vm; + boost::program_options:: + store (boost::program_options::command_line_parser (argc, argv). + options (cmdline_options).positional(p).run(), vm); + + std::ifstream ifs ("simfqt.cfg"); + boost::program_options::store (parse_config_file (ifs, config_file_options), + vm); + boost::program_options::notify (vm); + + if (vm.count ("help")) { + std::cout << visible << std::endl; + return K_SIMFQT_EARLY_RETURN_STATUS; + } + + if (vm.count ("input")) { + ioInputFilename = vm["input"].as< std::string >(); + std::cout << "Input filename is: " << ioInputFilename << std::endl; + } + + if (vm.count ("log")) { + ioLogFilename = vm["log"].as< std::string >(); + std::cout << "Log filename is: " << ioLogFilename << std::endl; + } + + ioQueryString = createStringFromWordList (lWordList); + std::cout << "The query string is: " << ioQueryString << std::endl; + + return 0; +} + +// /////////////// M A I N ///////////////// +int main (int argc, char* argv[]) { + try { + + // Query + std::string lQuery; + + // Input file name + stdair::Filename_T lInputFilename; + + // Output log File + std::string lLogFilename; + + // Call the command-line option parser + const int lOptionParserStatus = + readConfiguration (argc, argv, lQuery, lInputFilename, lLogFilename); + + if (lOptionParserStatus == K_SIMFQT_EARLY_RETURN_STATUS) { + return 0; + } + + // Set the log parameters + std::ofstream logOutputFile; + // Open and clean the log outputfile + logOutputFile.open (lLogFilename.c_str()); + logOutputFile.clear(); + + // Initialise the Simfqt service object + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + SIMFQT::SIMFQT_Service simfqtService (lLogParams, lInputFilename); + + // Close the Log outputFile + logOutputFile.close(); + + } CATCH_ALL_EXCEPTIONS + + return 0; +} Added: trunk/simfqt/simfqt/batches/simfqt.log =================================================================== --- trunk/simfqt/simfqt/batches/simfqt.log (rev 0) +++ trunk/simfqt/simfqt/batches/simfqt.log 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,2 @@ +[D]../../simfqt/command/FareParserHelper.cpp:530: Parsing fare input file: ../../test/samples/fare01.csv +[D]../../simfqt/command/FareParserHelper.cpp:550: Parsing of fare input file: ../../test/samples/fare01.csv succeeded: read 417 characters. The input file has not been fully read. Stop point: 1 Modified: trunk/simfqt/simfqt/batches/sources.mk =================================================================== --- trunk/simfqt/simfqt/batches/sources.mk 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/batches/sources.mk 2010-11-02 16:01:27 UTC (rev 18) @@ -1,2 +1,2 @@ -batches_h_sources = -batches_cc_sources = +simfqt_batches_h_sources = +simfqt_batches_cc_sources = $(top_srcdir)/simfqt/batches/simfqt.cpp Deleted: trunk/simfqt/simfqt/bom/BomAbstract.cpp =================================================================== --- trunk/simfqt/simfqt/bom/BomAbstract.cpp 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/bom/BomAbstract.cpp 2010-11-02 16:01:27 UTC (rev 18) @@ -1,9 +0,0 @@ -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// SIMFQT -#include <simfqt/bom/BomAbstract.hpp> - -namespace SIMFQT { - -} Deleted: trunk/simfqt/simfqt/bom/BomAbstract.hpp =================================================================== --- trunk/simfqt/simfqt/bom/BomAbstract.hpp 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/bom/BomAbstract.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -1,91 +0,0 @@ -#ifndef __SIMFQT_BOM_BOMABSTRACT_HPP -#define __SIMFQT_BOM_BOMABSTRACT_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <iosfwd> -#include <string> - -namespace SIMFQT { - - /** Base class for the Business Object Model (BOM) layer. */ - class BomAbstract { - friend class FacBomAbstract; - public: - // /////////// Display support methods ///////// - /** Dump a Business Object into an output stream. - @param ostream& the output stream. */ - virtual void toStream (std::ostream& ioOut) const = 0; - - /** Read a Business Object from an input stream. - @param istream& the input stream. */ - virtual void fromStream (std::istream& ioIn) = 0; - - /** Get the serialised version of the Business Object. */ - virtual std::string toString() const = 0; - - /** Get a string describing the whole key (differentiating two objects - at any level). */ - virtual std::string describeKey() const = 0; - - /** Get a string describing the short key (differentiating two objects - at the same level). */ - virtual std::string describeShortKey() const = 0; - - - protected: - /** Protected Default Constructor to ensure this class is abtract. */ - BomAbstract() {} - BomAbstract(const BomAbstract&) {} - - /** Destructor. */ - virtual ~BomAbstract() {} - }; -} - -/** - Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing - Output Operators" (p653) of his book "The C++ Standard Library: A Tutorial - and Reference", published by Addison-Wesley. - */ -template <class charT, class traits> -inline -std::basic_ostream<charT, traits>& -operator<< (std::basic_ostream<charT, traits>& ioOut, - const SIMFQT::BomAbstract& iBom) { - /** - string stream: - - with same format - - without special field width - */ - std::basic_ostringstream<charT,traits> ostr; - ostr.copyfmt (ioOut); - ostr.width (0); - - // Fill string stream - iBom.toStream (ostr); - - // Print string stream - ioOut << ostr.str(); - - return ioOut; -} - -/** - Piece of code given by Nicolai M. Josuttis, Section 13.12.1 "Implementing - Output Operators" (pp655-657) of his book "The C++ Standard Library: - A Tutorial and Reference", published by Addison-Wesley. - */ -template <class charT, class traits> -inline -std::basic_istream<charT, traits>& -operator>> (std::basic_istream<charT, traits>& ioIn, - SIMFQT::BomAbstract& ioBom) { - // Fill Bom object with input stream - ioBom.fromStream (ioIn); - return ioIn; -} - -#endif // __SIMFQT_BOM_BOMABSTRACT_HPP Added: trunk/simfqt/simfqt/bom/FareRuleStruct.cpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.cpp (rev 0) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,49 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <sstream> +// StdAir +#include <stdair/basic/BasConst_General.hpp> +#include <stdair/service/Logger.hpp> +// SIMFQT +#include <simfqt/SIMFQT_Types.hpp> +#include <simfqt/bom/FareRuleStruct.hpp> + +namespace SIMFQT { + + // //////////////////////////////////////////////////////////////////// + FareRuleStruct::FareRuleStruct () + :_fareId(0), _origin(""), _destination(""), + _dateRangeStart(stdair::DEFAULT_DATE), + _dateRangeEnd(stdair::DEFAULT_DATE), + _timeRangeStart(stdair::DEFAULT_EPSILON_DURATION), + _timeRangeEnd(stdair::DEFAULT_EPSILON_DURATION), + _pos (""), _advancePurchase(0), _saturdayStay("T"), + _changeFees("T"), _nonRefundable("T"), + _minimumStay(0), _fare(0), + _airlineCode(""), _classCode("") { + } + + // //////////////////////////////////////////////////////////////////// + stdair::Date_T FareRuleStruct::getDate() const { + return stdair::Date_T (_itYear, _itMonth, _itDay); + } + + // //////////////////////////////////////////////////////////////////// + stdair::Duration_T FareRuleStruct::getTime() const { + return boost::posix_time::hours (_itHours) + + boost::posix_time::minutes (_itMinutes) + + boost::posix_time::seconds (_itSeconds); + } + + + // //////////////////////////////////////////////////////////////////// + const std::string FareRuleStruct::describe () const { + std::ostringstream ostr; + return ostr.str(); + } + +} + Added: trunk/simfqt/simfqt/bom/FareRuleStruct.hpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.hpp (rev 0) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,108 @@ +#ifndef __SIMFQT_BOM_FARERULESTRUCT_HPP +#define __SIMFQT_BOM_FARERULESTRUCT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +#include <vector> +// STDAIR +#include <stdair/STDAIR_Types.hpp> +#include <stdair/basic/StructAbstract.hpp> +// SIMFQT +#include <simfqt/SIMFQT_Types.hpp> + +namespace SIMFQT { + + /** Utility Structure for the parsing of Flight-Period structures. */ + struct FareRuleStruct : public stdair::StructAbstract { + public: + + /** Default constructor. */ + FareRuleStruct (); + + /** Get the date from the staging details. */ + stdair::Date_T getDate() const; + + /** Get the time from the staging details. */ + stdair::Duration_T getTime() const; + + /** Display of the structure. */ + const std::string describe() const; + + // ////////////////// Attributes ///////////////// + /** Staging Date. */ + unsigned int _itYear; + unsigned int _itMonth; + unsigned int _itDay; + + /** Staging Time. */ + long _itHours; + long _itMinutes; + long _itSeconds; + + + unsigned long int _nbOfAirlines; + + /** Fare ID. */ + SIMFQT::FareQuoteID_T _fareId; + + /** Origin. */ + stdair::AirportCode_T _origin; + + /** Destination. */ + stdair::AirportCode_T _destination; + + /** Start Range date available for this fare rule.*/ + stdair::Date_T _dateRangeStart; + + /** Start Range date available for this fare rule.*/ + stdair::Date_T _dateRangeEnd; + + /** Start time from the time range available for this fare rule.*/ + stdair::Duration_T _timeRangeStart; + + /** End time from the time range available for this fare rule.*/ + stdair::Duration_T _timeRangeEnd; + + /** Point-of-sale. */ + stdair::AirlineCode_T _pos; + + /** Channel distribution. */ + stdair::ChannelLabel_T _channel; + + /** Number of days that the ticket is sold before the flightDate.*/ + stdair::DayDuration_T _advancePurchase; + + /** Boolean saying whether a saturday is considered during the stay .*/ + stdair::SaturdayStay_T _saturdayStay; + + /** Boolean saying whether the change fees option is requested or not.*/ + stdair::ChangeFees_T _changeFees; + + /** Boolean saying whether the refundable option is requested or not.*/ + stdair::NonRefundable_T _nonRefundable; + + /** Number of days that the customer spent into the destination city.*/ + stdair::DayDuration_T _minimumStay; + + /** Price.*/ + stdair::PriceValue_T _fare; + + /** Airline code */ + stdair::AirlineCode_T _airlineCode; + + /** Code */ + stdair::ClassCode_T _classCode; + + /** Airline Code List*/ + stdair::AirlineCodeList_T _airlineCodeList; + + /** Class Code List*/ + stdair::ClassCodeList_T _classCodeList; + + }; + +} +#endif // __SIMFQT_BOM_FARERULESTRUCT_HPP Modified: trunk/simfqt/simfqt/bom/Makefile.am =================================================================== --- trunk/simfqt/simfqt/bom/Makefile.am 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/bom/Makefile.am 2010-11-02 16:01:27 UTC (rev 18) @@ -6,7 +6,7 @@ noinst_LTLIBRARIES = libsimfqtbom.la libsimfqtbom_la_SOURCES = $(simfqt_bom_h_sources) $(simfqt_bom_cc_sources) -libsimfqtbom_la_CXXFLAGS = +libsimfqtbom_la_CXXFLAGS = $(STDAIR_CFLAGS) libsimfqtbom_la_LDFLAGS = # Modified: trunk/simfqt/simfqt/bom/sources.mk =================================================================== --- trunk/simfqt/simfqt/bom/sources.mk 2010-11-01 10:54:47 UTC (rev 17) +++ trunk/simfqt/simfqt/bom/sources.mk 2010-11-02 16:01:27 UTC (rev 18) @@ -1,4 +1,2 @@ -simfqt_bom_h_sources = \ - $(top_srcdir)/simfqt/bom/BomAbstract.hpp -simfqt_bom_cc_sources = \ - $(top_srcdir)/simfqt/bom/BomAbstract.cpp +simfqt_bom_h_sources = $(top_srcdir)/simfqt/bom/FareRuleStruct.hpp +simfqt_bom_cc_sources = $(top_srcdir)/simfqt/bom/FareRuleStruct.cpp Added: trunk/simfqt/simfqt/command/FareParser.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParser.cpp (rev 0) +++ trunk/simfqt/simfqt/command/FareParser.cpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,27 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <string> +// StdAir +//#include <stdair/bom/Inventory.hpp> +// AirSched +#include <simfqt/command/FareParserHelper.hpp> +#include <simfqt/command/FareParser.hpp> + +namespace SIMFQT { + + // ////////////////////////////////////////////////////////////////////// + void FareParser::fareRuleGeneration (const stdair::Filename_T& iFilename, + stdair::BomRoot& ioBomRoot) { + + // Initialise the Fare file parser. + FareRuleFileParser lFareRuleFileParser (ioBomRoot, iFilename); + + // Parse the CSV-formatted fare input file generate the + // corresponding fare rules and fulfill the WorldSchedule. + lFareRuleFileParser.generateFareRules (); + } + +} Added: trunk/simfqt/simfqt/command/FareParser.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParser.hpp (rev 0) +++ trunk/simfqt/simfqt/command/FareParser.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,31 @@ +#ifndef __SIMFQT_CMD_FAREPARSER_HPP +#define __SIMFQT_CMD_FAREPARSER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/command/CmdAbstract.hpp> + +// Forward declarations. +namespace stdair { + class BomRoot; +} + +namespace SIMFQT { + + /** Class wrapping the parser entry point. */ + class FareParser : public stdair::CmdAbstract { + public: + /** Parses the CSV file describing the fares for the + simulator, and generates the inventories accordingly. + @param const stdair::Filename_T& The file-name of the CSV-formatted + schedule input file. + @param stdair::BomRoot& Root of the BOM tree. */ + static void fareRuleGeneration (const stdair::Filename_T&, stdair::BomRoot&); + }; +} +#endif // __SIMFQT_CMD_FAREPARSER_HPP Added: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp (rev 0) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,563 @@ + // ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +#include <vector> +// StdAir +#include <stdair/basic/BasFileMgr.hpp> +#include <stdair/bom/BomRoot.hpp> +#include <stdair/service/Logger.hpp> +// SIMFQT +#include <simfqt/command/FareParserHelper.hpp> +#include <simfqt/command/FareRuleGenerator.hpp> + +namespace SIMFQT { + + namespace FareParserHelper { + + // ////////////////////////////////////////////////////////////////// + // Semantic actions + // ////////////////////////////////////////////////////////////////// + + ParserSemanticAction:: + ParserSemanticAction (FareRuleStruct& ioFareRule) + : _fareRule (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + storeFareId:: + storeFareId (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeFareId::operator() (unsigned int iFareId) const { + _fareRule._fareId = iFareId; + + //STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule._fareId); + + _fareRule._nbOfAirlines = 0; + _fareRule._airlineCode = ""; + _fareRule._classCode = ""; + _fareRule._airlineCodeList.clear(); + _fareRule._classCodeList.clear(); + } + + // ////////////////////////////////////////////////////////////////// + storeOrigin :: + storeOrigin (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeOrigin::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + stdair::AirportCode_T lOrigin (iStr, iStrEnd); + //STDAIR_LOG_DEBUG ( "Origin: " << lOrigin); + _fareRule._origin = lOrigin; + } + + // ////////////////////////////////////////////////////////////////// + storeDestination :: + storeDestination (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeDestination::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + stdair::AirportCode_T lDestination (iStr, iStrEnd); + //STDAIR_LOG_DEBUG ( "Destination: " << lDestination); + _fareRule._destination = lDestination; + } + + // ////////////////////////////////////////////////////////////////// + storeDateRangeStart:: + storeDateRangeStart (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeDateRangeStart::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + _fareRule._dateRangeStart = _fareRule.getDate(); + //STDAIR_LOG_DEBUG ("Date Range Start: "<< _fareRule._dateRangeStart); + } + + // ////////////////////////////////////////////////////////////////// + storeDateRangeEnd:: + storeDateRangeEnd(FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeDateRangeEnd::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + _fareRule._dateRangeEnd = _fareRule.getDate(); + //STDAIR_LOG_DEBUG ("Date Range End: " << _fareRule._dateRangeEnd); + } + + // ////////////////////////////////////////////////////////////////// + storeStartRangeTime:: + storeStartRangeTime (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeStartRangeTime::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + _fareRule._timeRangeStart = _fareRule.getTime(); + //STDAIR_LOG_DEBUG ("Time Range Start: " << _fareRule._timeRangeStart); + // Reset the number of seconds + _fareRule._itSeconds = 0; + } + + // ////////////////////////////////////////////////////////////////// + storeEndRangeTime:: + storeEndRangeTime (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeEndRangeTime::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + _fareRule._timeRangeEnd = _fareRule.getTime(); + // STDAIR_LOG_DEBUG ("Time Range End: " << _fareRule._timeRangeEnd); + // Reset the number of seconds + _fareRule._itSeconds = 0; + } + + // ////////////////////////////////////////////////////////////////// + storePOS :: + storePOS (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storePOS::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + stdair::AirlineCode_T lPOS (iStr, iStrEnd); + _fareRule._pos = lPOS; + //STDAIR_LOG_DEBUG ("POS: " << _fareRule._pos); + } + + // ////////////////////////////////////////////////////////////////// + storeChannel :: + storeChannel (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeChannel::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + stdair::ChannelLabel_T lChannel (iStr, iStrEnd); + _fareRule._channel = lChannel; + if (lChannel != "IN" && lChannel != "IF" + && lChannel != "DN" && lChannel != "DF") { + STDAIR_LOG_DEBUG ("Invalid channel " << lChannel); + } + // STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); + } + + // ////////////////////////////////////////////////////////////////// + storeAdvancePurchase :: + storeAdvancePurchase (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeAdvancePurchase::operator() (unsigned int iAdancePurchase) const { + _fareRule._advancePurchase = iAdancePurchase; + //STDAIR_LOG_DEBUG ( "Advance Purchase: " << _fareRule._advancePurchase); + } + + // ////////////////////////////////////////////////////////////////// + storeSaturdayStay :: + storeSaturdayStay (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeSaturdayStay::operator() (char iSaturdayStay) const { + bool lBool = false; + if (iSaturdayStay == 'T') { + lBool = true; + } else { + if (iSaturdayStay != 'F') { + STDAIR_LOG_DEBUG ("Invalid saturdayStay char " << iSaturdayStay); + } + } + stdair::SaturdayStay_T lSaturdayStay (lBool); + _fareRule._saturdayStay = lSaturdayStay; + //STDAIR_LOG_DEBUG ("Saturday Stay: " << _fareRule._saturdayStay); + } + + // ////////////////////////////////////////////////////////////////// + storeChangeFees :: + storeChangeFees (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeChangeFees::operator() (char iChangefees) const { + + bool lBool = false; + if (iChangefees == 'T') { + lBool = true; + } else { + if (iChangefees != 'F') { + STDAIR_LOG_DEBUG ("Invalid change fees char " << iChangefees); + } + } + stdair::ChangeFees_T lChangefees (lBool); + _fareRule._changeFees = lChangefees; + //STDAIR_LOG_DEBUG ("Change fees: " << _fareRule._changeFees); + } + + // ////////////////////////////////////////////////////////////////// + storeNonRefundable :: + storeNonRefundable (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeNonRefundable::operator() (char iNonRefundable) const { + bool lBool = false; + if (iNonRefundable == 'T') { + lBool = true; + } else { + if (iNonRefundable != 'F') { + STDAIR_LOG_DEBUG ("Invalid non refundable char " << iNonRefundable); + } + } + stdair::NonRefundable_T lNonRefundable (lBool); + _fareRule._nonRefundable = lNonRefundable; + // STDAIR_LOG_DEBUG ("Non refundable: " << _fareRule._nonRefundable); + } + + // ////////////////////////////////////////////////////////////////// + storeMinimumStay :: + storeMinimumStay (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeMinimumStay::operator() (unsigned int iMinStay) const { + _fareRule._minimumStay = iMinStay; + //STDAIR_LOG_DEBUG ("Minimum Stay: " << _fareRule._minimumStay ); + } + + // ////////////////////////////////////////////////////////////////// + storeFare :: + storeFare (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeFare::operator() (double iFare) const { + _fareRule._fare = iFare; + // STDAIR_LOG_DEBUG ("Fare: " << _fareRule._fare); + } + + // ////////////////////////////////////////////////////////////////// + storeAirlineCode :: + storeAirlineCode (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeAirlineCode::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + + bool lAlreadyInTheList = false; + stdair::AirlineCode_T lAirlineCode (iStr, iStrEnd); + // Update the airline code + _fareRule._airlineCode = lAirlineCode; + // Test if the FareRule Struct stands for interline products + if (_fareRule._airlineCodeList.size() > 0) { + // Update the number of airlines if necessary + std::vector<stdair::AirlineCode_T>::iterator Airline_iterator; + for (Airline_iterator = _fareRule._airlineCodeList.begin(); + Airline_iterator != _fareRule._airlineCodeList.end(); + ++Airline_iterator) { + stdair::AirlineCode_T lPreviousAirlineCode = + *Airline_iterator; + if (lPreviousAirlineCode == lAirlineCode) { + lAlreadyInTheList = true; + /*STDAIR_LOG_DEBUG ("Airline Code Already Existing: " + << lAirlineCode);*/ + } + } + if (lAlreadyInTheList == false) { + /*STDAIR_LOG_DEBUG ("New Airline Code: " + << lAirlineCode);*/ + _fareRule._airlineCodeList.push_back(lAirlineCode); + } + } else { + /*STDAIR_LOG_DEBUG ("First Airline Code: " + << lAirlineCode);*/ + _fareRule._airlineCodeList.push_back (lAirlineCode); + } + // STDAIR_LOG_DEBUG ( "Airline code: " << lAirlineCode); + } + + // ////////////////////////////////////////////////////////////////// + storeClass :: + storeClass (FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + void storeClass::operator() (char iChar) const { + std::ostringstream ostr; + ostr << iChar; + std::string classCodeStr = ostr.str(); + const stdair::ClassCode_T lClassCode (classCodeStr); + _fareRule._classCodeList.push_back(lClassCode); + // Insertion of this class Code in the whole classCode name + std::ostringstream ostrr; + ostrr << _fareRule._classCode << classCodeStr; + _fareRule._classCode = ostrr.str(); + //STDAIR_LOG_DEBUG ("Class Code: " << lClassCode << std::endl); + + } + + // ////////////////////////////////////////////////////////////////// + doEndFare:: + doEndFare (stdair::BomRoot& ioBomRoot, + FareRuleStruct& ioFareRule) + : ParserSemanticAction (ioFareRule), + _bomRoot (ioBomRoot) { + } + + // ////////////////////////////////////////////////////////////////// + + void doEndFare::operator() (iterator_t iStr, + iterator_t iStrEnd) const { + + // Generation of the fare rule object. + FareRuleGenerator::createFareRule (_bomRoot, _fareRule); + } + + // /////////////////////////////////////////////////////////////////// + // + // Utility Parsers + // + // /////////////////////////////////////////////////////////////////// + + /** 2-digit-integer parser */ + uint2_p_t uint2_p; + + /** 4-digit-integer parser */ + uint4_p_t uint4_p; + + /** Up-to-4-digit-integer parser */ + uint1_4_p_t uint1_4_p; + + /** Sequence of (capital) alphabetic characters: chset_p("A-Z") */ + chset_t alpha_cap_set_p ("A-Z"); + + /** Airport Parser: repeat_p(3)[chset_p("0-9A-Z")] */ + repeat_p_t airport_p (chset_t("0-9A-Z").derived(), 3, 3); + + /** Year Parser: limit_d(2000u, 2099u)[uint4_p] */ + bounded4_p_t year_p (uint4_p.derived(), 2000u, 2099u); + + /** Month Parser: limit_d(1u, 12u)[uint2_p] */ + bounded2_p_t month_p (uint2_p.derived(), 1u, 12u); + + /** Day Parser: limit_d(1u, 31u)[uint2_p] */ + bounded2_p_t day_p (uint2_p.derived(), 1u, 31u); + + /** Hour Parser: limit_d(0u, 23u)[uint2_p] */ + bounded2_p_t hours_p (uint2_p.derived(), 0u, 23u); + + /** Minute Parser: limit_d(0u, 59u)[uint2_p] */ + bounded2_p_t minutes_p (uint2_p.derived(), 0u, 59u); + + /** Second Parser: limit_d(0u, 59u)[uint2_p] */ + bounded2_p_t seconds_p (uint2_p.derived(), 0u, 59u); + + /** Airline Code Parser: repeat_p(2,3)[chset_p("0-9A-Z")] */ + repeat_p_t airline_code_p (chset_t("0-9A-Z").derived(), 2, 3); + + /** Channel type Parser: repeat_p(2,3)[chset_p("A-ZA-Z")] */ + repeat_p_t channel_type_p (chset_t("A-Z").derived(), 2, 3); + + // ////////////////////////////////////////////////////////////////// + // (Boost Spirit) Grammar Definition + // ////////////////////////////////////////////////////////////////// + + // ////////////////////////////////////////////////////////////////// + FareRuleParser:: + FareRuleParser (stdair::BomRoot& ioBomRoot, + FareRuleStruct& ioFareRule) + : _bomRoot (ioBomRoot), + _fareRule (ioFareRule) { + } + + // ////////////////////////////////////////////////////////////////// + template<typename ScannerT> + FareRuleParser::definition<ScannerT>:: + definition (FareRuleParser const& self) { + + fare_rule_list = *( comments | fare_rule ) + ; + + comments = boost::spirit::classic::comment_p("//") + | boost::spirit::classic::comment_p("/*", "*/") + ; + + fare_rule = fare_key + >> +( ';' >> segment ) + >> fare_rule_end[doEndFare(self._bomRoot, self._fareRule)] + ; + + fare_rule_end = boost::spirit::classic::ch_p(';') + ; + + fare_key = fare_id + >> ';' >> (airport_p)[storeOrigin(self._fareRule)] + >> ';' >> (airport_p)[storeDestination(self._fareRule)] + >> ';' >> date[storeDateRangeStart(self._fareRule)] + >> ';' >> date[storeDateRangeEnd(self._fareRule)] + >> ';' >> time[storeStartRangeTime(self._fareRule)] + >> ';' >> time[storeEndRangeTime(self._fareRule)] + >> ';' >> (airport_p)[storePOS(self._fareRule)] + >> ';' >> (channel_type_p)[storeChannel(self._fareRule)] + >> ';' >> (uint1_4_p)[storeAdvancePurchase(self._fareRule)] + >> ';' >> (alpha_cap_set_p)[storeSaturdayStay(self._fareRule)] + >> ';' >> (alpha_cap_set_p)[storeChangeFees(self._fareRule)] + >> ';' >> (alpha_cap_set_p)[storeNonRefundable(self._fareRule)] + >> ';' >> (uint1_4_p)[storeMinimumStay(self._fareRule)] + >> ';' >> (boost::spirit::classic::ureal_p)[storeFare(self._fareRule)] + ; + + fare_id = boost::spirit::classic::lexeme_d[ + (uint1_4_p)[storeFareId(self._fareRule)]] + ; + + date = boost::spirit::classic::lexeme_d[ + (year_p)[boost::spirit::classic::assign_a(self._fareRule._itYear)] + >> '-' + >> (month_p)[boost::spirit::classic::assign_a(self._fareRule._itMonth)] + >> '-' + >> (day_p)[boost::spirit::classic::assign_a(self._fareRule._itDay)]] + ; + + time = boost::spirit::classic::lexeme_d[ + (hours_p)[boost::spirit::classic::assign_a(self._fareRule._itHours)] + >> ':' + >> (minutes_p)[boost::spirit::classic::assign_a(self._fareRule._itMinutes)] + >> !(':' >> (seconds_p)[boost::spirit::classic::assign_a(self._fareRule._itSeconds)])] + ; + + segment = boost::spirit::classic::lexeme_d[ + (airline_code_p)[storeAirlineCode(self._fareRule)]] + >> ';' >> (alpha_cap_set_p)[storeClass(self._fareRule)] + ; + + //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); + BOOST_SPIRIT_DEBUG_NODE (fare_rule_list); + BOOST_SPIRIT_DEBUG_NODE (comments); + BOOST_SPIRIT_DEBUG_NODE (fare_rule); + BOOST_SPIRIT_DEBUG_NODE (fare_id); + BOOST_SPIRIT_DEBUG_NODE (fare_key); + BOOST_SPIRIT_DEBUG_NODE (segment); + BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); + BOOST_SPIRIT_DEBUG_NODE (date); + BOOST_SPIRIT_DEBUG_NODE (time); + + } + + // ////////////////////////////////////////////////////////////////// + template<typename ScannerT> + boost::spirit::classic::rule<ScannerT> const& + FareRuleParser::definition<ScannerT>::start() const { + return fare_rule_list; + } + + } + + + ///////////////////////////////////////////////////////////////////////// + // + // Entry class for the file parser + // + ///////////////////////////////////////////////////////////////////////// + + // ////////////////////////////////////////////////////////////////////// + FareRuleFileParser:: + FareRuleFileParser (stdair::BomRoot& ioBomRoot, + const stdair::Filename_T& iFilename) + : _filename (iFilename), _bomRoot (ioBomRoot) { + init(); + } + + // ////////////////////////////////////////////////////////////////////// + void FareRuleFileParser::init() { + // Check that the file exists and is readable + const bool doesExistAndIsReadable = + stdair::BasFileMgr::doesExistAndIsReadable (_filename); + + if (doesExistAndIsReadable == false) { + STDAIR_LOG_ERROR ("The fare schedule file " << _filename + << " does not exist or can not be read."); + + throw FareInputFileNotFoundException ("The fare file " + _filename + " does not exist or can not be read"); + } + + // Open the file + _startIterator = iterator_t (_filename); + + // Check the filename exists and can be open + if (!_startIterator) { + STDAIR_LOG_ERROR ("The fare file " << _filename << " can not be open." + << std::endl); + + throw FareInputFileNotFoundException ("The file " + _filename + " does not exist or can not be read"); + } + + // Create an EOF iterator + _endIterator = _startIterator.make_end(); + } + + // ////////////////////////////////////////////////////////////////////// + bool FareRuleFileParser::generateFareRules () { + bool oResult = false; + + STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); + + // Initialise the parser (grammar) with the helper/staging structure. + FareParserHelper::FareRuleParser lFPParser (_bomRoot, _fareRule); + + // Launch the parsing of the file and, thanks to the doEndFare + // call-back structure, the building of the whole BomRoot BOM + boost::spirit::classic::parse_info<iterator_t> info = + boost::spirit::classic::parse (_startIterator, _endIterator, lFPParser, + boost::spirit::classic::space_p); + + // Retrieves whether or not the parsing was successful + oResult = info.hit; + + const std::string hasBeenFullyReadStr = (info.full == true)?"":"not "; + if (oResult == true) { + STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename + << " succeeded: read " << info.length + << " characters. The input file has " + << hasBeenFullyReadStr + << "been fully read. Stop point: " << info.stop); + + } else { + // TODO: decide whether to throw an exception + STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename + << " failed: read " << info.length + << " characters. The input file has " + << hasBeenFullyReadStr + << "been fully read. Stop point: " << info.stop); + } + return oResult; + } + +} Added: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp (rev 0) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-02 16:01:27 UTC (rev 18) @@ -0,0 +1,328 @@ +#ifndef __SIMFQT_CMD_FAREPARSERHELPER_HPP +#define __SIMFQT_CMD_FAREPARSERHELPER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +// #define BOOST_SPIRIT_DEBUG +// StdAir +#include <stdair/command/CmdAbstract.hpp> +// AirSched +#include <simfqt/SIMFQT_Types.hpp> +#include <simfqt/basic/BasParserTypes.hpp> +#include <simfqt/bom/FareRuleStruct.hpp> + +// Forward declarations +namespace stdair { + class BomRoot; +} + +namespace SIMFQT { + + namespace FareParserHelper { + + // /////////////////////////////////////////////////////////////////// + // Semantic actions + // //////////////////////////////////////////////////// + /////////////// + /** Generic Semantic Action (Actor / Functor) for the Fare Parser. */ + struct ParserSemanticAction { + /** Actor Constructor. */ + ParserSemanticAction (FareRuleStruct&); + /** Actor Context. */ + FareRuleStruct& _fareRule; + }; + + /** Store the parsed fare Id. */ + struct storeFareId : public ParserSemanticAction { + /** Actor Constructor. */ + storeFareId (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (unsigned int) const; + }; + + /** Store the parsed origin. */ + struct storeOrigin : public ParserSemanticAction { + /** Actor Constructor. */ + storeOrigin (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed destination. */ + struct storeDestination : public ParserSemanticAction { + /** Actor Constructor. */ + storeDestination (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed start of the date range. */ + struct storeDateRangeStart : public ParserSemanticAction { + /** Actor Constructor. */ + storeDateRangeStart (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed end of the date range. */ + struct storeDateRangeEnd : public ParserSemanticAction { + /** Actor Constructor. */ + storeDateRangeEnd (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed start range time. */ + struct storeStartRangeTime : public ParserSemanticAction { + /** Actor Constructor. */ + storeStartRangeTime (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t iStr, iterator_t iStrEnd) const; + }; + + /** Store the parsed end start range time. */ + struct storeEndRangeTime : public ParserSemanticAction { + /** Actor Constructor. */ + storeEndRangeTime (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed customer position. */ + struct storePOS : public ParserSemanticAction { + /** Actor Constructor. */ + storePOS (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the channel distribution. */ + struct storeChannel : public ParserSemanticAction { + /** Actor Constructor. */ + storeChannel (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed advance purchase days. */ + struct storeAdvancePurchase : public ParserSemanticAction { + /** Actor Constructor. */ + storeAdvancePurchase (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (unsigned int) const; + }; + + /** Store the parsed saturday night. */ + struct storeSaturdayStay : public ParserSemanticAction { + /** Actor Constructor. */ + storeSaturdayStay (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (char) const; + }; + + /** Store the parsed change fees. */ + struct storeChangeFees : public ParserSemanticAction { + /** Actor Constructor. */ + storeChangeFees (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (char) const; + }; + + /** Store the parsed refundable option */ + struct storeNonRefundable : public ParserSemanticAction { + /** Actor Constructor. */ + storeNonRefundable (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (char) const; + }; + + /** Store the parsed minimum stay. */ + struct storeMinimumStay : public ParserSemanticAction { + /** Actor Constructor. */ + storeMinimumStay (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (unsigned int) const; + }; + + /** Store the parsed fare value. */ + struct storeFare : public ParserSemanticAction { + /** Actor Constructor. */ + storeFare (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (double) const; + }; + + /** Store the parsed airline code. */ + struct storeAirlineCode : public ParserSemanticAction { + /** Actor Constructor. */ + storeAirlineCode (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + }; + + /** Store the parsed class. */ + struct storeClass : public ParserSemanticAction { + /** Actor Constructor. */ + storeClass (FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (char) const; + }; + + /** Mark the end of the fare-rule parsing. */ + struct doEndFare : public ParserSemanticAction { + /** Actor Constructor. */ + doEndFare (stdair::BomRoot&, FareRuleStruct&); + /** Actor Function (functor). */ + void operator() (iterator_t, iterator_t) const; + /** Actor Specific Context. */ + stdair::BomRoot& _bomRoot; + }; + + + ///////////////////////////////////////////////////////////////////////// + // + // (Boost Spirit) Grammar Definition + // + ///////////////////////////////////////////////////////////////////////// + /** + + // Fare: fareID; OriginCity; DestinationCity; DateRangeStart; + DateRangeEnd; DepartureTimeRangeStart; DepartureTimeRangeEnd; + POS; AdvancePurchase; SaturdayNight; ChangeFees; NonRefundable; + MinimumStay; Price; AirlineCode; Class; + + fareID + OriginCity (3-char airport code) + DestinationCity (3-char airport code) + DateRangeStart (yyyy-mm-dd) + DateRangeEnd (yyyy-mm-dd) + DepartureTimeRangeStart (hh:mm) + DepartureTimeRangeEnd (hh:mm) + POS (3-char position city) + Channel (D=direct, I=indirect, N=oNline, F=oFfline) + AdvancePurchase + SaturdayNight (T=True, F=False) + ChangeFees (T=True, F=False) + NonRefundable (T=True, F=False) + MinimumStay + Price + AirlineCode (2-char airline code) + Class (1-char class code) + + Grammar: + Demand ::= PrefDepDate ';' Origin ';' Destination ';' PassengerType + ';' DemandParams ';' PosDist ';' ChannelDist ';' TripDist + ';' StayDist ';' FfDist ';' PrefDepTimeDist + ';' minWTP ';' TimeValueDist ';' DtdDist + EndOfDemand + PrefDepDate ::= date + PassengerType ::= 'T' | 'F' + DemandParams ::= DemandMean ';' DemandStdDev + PosDist ::= PosPair (',' PosPair)* + PosPair ::= PosCode ':' PosShare + PosCode ::= AirportCode | "row" + PosShare ::= real + ChannelDist ::= ChannelPair (',' ChannelPair)* + ChannelPair ::= Channel_Code ':' ChannelShare + ChannelCode ::= "DF" | "DN" | "IF" | "IN" + ChannelShare ::= real + TripDist ::= TripPair (',' TripPair)* + TripPair ::= TripCode ':' TripShare + TripCode ::= "RO" | "RI" | "OW" + TripShare ::= real + StayDist ::= StayPair (',' StayPair)* + StayPair ::= [0;3]-digit-integer ':' stay_share + StayShare ::= real + FFDist ::= FF_Pair (',' FF_Pair)* + FFPair ::= FFCode ':' FFShare + FFCode ::= 'P' | 'G' | 'S' | 'M' | 'N' + FFShare ::= real + PrefDepTimeDist ::= PrefDepTi... [truncated message content] |
From: <gsa...@us...> - 2010-11-29 08:52:30
|
Revision: 23 http://simfqt.svn.sourceforge.net/simfqt/?rev=23&view=rev Author: gsabatier Date: 2010-11-29 08:52:23 +0000 (Mon, 29 Nov 2010) Log Message: ----------- [Simfqt] Running error with spirit v2 parser Modified Paths: -------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp trunk/simfqt/simfqt/basic/sources.mk trunk/simfqt/simfqt/batches/simfqt.cpp trunk/simfqt/simfqt/bom/FareRuleStruct.cpp trunk/simfqt/simfqt/command/FareParser.cpp trunk/simfqt/simfqt/command/FareParserHelper.cpp trunk/simfqt/simfqt/command/FareParserHelper.hpp Modified: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-29 08:52:23 UTC (rev 23) @@ -1,22 +1,14 @@ -#ifndef __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP -#define __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP +#ifndef __SIMFQT_BAS_BASCOMPARSERTYPES_HPP +#define __SIMFQT_BAS_BASCOMPARSERTYPES_HPP // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// -// STL -#include <string> -// Boost -//#define BOOST_SPIRIT_DEBUG -#include <boost/spirit/home/classic/core.hpp> -#include <boost/spirit/home/classic/attribute.hpp> -#include <boost/spirit/home/classic/utility/functor_parser.hpp> -#include <boost/spirit/home/classic/utility/loops.hpp> -#include <boost/spirit/home/classic/utility/chset.hpp> -#include <boost/spirit/home/classic/utility/confix.hpp> -#include <boost/spirit/home/classic/iterator/file_iterator.hpp> -#include <boost/spirit/home/classic/actor/push_back_actor.hpp> -#include <boost/spirit/home/classic/actor/assign_actor.hpp> +// Boost Spirit (Parsing) +#include <boost/spirit/include/qi.hpp> +#include <boost/spirit/include/phoenix_core.hpp> +#include <boost/spirit/include/phoenix_operator.hpp> +#include <boost/spirit/include/support_multi_pass.hpp> namespace SIMFQT { @@ -25,47 +17,29 @@ // Definition of Basic Types // // /////////////////////////////////////////////////////////////////////// - // For a file, the parsing unit is the character (char). For a string, - // it is a "char const *". - // typedef char const* iterator_t; - typedef char char_t; // The types of iterator, scanner and rule are then derived from // the parsing unit. - typedef boost::spirit::classic::file_iterator<char_t> iterator_t; - typedef boost::spirit::classic::scanner<iterator_t> scanner_t; - typedef boost::spirit::classic::rule<scanner_t> rule_t; - + typedef std::istreambuf_iterator<char> base_iterator_t; + typedef boost::spirit::multi_pass<base_iterator_t> iterator_t; + + // /////////////////////////////////////////////////////////////////////// // // Parser related types // // /////////////////////////////////////////////////////////////////////// /** 1-digit-integer parser */ - typedef boost::spirit::classic::int_parser<unsigned int, 10, 1, 1> int1_p_t; + typedef boost::spirit::qi::int_parser<unsigned int, 10, 1, 1> int1_p_t; /** 2-digit-integer parser */ - typedef boost::spirit::classic::uint_parser<unsigned int, 10, 2, 2> uint2_p_t; + typedef boost::spirit::qi::uint_parser<unsigned int, 10, 2, 2> uint2_p_t; /** 4-digit-integer parser */ - typedef boost::spirit::classic::uint_parser<unsigned int, 10, 4, 4> uint4_p_t; + typedef boost::spirit::qi::uint_parser<unsigned int, 10, 4, 4> uint4_p_t; /** Up-to-4-digit-integer parser */ - typedef boost::spirit::classic::uint_parser<unsigned int, 10, 1, 4> uint1_4_p_t; - - /** character set */ - typedef boost::spirit::classic::chset<char_t> chset_t; - - /** (Repeating) sequence of a given number of characters: - repeat_p(min, max) */ - typedef boost::spirit::classic::impl::loop_traits<chset_t, - unsigned int, - unsigned int>::type repeat_p_t; - - /** Bounded-number-of-integers parser */ - typedef boost::spirit::classic::bounded<uint2_p_t, unsigned int> bounded2_p_t; - typedef boost::spirit::classic::bounded<uint4_p_t, unsigned int> bounded4_p_t; - typedef boost::spirit::classic::bounded<uint1_4_p_t, unsigned int> bounded1_4_p_t; - + typedef boost::spirit::qi::uint_parser<unsigned int, 10, 1, 4> uint1_4_p_t; + } -#endif // __AIRSCHED_BAS_BASCOMPARSERTYPES_HPP +#endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/basic/sources.mk =================================================================== --- trunk/simfqt/simfqt/basic/sources.mk 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/basic/sources.mk 2010-11-29 08:52:23 UTC (rev 23) @@ -1,5 +1,6 @@ simfqt_bas_h_sources = \ $(top_srcdir)/simfqt/basic/BasConst_General.hpp \ - $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp + $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp \ + $(top_srcdir)/simfqt/basic/BasParserTypes.hpp simfqt_bas_cc_sources = \ $(top_srcdir)/simfqt/basic/BasConst.cpp Modified: trunk/simfqt/simfqt/batches/simfqt.cpp =================================================================== --- trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -27,7 +27,7 @@ const std::string K_SIMFQT_DEFAULT_LOG_FILENAME ("simfqt.log"); /** Default name and location for the (CSV) input file. */ -const std::string K_SIMFQT_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare01.csv"); +const std::string K_SIMFQT_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare02.csv"); /** Default query string. */ const std::string K_SIMFQT_DEFAULT_QUERY_STRING ("my good old query"); Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.cpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -24,6 +24,7 @@ _changeFees("T"), _nonRefundable("T"), _minimumStay(0), _fare(0), _airlineCode(""), _classCode("") { + STDAIR_LOG_DEBUG ("fare rule struct."); } // //////////////////////////////////////////////////////////////////// Modified: trunk/simfqt/simfqt/command/FareParser.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParser.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/command/FareParser.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -6,6 +6,7 @@ #include <string> // StdAir //#include <stdair/bom/Inventory.hpp> +#include <stdair/service/Logger.hpp> // AirSched #include <simfqt/command/FareParserHelper.hpp> #include <simfqt/command/FareParser.hpp> @@ -22,6 +23,7 @@ // Parse the CSV-formatted fare input file generate the // corresponding fare rules and fulfill the WorldSchedule. lFareRuleFileParser.generateFareRules (); + STDAIR_LOG_DEBUG ("Finish!"); } } Modified: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-29 08:52:23 UTC (rev 23) @@ -4,6 +4,7 @@ // STL #include <cassert> #include <vector> +#include <fstream> // StdAir #include <stdair/basic/BasFileMgr.hpp> #include <stdair/bom/BomRoot.hpp> @@ -32,16 +33,18 @@ } // ////////////////////////////////////////////////////////////////// - void storeFareId::operator() (unsigned int iFareId) const { - _fareRule._fareId = iFareId; + void storeFareId::operator() (unsigned int iFareId, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + //_fareRule._fareId = iFareId; - //STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule._fareId); + STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule._fareId); _fareRule._nbOfAirlines = 0; - _fareRule._airlineCode = ""; - _fareRule._classCode = ""; - _fareRule._airlineCodeList.clear(); - _fareRule._classCodeList.clear(); + _fareRule._airlineCode = ""; + _fareRule._classCode = ""; + _fareRule._airlineCodeList.clear(); + _fareRule._classCodeList.clear(); } // ////////////////////////////////////////////////////////////////// @@ -51,10 +54,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeOrigin::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::AirportCode_T lOrigin (iStr, iStrEnd); - //STDAIR_LOG_DEBUG ( "Origin: " << lOrigin); + void storeOrigin::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::AirportCode_T lOrigin (iChar.begin(), iChar.end()); + STDAIR_LOG_DEBUG ( "Origin: " << lOrigin); _fareRule._origin = lOrigin; } @@ -65,10 +69,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeDestination::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::AirportCode_T lDestination (iStr, iStrEnd); - //STDAIR_LOG_DEBUG ( "Destination: " << lDestination); + void storeDestination::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::AirportCode_T lDestination (iChar.begin(), iChar.end()); + STDAIR_LOG_DEBUG ( "Destination: " << lDestination); _fareRule._destination = lDestination; } @@ -79,10 +84,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeDateRangeStart::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeDateRangeStart::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._dateRangeStart = _fareRule.getDate(); - //STDAIR_LOG_DEBUG ("Date Range Start: "<< _fareRule._dateRangeStart); + STDAIR_LOG_DEBUG ("Date Range Start: "<< _fareRule._dateRangeStart); } // ////////////////////////////////////////////////////////////////// @@ -92,10 +98,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeDateRangeEnd::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeDateRangeEnd::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._dateRangeEnd = _fareRule.getDate(); - //STDAIR_LOG_DEBUG ("Date Range End: " << _fareRule._dateRangeEnd); + STDAIR_LOG_DEBUG ("Date Range End: " << _fareRule._dateRangeEnd); } // ////////////////////////////////////////////////////////////////// @@ -105,10 +112,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeStartRangeTime::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeStartRangeTime::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._timeRangeStart = _fareRule.getTime(); - //STDAIR_LOG_DEBUG ("Time Range Start: " << _fareRule._timeRangeStart); + STDAIR_LOG_DEBUG ("Time Range Start: " << _fareRule._timeRangeStart); // Reset the number of seconds _fareRule._itSeconds = 0; } @@ -120,10 +128,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeEndRangeTime::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeEndRangeTime::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._timeRangeEnd = _fareRule.getTime(); - // STDAIR_LOG_DEBUG ("Time Range End: " << _fareRule._timeRangeEnd); + STDAIR_LOG_DEBUG ("Time Range End: " << _fareRule._timeRangeEnd); // Reset the number of seconds _fareRule._itSeconds = 0; } @@ -135,11 +144,12 @@ } // ////////////////////////////////////////////////////////////////// - void storePOS::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::AirlineCode_T lPOS (iStr, iStrEnd); + void storePOS::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::AirlineCode_T lPOS (iChar.begin(), iChar.end()); _fareRule._pos = lPOS; - //STDAIR_LOG_DEBUG ("POS: " << _fareRule._pos); + STDAIR_LOG_DEBUG ("POS: " << _fareRule._pos); } // ////////////////////////////////////////////////////////////////// @@ -149,15 +159,16 @@ } // ////////////////////////////////////////////////////////////////// - void storeChannel::operator() (iterator_t iStr, - iterator_t iStrEnd) const { - stdair::ChannelLabel_T lChannel (iStr, iStrEnd); + void storeChannel::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { + stdair::ChannelLabel_T lChannel (iChar.begin(), iChar.end()); _fareRule._channel = lChannel; if (lChannel != "IN" && lChannel != "IF" && lChannel != "DN" && lChannel != "DF") { STDAIR_LOG_DEBUG ("Invalid channel " << lChannel); } - // STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); + STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); } // ////////////////////////////////////////////////////////////////// @@ -167,9 +178,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeAdvancePurchase::operator() (unsigned int iAdancePurchase) const { + void storeAdvancePurchase::operator() (unsigned int iAdancePurchase, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._advancePurchase = iAdancePurchase; - //STDAIR_LOG_DEBUG ( "Advance Purchase: " << _fareRule._advancePurchase); + STDAIR_LOG_DEBUG ( "Advance Purchase: " << _fareRule._advancePurchase); } // ////////////////////////////////////////////////////////////////// @@ -179,7 +192,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeSaturdayStay::operator() (char iSaturdayStay) const { + void storeSaturdayStay::operator() (char iSaturdayStay, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lBool = false; if (iSaturdayStay == 'T') { lBool = true; @@ -190,7 +205,7 @@ } stdair::SaturdayStay_T lSaturdayStay (lBool); _fareRule._saturdayStay = lSaturdayStay; - //STDAIR_LOG_DEBUG ("Saturday Stay: " << _fareRule._saturdayStay); + STDAIR_LOG_DEBUG ("Saturday Stay: " << _fareRule._saturdayStay); } // ////////////////////////////////////////////////////////////////// @@ -200,7 +215,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeChangeFees::operator() (char iChangefees) const { + void storeChangeFees::operator() (char iChangefees, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lBool = false; if (iChangefees == 'T') { @@ -212,7 +229,7 @@ } stdair::ChangeFees_T lChangefees (lBool); _fareRule._changeFees = lChangefees; - //STDAIR_LOG_DEBUG ("Change fees: " << _fareRule._changeFees); + STDAIR_LOG_DEBUG ("Change fees: " << _fareRule._changeFees); } // ////////////////////////////////////////////////////////////////// @@ -222,7 +239,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeNonRefundable::operator() (char iNonRefundable) const { + void storeNonRefundable::operator() (char iNonRefundable, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lBool = false; if (iNonRefundable == 'T') { lBool = true; @@ -233,7 +252,7 @@ } stdair::NonRefundable_T lNonRefundable (lBool); _fareRule._nonRefundable = lNonRefundable; - // STDAIR_LOG_DEBUG ("Non refundable: " << _fareRule._nonRefundable); + STDAIR_LOG_DEBUG ("Non refundable: " << _fareRule._nonRefundable); } // ////////////////////////////////////////////////////////////////// @@ -243,9 +262,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeMinimumStay::operator() (unsigned int iMinStay) const { + void storeMinimumStay::operator() (unsigned int iMinStay, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._minimumStay = iMinStay; - //STDAIR_LOG_DEBUG ("Minimum Stay: " << _fareRule._minimumStay ); + STDAIR_LOG_DEBUG ("Minimum Stay: " << _fareRule._minimumStay ); } // ////////////////////////////////////////////////////////////////// @@ -255,9 +276,11 @@ } // ////////////////////////////////////////////////////////////////// - void storeFare::operator() (double iFare) const { + void storeFare::operator() (double iFare, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { _fareRule._fare = iFare; - // STDAIR_LOG_DEBUG ("Fare: " << _fareRule._fare); + STDAIR_LOG_DEBUG ("Fare: " << _fareRule._fare); } // ////////////////////////////////////////////////////////////////// @@ -267,11 +290,12 @@ } // ////////////////////////////////////////////////////////////////// - void storeAirlineCode::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void storeAirlineCode::operator() (std::vector<char> iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { bool lAlreadyInTheList = false; - stdair::AirlineCode_T lAirlineCode (iStr, iStrEnd); + stdair::AirlineCode_T lAirlineCode (iChar.begin(), iChar.end()); // Update the airline code _fareRule._airlineCode = lAirlineCode; // Test if the FareRule Struct stands for interline products @@ -299,7 +323,7 @@ << lAirlineCode);*/ _fareRule._airlineCodeList.push_back (lAirlineCode); } - // STDAIR_LOG_DEBUG ( "Airline code: " << lAirlineCode); + STDAIR_LOG_DEBUG ( "Airline code: " << lAirlineCode); } // ////////////////////////////////////////////////////////////////// @@ -309,7 +333,9 @@ } // ////////////////////////////////////////////////////////////////// - void storeClass::operator() (char iChar) const { + void storeClass::operator() (char iChar, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { std::ostringstream ostr; ostr << iChar; std::string classCodeStr = ostr.str(); @@ -319,7 +345,7 @@ std::ostringstream ostrr; ostrr << _fareRule._classCode << classCodeStr; _fareRule._classCode = ostrr.str(); - //STDAIR_LOG_DEBUG ("Class Code: " << lClassCode << std::endl); + STDAIR_LOG_DEBUG ("Class Code: " << lClassCode << std::endl); } @@ -333,164 +359,152 @@ // ////////////////////////////////////////////////////////////////// - void doEndFare::operator() (iterator_t iStr, - iterator_t iStrEnd) const { + void doEndFare::operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const { // Generation of the fare rule object. + STDAIR_LOG_DEBUG ("Do End"); FareRuleGenerator::createFareRule (_bomRoot, _fareRule); - } - + } + // /////////////////////////////////////////////////////////////////// // // Utility Parsers // // /////////////////////////////////////////////////////////////////// - + /** 1-digit-integer parser */ + int1_p_t int1_p; + /** 2-digit-integer parser */ uint2_p_t uint2_p; - + /** 4-digit-integer parser */ uint4_p_t uint4_p; - + /** Up-to-4-digit-integer parser */ uint1_4_p_t uint1_4_p; - /** Sequence of (capital) alphabetic characters: chset_p("A-Z") */ - chset_t alpha_cap_set_p ("A-Z"); - - /** Airport Parser: repeat_p(3)[chset_p("0-9A-Z")] */ - repeat_p_t airport_p (chset_t("0-9A-Z").derived(), 3, 3); - - /** Year Parser: limit_d(2000u, 2099u)[uint4_p] */ - bounded4_p_t year_p (uint4_p.derived(), 2000u, 2099u); - - /** Month Parser: limit_d(1u, 12u)[uint2_p] */ - bounded2_p_t month_p (uint2_p.derived(), 1u, 12u); - - /** Day Parser: limit_d(1u, 31u)[uint2_p] */ - bounded2_p_t day_p (uint2_p.derived(), 1u, 31u); - - /** Hour Parser: limit_d(0u, 23u)[uint2_p] */ - bounded2_p_t hours_p (uint2_p.derived(), 0u, 23u); - - /** Minute Parser: limit_d(0u, 59u)[uint2_p] */ - bounded2_p_t minutes_p (uint2_p.derived(), 0u, 59u); - - /** Second Parser: limit_d(0u, 59u)[uint2_p] */ - bounded2_p_t seconds_p (uint2_p.derived(), 0u, 59u); - - /** Airline Code Parser: repeat_p(2,3)[chset_p("0-9A-Z")] */ - repeat_p_t airline_code_p (chset_t("0-9A-Z").derived(), 2, 3); - - /** Channel type Parser: repeat_p(2,3)[chset_p("A-ZA-Z")] */ - repeat_p_t channel_type_p (chset_t("A-Z").derived(), 2, 3); - // ////////////////////////////////////////////////////////////////// // (Boost Spirit) Grammar Definition // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// - FareRuleParser:: - FareRuleParser (stdair::BomRoot& ioBomRoot, - FareRuleStruct& ioFareRule) - : _bomRoot (ioBomRoot), - _fareRule (ioFareRule) { - } + template <typename ITERATOR> + struct FareRuleParser : + public boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> { - // ////////////////////////////////////////////////////////////////// - template<typename ScannerT> - FareRuleParser::definition<ScannerT>:: - definition (FareRuleParser const& self) { + FareRuleParser (stdair::BomRoot& ioBomRoot, + FareRuleStruct& iofareRule) : + FareRuleParser::base_type(start), + _bomRoot(ioBomRoot), + _fareRule(iofareRule) { - fare_rule_list = *( comments | fare_rule ) - ; + STDAIR_LOG_DEBUG ("Begin parsing"); + + start = * (fare_rule) // *(comments | fare_rule) + ; - comments = boost::spirit::classic::comment_p("//") - | boost::spirit::classic::comment_p("/*", "*/") + comments = (boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("/")]) + >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) + >> +(boost::spirit::ascii::char_) + >> boost::spirit::qi::eol ] + | boost::spirit::qi::lexeme[ + (boost::spirit::ascii::char_("/") + >> boost::spirit::ascii::char_("*") + >> +(boost::spirit::ascii::char_ - boost::spirit::ascii::char_("*")) + >> boost::spirit::ascii::char_("*") + >> boost::spirit::ascii::char_("/")) ]) ; - fare_rule = fare_key - >> +( ';' >> segment ) - >> fare_rule_end[doEndFare(self._bomRoot, self._fareRule)] + fare_rule =// fare_key + //>> +( ';' >> segment ) + //>> + fare_rule_end[doEndFare(_bomRoot, _fareRule)] ; - fare_rule_end = boost::spirit::classic::ch_p(';') + fare_rule_end = boost::spirit::ascii::char_(";") ; fare_key = fare_id - >> ';' >> (airport_p)[storeOrigin(self._fareRule)] - >> ';' >> (airport_p)[storeDestination(self._fareRule)] - >> ';' >> date[storeDateRangeStart(self._fareRule)] - >> ';' >> date[storeDateRangeEnd(self._fareRule)] - >> ';' >> time[storeStartRangeTime(self._fareRule)] - >> ';' >> time[storeEndRangeTime(self._fareRule)] - >> ';' >> (airport_p)[storePOS(self._fareRule)] - >> ';' >> (channel_type_p)[storeChannel(self._fareRule)] - >> ';' >> (uint1_4_p)[storeAdvancePurchase(self._fareRule)] - >> ';' >> (alpha_cap_set_p)[storeSaturdayStay(self._fareRule)] - >> ';' >> (alpha_cap_set_p)[storeChangeFees(self._fareRule)] - >> ';' >> (alpha_cap_set_p)[storeNonRefundable(self._fareRule)] - >> ';' >> (uint1_4_p)[storeMinimumStay(self._fareRule)] - >> ';' >> (boost::spirit::classic::ureal_p)[storeFare(self._fareRule)] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storeOrigin(_fareRule)] ] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storeDestination(_fareRule)] ] + >> ';' >> date[storeDateRangeStart(_fareRule)] + >> ';' >> date[storeDateRangeEnd(_fareRule)] + >> ';' >> time[storeStartRangeTime(_fareRule)] + >> ';' >> time[storeEndRangeTime(_fareRule)] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storePOS(_fareRule)] ] + >> ';' >> boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")])[storeChannel(_fareRule)] ] + >> ';' >> (uint1_4_p)[storeAdvancePurchase(_fareRule)] + >> ';' >> boost::spirit::ascii::char_("A-Z")[storeSaturdayStay(_fareRule)] + >> ';' >> boost::spirit::ascii::char_("A-Z")[storeChangeFees(_fareRule)] + >> ';' >> boost::spirit::ascii::char_("A-Z")[storeNonRefundable(_fareRule)] + >> ';' >> uint1_4_p[storeMinimumStay(_fareRule)] + >> ';' >> boost::spirit::qi::double_[storeFare(_fareRule)] ; - fare_id = boost::spirit::classic::lexeme_d[ - (uint1_4_p)[storeFareId(self._fareRule)]] + fare_id = boost::spirit::qi::lexeme[ + uint1_4_p[storeFareId(_fareRule)] ] ; - date = boost::spirit::classic::lexeme_d[ - (year_p)[boost::spirit::classic::assign_a(self._fareRule._itYear)] - >> '-' - >> (month_p)[boost::spirit::classic::assign_a(self._fareRule._itMonth)] - >> '-' - >> (day_p)[boost::spirit::classic::assign_a(self._fareRule._itDay)]] + date = boost::spirit::qi::lexeme[ + uint4_p[boost::phoenix::ref(_fareRule._itYear) = boost::spirit::qi::labels::_1] + >> '-' + >> uint2_p[boost::phoenix::ref(_fareRule._itMonth) =boost::spirit::qi::labels::_1] + >> '-' + >> uint2_p[boost::phoenix::ref(_fareRule._itDay) = boost::spirit::qi::labels::_1] ] ; - - time = boost::spirit::classic::lexeme_d[ - (hours_p)[boost::spirit::classic::assign_a(self._fareRule._itHours)] - >> ':' - >> (minutes_p)[boost::spirit::classic::assign_a(self._fareRule._itMinutes)] - >> !(':' >> (seconds_p)[boost::spirit::classic::assign_a(self._fareRule._itSeconds)])] - ; + + time = boost::spirit::qi::lexeme[ + uint2_p[boost::phoenix::ref(_fareRule._itHours) = boost::spirit::qi::labels::_1] + >> ':' + >> uint2_p[boost::phoenix::ref(_fareRule._itMinutes) = boost::spirit::qi::labels::_1] + >> !(':' >> (uint2_p)[boost::phoenix::ref(_fareRule._itSeconds) = boost::spirit::qi::labels::_1]) ] + ; - segment = boost::spirit::classic::lexeme_d[ - (airline_code_p)[storeAirlineCode(self._fareRule)]] - >> ';' >> (alpha_cap_set_p)[storeClass(self._fareRule)] + segment = boost::spirit::qi::lexeme[ + (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")])[storeAirlineCode(_fareRule)] ] + >> ';' + >> boost::spirit::ascii::char_("A-Z")[storeClass(_fareRule)] ; - //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); - BOOST_SPIRIT_DEBUG_NODE (fare_rule_list); - BOOST_SPIRIT_DEBUG_NODE (comments); - BOOST_SPIRIT_DEBUG_NODE (fare_rule); - BOOST_SPIRIT_DEBUG_NODE (fare_id); - BOOST_SPIRIT_DEBUG_NODE (fare_key); - BOOST_SPIRIT_DEBUG_NODE (segment); - BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); - BOOST_SPIRIT_DEBUG_NODE (date); - BOOST_SPIRIT_DEBUG_NODE (time); + //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); + BOOST_SPIRIT_DEBUG_NODE (start); + BOOST_SPIRIT_DEBUG_NODE (comments); + BOOST_SPIRIT_DEBUG_NODE (fare_rule); + BOOST_SPIRIT_DEBUG_NODE (fare_id); + BOOST_SPIRIT_DEBUG_NODE (fare_key); + BOOST_SPIRIT_DEBUG_NODE (segment); + BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); + BOOST_SPIRIT_DEBUG_NODE (date); + BOOST_SPIRIT_DEBUG_NODE (time); + } - } + boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> + start, comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, + date, time; + + // Parser Context + stdair::BomRoot& _bomRoot; + FareRuleStruct& _fareRule; + }; - // ////////////////////////////////////////////////////////////////// - template<typename ScannerT> - boost::spirit::classic::rule<ScannerT> const& - FareRuleParser::definition<ScannerT>::start() const { - return fare_rule_list; - } - } - - ///////////////////////////////////////////////////////////////////////// // // Entry class for the file parser // ///////////////////////////////////////////////////////////////////////// - + // ////////////////////////////////////////////////////////////////////// FareRuleFileParser:: - FareRuleFileParser (stdair::BomRoot& ioBomRoot, - const stdair::Filename_T& iFilename) + FareRuleFileParser (stdair::BomRoot& ioBomRoot, + const stdair::Filename_T& iFilename) : _filename (iFilename), _bomRoot (ioBomRoot) { init(); } @@ -503,61 +517,65 @@ if (doesExistAndIsReadable == false) { STDAIR_LOG_ERROR ("The fare schedule file " << _filename - << " does not exist or can not be read."); + << " does not exist or can not be read."); throw FareInputFileNotFoundException ("The fare file " + _filename + " does not exist or can not be read"); } - // Open the file - _startIterator = iterator_t (_filename); + // File to be parsed + const std::string* lFileName = &_filename; + const char *lChar = (*lFileName).c_str(); + std::ifstream fileToBeParsed(lChar, std::ios_base::in); // Check the filename exists and can be open - if (!_startIterator) { + if (fileToBeParsed == false) { STDAIR_LOG_ERROR ("The fare file " << _filename << " can not be open." << std::endl); throw FareInputFileNotFoundException ("The file " + _filename + " does not exist or can not be read"); } + + // Create an input iterator + base_iterator_t inputBegin(fileToBeParsed); + typedef boost::spirit::multi_pass<base_iterator_t> iterator_t; - // Create an EOF iterator - _endIterator = _startIterator.make_end(); + // Convert input iterator to an iterator usable by spirit parser + iterator_t _startIterator = boost::spirit::make_default_multi_pass(inputBegin); } // ////////////////////////////////////////////////////////////////////// bool FareRuleFileParser::generateFareRules () { - bool oResult = false; STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); // Initialise the parser (grammar) with the helper/staging structure. - FareParserHelper::FareRuleParser lFPParser (_bomRoot, _fareRule); + typedef FareParserHelper::FareRuleParser<iterator_t> FareRule_T; + FareRule_T lFPParser(_bomRoot, _fareRule); // Launch the parsing of the file and, thanks to the doEndFare // call-back structure, the building of the whole BomRoot BOM - boost::spirit::classic::parse_info<iterator_t> info = - boost::spirit::classic::parse (_startIterator, _endIterator, lFPParser, - boost::spirit::classic::space_p); - - // Retrieves whether or not the parsing was successful - oResult = info.hit; + STDAIR_LOG_DEBUG ("Begin parsing"); + + const bool hasParsingBeenSuccesful = + boost::spirit::qi::phrase_parse(_startIterator, _endIterator, lFPParser, boost::spirit::ascii::space); - const std::string hasBeenFullyReadStr = (info.full == true)?"":"not "; - if (oResult == true) { - STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename - << " succeeded: read " << info.length - << " characters. The input file has " - << hasBeenFullyReadStr - << "been fully read. Stop point: " << info.stop); + STDAIR_LOG_DEBUG ("Finish parsing"); + if (hasParsingBeenSuccesful == false) { + // TODO: decide whether to throw an exceqption + STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename + << " failed"); - } else { - // TODO: decide whether to throw an exception - STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename - << " failed: read " << info.length - << " characters. The input file has " - << hasBeenFullyReadStr - << "been fully read. Stop point: " << info.stop); } - return oResult; + // if (_startIterator != _endIterator) { + // // TODO: decide whether to throw an exception + // STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename + // << " failed"); + // } + // if (hasParsingBeenSuccesful == true && _startIterator == _endIterator) { + // STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename + // << " succeeded ;)"); + // } + return hasParsingBeenSuccesful; } } Modified: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-06 10:01:27 UTC (rev 22) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-29 08:52:23 UTC (rev 23) @@ -6,10 +6,10 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> -// #define BOOST_SPIRIT_DEBUG +//#define BOOST_SPIRIT_DEBUG // StdAir #include <stdair/command/CmdAbstract.hpp> -// AirSched +// Simfqt #include <simfqt/SIMFQT_Types.hpp> #include <simfqt/basic/BasParserTypes.hpp> #include <simfqt/bom/FareRuleStruct.hpp> @@ -40,7 +40,9 @@ /** Actor Constructor. */ storeFareId (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (unsigned int) const; + void operator() (unsigned int, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed origin. */ @@ -48,7 +50,9 @@ /** Actor Constructor. */ storeOrigin (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed destination. */ @@ -56,7 +60,9 @@ /** Actor Constructor. */ storeDestination (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed start of the date range. */ @@ -64,7 +70,9 @@ /** Actor Constructor. */ storeDateRangeStart (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed end of the date range. */ @@ -72,7 +80,9 @@ /** Actor Constructor. */ storeDateRangeEnd (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed start range time. */ @@ -80,7 +90,9 @@ /** Actor Constructor. */ storeStartRangeTime (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t iStr, iterator_t iStrEnd) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed end start range time. */ @@ -88,7 +100,9 @@ /** Actor Constructor. */ storeEndRangeTime (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed customer position. */ @@ -96,7 +110,9 @@ /** Actor Constructor. */ storePOS (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the channel distribution. */ @@ -104,7 +120,9 @@ /** Actor Constructor. */ storeChannel (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed advance purchase days. */ @@ -112,7 +130,9 @@ /** Actor Constructor. */ storeAdvancePurchase (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (unsigned int) const; + void operator() (unsigned int, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed saturday night. */ @@ -120,7 +140,9 @@ /** Actor Constructor. */ storeSaturdayStay (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed change fees. */ @@ -128,7 +150,9 @@ /** Actor Constructor. */ storeChangeFees (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed refundable option */ @@ -136,7 +160,9 @@ /** Actor Constructor. */ storeNonRefundable (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed minimum stay. */ @@ -144,7 +170,9 @@ /** Actor Constructor. */ storeMinimumStay (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (unsigned int) const; + void operator() (unsigned int, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed fare value. */ @@ -152,7 +180,9 @@ /** Actor Constructor. */ storeFare (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (double) const; + void operator() (double, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed airline code. */ @@ -160,7 +190,9 @@ /** Actor Constructor. */ storeAirlineCode (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (std::vector<char>, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Store the parsed class. */ @@ -168,7 +200,9 @@ /** Actor Constructor. */ storeClass (FareRuleStruct&); /** Actor Function (functor). */ - void operator() (char) const; + void operator() (char, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; }; /** Mark the end of the fare-rule parsing. */ @@ -176,7 +210,9 @@ /** Actor Constructor. */ doEndFare (stdair::BomRoot&, FareRuleStruct&); /** Actor Function (functor). */ - void operator() (iterator_t, iterator_t) const; + void operator() (boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type, + boost::spirit::qi::unused_type) const; /** Actor Specific Context. */ stdair::BomRoot& _bomRoot; }; @@ -255,27 +291,20 @@ */ /** Grammar for the Fare-Rule parser. */ + /*template <typename ITERATOR> struct FareRuleParser : - public boost::spirit::classic::grammar<FareRuleParser> { + public boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> { FareRuleParser (stdair::BomRoot&, FareRuleStruct&); - template <typename ScannerT> - struct definition { - definition (FareRuleParser const& self); + boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> start, + comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, date, + time; - // Instantiation of rules - boost::spirit::classic::rule<ScannerT> fare_rule_list, comments, - fare_rule, fare_id, fare_key, segment, fare_rule_end, date, time; - - /** Entry point of the parser. */ - boost::spirit::classic::rule<ScannerT> const& start() const; - }; - // Parser Context stdair::BomRoot& _bomRoot; FareRuleStruct& _fareRule; - }; + };*/ } /** Short Description @@ -316,7 +345,7 @@ /** End iterator for the parser. */ iterator_t _endIterator; - + /** stdair::BomRoot. */ stdair::BomRoot& _bomRoot; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qua...@us...> - 2010-11-29 15:42:59
|
Revision: 24 http://simfqt.svn.sourceforge.net/simfqt/?rev=24&view=rev Author: quannaus Date: 2010-11-29 15:42:53 +0000 (Mon, 29 Nov 2010) Log Message: ----------- [dev] Fixed a bug in the itertor. Modified Paths: -------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp trunk/simfqt/simfqt/batches/simfqt.cpp trunk/simfqt/simfqt/command/FareParserHelper.cpp trunk/simfqt/simfqt/command/FareParserHelper.hpp Modified: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-29 08:52:23 UTC (rev 23) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-29 15:42:53 UTC (rev 24) @@ -33,13 +33,13 @@ typedef boost::spirit::qi::int_parser<unsigned int, 10, 1, 1> int1_p_t; /** 2-digit-integer parser */ - typedef boost::spirit::qi::uint_parser<unsigned int, 10, 2, 2> uint2_p_t; + typedef boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p_t; /** 4-digit-integer parser */ - typedef boost::spirit::qi::uint_parser<unsigned int, 10, 4, 4> uint4_p_t; + typedef boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p_t; /** Up-to-4-digit-integer parser */ - typedef boost::spirit::qi::uint_parser<unsigned int, 10, 1, 4> uint1_4_p_t; + typedef boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p_t; } #endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/batches/simfqt.cpp =================================================================== --- trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-29 08:52:23 UTC (rev 23) +++ trunk/simfqt/simfqt/batches/simfqt.cpp 2010-11-29 15:42:53 UTC (rev 24) @@ -27,7 +27,7 @@ const std::string K_SIMFQT_DEFAULT_LOG_FILENAME ("simfqt.log"); /** Default name and location for the (CSV) input file. */ -const std::string K_SIMFQT_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare02.csv"); +const std::string K_SIMFQT_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare01.csv"); /** Default query string. */ const std::string K_SIMFQT_DEFAULT_QUERY_STRING ("my good old query"); Modified: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-29 08:52:23 UTC (rev 23) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-29 15:42:53 UTC (rev 24) @@ -36,7 +36,7 @@ void storeFareId::operator() (unsigned int iFareId, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const { - //_fareRule._fareId = iFareId; + _fareRule._fareId = iFareId; STDAIR_LOG_DEBUG ( "Fare Id: " << _fareRule._fareId); @@ -358,7 +358,6 @@ } // ////////////////////////////////////////////////////////////////// - void doEndFare::operator() (boost::spirit::qi::unused_type, boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const { @@ -390,40 +389,24 @@ // ////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////// - template <typename ITERATOR> - struct FareRuleParser : - public boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> { + FareRuleParser::FareRuleParser (stdair::BomRoot& ioBomRoot, + FareRuleStruct& iofareRule) : + FareRuleParser::base_type(start), + _bomRoot(ioBomRoot), + _fareRule(iofareRule) { + + start = *(comments | fare_rule) + ; + + comments = (boost::spirit::qi::lexeme[ (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("/")]) >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) >> boost::spirit::qi::eol ] + | boost::spirit::qi::lexeme[ (boost::spirit::ascii::char_("/") >> boost::spirit::ascii::char_("*") >> +(boost::spirit::ascii::char_ - boost::spirit::ascii::char_("*")) >> boost::spirit::ascii::char_("*") >> boost::spirit::ascii::char_("/")) ]) + ; - FareRuleParser (stdair::BomRoot& ioBomRoot, - FareRuleStruct& iofareRule) : - FareRuleParser::base_type(start), - _bomRoot(ioBomRoot), - _fareRule(iofareRule) { - - STDAIR_LOG_DEBUG ("Begin parsing"); - - start = * (fare_rule) // *(comments | fare_rule) - ; - - comments = (boost::spirit::qi::lexeme[ - (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("/")]) - >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) - >> +(boost::spirit::ascii::char_) - >> boost::spirit::qi::eol ] - | boost::spirit::qi::lexeme[ - (boost::spirit::ascii::char_("/") - >> boost::spirit::ascii::char_("*") - >> +(boost::spirit::ascii::char_ - boost::spirit::ascii::char_("*")) - >> boost::spirit::ascii::char_("*") - >> boost::spirit::ascii::char_("/")) ]) + fare_rule = fare_key + >> +( ';' >> segment ) + >> fare_rule_end[doEndFare(_bomRoot, _fareRule)] ; - fare_rule =// fare_key - //>> +( ';' >> segment ) - //>> - fare_rule_end[doEndFare(_bomRoot, _fareRule)] - ; - fare_rule_end = boost::spirit::ascii::char_(";") ; @@ -448,9 +431,7 @@ >> ';' >> boost::spirit::qi::double_[storeFare(_fareRule)] ; - fare_id = boost::spirit::qi::lexeme[ - uint1_4_p[storeFareId(_fareRule)] ] - ; + fare_id = uint1_4_p[storeFareId(_fareRule)]; date = boost::spirit::qi::lexeme[ uint4_p[boost::phoenix::ref(_fareRule._itYear) = boost::spirit::qi::labels::_1] @@ -483,16 +464,7 @@ BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); BOOST_SPIRIT_DEBUG_NODE (date); BOOST_SPIRIT_DEBUG_NODE (time); - } - - boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> - start, comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, - date, time; - - // Parser Context - stdair::BomRoot& _bomRoot; - FareRuleStruct& _fareRule; - }; + } } ///////////////////////////////////////////////////////////////////////// @@ -521,7 +493,15 @@ throw FareInputFileNotFoundException ("The fare file " + _filename + " does not exist or can not be read"); } + } + // ////////////////////////////////////////////////////////////////////// + bool FareRuleFileParser::generateFareRules () { + + STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); + + + // File to be parsed const std::string* lFileName = &_filename; const char *lChar = (*lFileName).c_str(); @@ -536,45 +516,37 @@ } // Create an input iterator - base_iterator_t inputBegin(fileToBeParsed); - typedef boost::spirit::multi_pass<base_iterator_t> iterator_t; - - // Convert input iterator to an iterator usable by spirit parser - iterator_t _startIterator = boost::spirit::make_default_multi_pass(inputBegin); - } + base_iterator_t inputBegin (fileToBeParsed); - // ////////////////////////////////////////////////////////////////////// - bool FareRuleFileParser::generateFareRules () { - - STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); + // Convert input iterator to an iterator usable by spirit parser + iterator_t start = boost::spirit::make_default_multi_pass (inputBegin); + iterator_t end; // Initialise the parser (grammar) with the helper/staging structure. - typedef FareParserHelper::FareRuleParser<iterator_t> FareRule_T; - FareRule_T lFPParser(_bomRoot, _fareRule); + FareParserHelper::FareRuleParser lFPParser(_bomRoot, _fareRule); // Launch the parsing of the file and, thanks to the doEndFare // call-back structure, the building of the whole BomRoot BOM - STDAIR_LOG_DEBUG ("Begin parsing"); - + STDAIR_LOG_DEBUG ("Begin parsing") ; const bool hasParsingBeenSuccesful = - boost::spirit::qi::phrase_parse(_startIterator, _endIterator, lFPParser, boost::spirit::ascii::space); + boost::spirit::qi::phrase_parse(start, end, lFPParser, boost::spirit::ascii::space); + STDAIR_LOG_DEBUG ("End parsing") ; - STDAIR_LOG_DEBUG ("Finish parsing"); if (hasParsingBeenSuccesful == false) { // TODO: decide whether to throw an exceqption STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename << " failed"); } - // if (_startIterator != _endIterator) { - // // TODO: decide whether to throw an exception - // STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename - // << " failed"); - // } - // if (hasParsingBeenSuccesful == true && _startIterator == _endIterator) { - // STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename - // << " succeeded ;)"); - // } + if (start != end) { + // TODO: decide whether to throw an exception + STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename + << " failed"); + } + if (hasParsingBeenSuccesful == true && start == end) { + STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename + << " succeeded ;)"); + } return hasParsingBeenSuccesful; } Modified: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-29 08:52:23 UTC (rev 23) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-29 15:42:53 UTC (rev 24) @@ -291,20 +291,20 @@ */ /** Grammar for the Fare-Rule parser. */ - /*template <typename ITERATOR> struct FareRuleParser : - public boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> { + public boost::spirit::qi::grammar<iterator_t, boost::spirit::ascii::space_type> { FareRuleParser (stdair::BomRoot&, FareRuleStruct&); - boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> start, - comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, date, - time; - + // Instantiation of rules + boost::spirit::qi::rule<iterator_t, boost::spirit::ascii::space_type> + start, comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, + date, time; + // Parser Context stdair::BomRoot& _bomRoot; FareRuleStruct& _fareRule; - };*/ + }; } /** Short Description @@ -340,12 +340,6 @@ /** File-name of the CSV-formatted schedule input file. */ stdair::Filename_T _filename; - /** Start iterator for the parser. */ - iterator_t _startIterator; - - /** End iterator for the parser. */ - iterator_t _endIterator; - /** stdair::BomRoot. */ stdair::BomRoot& _bomRoot; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <gsa...@us...> - 2010-12-01 10:35:00
|
Revision: 26 http://simfqt.svn.sourceforge.net/simfqt/?rev=26&view=rev Author: gsabatier Date: 2010-12-01 10:34:54 +0000 (Wed, 01 Dec 2010) Log Message: ----------- [Simfqt] A few improvements with spirit v2 parser Modified Paths: -------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp trunk/simfqt/simfqt/bom/FareRuleStruct.cpp trunk/simfqt/simfqt/command/FareParser.cpp trunk/simfqt/simfqt/command/FareParserHelper.cpp trunk/simfqt/simfqt/command/FareParserHelper.hpp Modified: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-12-01 10:34:54 UTC (rev 26) @@ -4,6 +4,8 @@ // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// STL +#include <string> // Boost Spirit (Parsing) #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> @@ -40,6 +42,7 @@ /** Up-to-4-digit-integer parser */ typedef boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p_t; +; } #endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.cpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-12-01 10:34:54 UTC (rev 26) @@ -24,7 +24,7 @@ _changeFees("T"), _nonRefundable("T"), _minimumStay(0), _fare(0), _airlineCode(""), _classCode("") { - STDAIR_LOG_DEBUG ("fare rule struct."); + } // //////////////////////////////////////////////////////////////////// Modified: trunk/simfqt/simfqt/command/FareParser.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParser.cpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/command/FareParser.cpp 2010-12-01 10:34:54 UTC (rev 26) @@ -23,7 +23,7 @@ // Parse the CSV-formatted fare input file generate the // corresponding fare rules and fulfill the WorldSchedule. lFareRuleFileParser.generateFareRules (); - STDAIR_LOG_DEBUG ("Finish!"); + } } Modified: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-12-01 10:34:54 UTC (rev 26) @@ -163,11 +163,11 @@ boost::spirit::qi::unused_type, boost::spirit::qi::unused_type) const { stdair::ChannelLabel_T lChannel (iChar.begin(), iChar.end()); - _fareRule._channel = lChannel; if (lChannel != "IN" && lChannel != "IF" && lChannel != "DN" && lChannel != "DF") { STDAIR_LOG_DEBUG ("Invalid channel " << lChannel); } + _fareRule._channel = lChannel; STDAIR_LOG_DEBUG ("Channel: " << _fareRule._channel); } @@ -345,7 +345,7 @@ std::ostringstream ostrr; ostrr << _fareRule._classCode << classCodeStr; _fareRule._classCode = ostrr.str(); - STDAIR_LOG_DEBUG ("Class Code: " << lClassCode << std::endl); + STDAIR_LOG_DEBUG ("Class Code: " << lClassCode); } @@ -394,79 +394,141 @@ FareRuleParser::base_type(start), _bomRoot(ioBomRoot), _fareRule(iofareRule) { - + start = *(comments | fare_rule) ; + + comments = (boost::spirit::qi::lexeme[ + boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_('/')] + >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) + >> boost::spirit::qi::eol + ] + | boost::spirit::qi::lexeme[ + boost::spirit::ascii::char_('/') >> + boost::spirit::ascii::char_('*') >> + +(boost::spirit::ascii::char_ - boost::spirit::ascii::char_('*')) >> + boost::spirit::ascii::char_('*') >> boost::spirit::ascii::char_('/') + ]) + ; + + fare_rule = fare_key + >> +( ';' >> segment ) + >> fare_rule_end[doEndFare(_bomRoot, _fareRule)] + ; + + fare_rule_end = boost::spirit::ascii::char_(';') + ; + + fare_key = fare_id + >> ';' >> origin >> ';' >> destination + >> ';' >> dateRangeStart >> ';' >> dateRangeEnd + >> ';' >> timeRangeStart >> ';' >> timeRangeEnd + >> ';' >> position + >> ';' >> channel + >> ';' >> advancePurchase + >> ';' >> saturdayStay + >> ';' >> changeFees + >> ';' >> nonRefundable + >> ';' >> minimumStay + >> ';' >> fare + ; + + fare_id = uint1_4_p[storeFareId(_fareRule)] + ; + + origin = boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")][storeOrigin(_fareRule)] + ; - comments = (boost::spirit::qi::lexeme[ (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("/")]) >> +(boost::spirit::ascii::char_ - boost::spirit::qi::eol) >> boost::spirit::qi::eol ] - | boost::spirit::qi::lexeme[ (boost::spirit::ascii::char_("/") >> boost::spirit::ascii::char_("*") >> +(boost::spirit::ascii::char_ - boost::spirit::ascii::char_("*")) >> boost::spirit::ascii::char_("*") >> boost::spirit::ascii::char_("/")) ]) - ; + destination = boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")][storeDestination(_fareRule)] + ; + + dateRangeStart = date[storeDateRangeStart(_fareRule)] + ; - fare_rule = fare_key - >> +( ';' >> segment ) - >> fare_rule_end[doEndFare(_bomRoot, _fareRule)] - ; + dateRangeEnd = date[storeDateRangeEnd(_fareRule)] + ; + + date = boost::spirit::qi::lexeme[ + uint4_p[boost::phoenix::ref(_fareRule._itYear) = boost::spirit::qi::labels::_1] + >> '-' + >> uint2_p[boost::phoenix::ref(_fareRule._itMonth) = boost::spirit::qi::labels::_1] + >> '-' + >> uint2_p[boost::phoenix::ref(_fareRule._itDay) = boost::spirit::qi::labels::_1] + ] + ; - fare_rule_end = boost::spirit::ascii::char_(";") - ; + timeRangeStart = time[storeStartRangeTime(_fareRule)] + ; + + timeRangeEnd = time[storeEndRangeTime(_fareRule)] + ; - fare_key = fare_id - >> ';' >> boost::spirit::qi::lexeme[ - (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storeOrigin(_fareRule)] ] - >> ';' >> boost::spirit::qi::lexeme[ - (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storeDestination(_fareRule)] ] - >> ';' >> date[storeDateRangeStart(_fareRule)] - >> ';' >> date[storeDateRangeEnd(_fareRule)] - >> ';' >> time[storeStartRangeTime(_fareRule)] - >> ';' >> time[storeEndRangeTime(_fareRule)] - >> ';' >> boost::spirit::qi::lexeme[ - (boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")])[storePOS(_fareRule)] ] - >> ';' >> boost::spirit::qi::lexeme[ - (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")])[storeChannel(_fareRule)] ] - >> ';' >> (uint1_4_p)[storeAdvancePurchase(_fareRule)] - >> ';' >> boost::spirit::ascii::char_("A-Z")[storeSaturdayStay(_fareRule)] - >> ';' >> boost::spirit::ascii::char_("A-Z")[storeChangeFees(_fareRule)] - >> ';' >> boost::spirit::ascii::char_("A-Z")[storeNonRefundable(_fareRule)] - >> ';' >> uint1_4_p[storeMinimumStay(_fareRule)] - >> ';' >> boost::spirit::qi::double_[storeFare(_fareRule)] - ; + time = boost::spirit::qi::lexeme[ + uint2_p[boost::phoenix::ref(_fareRule._itHours) = boost::spirit::qi::labels::_1] + >> ':' + >> uint2_p[boost::phoenix::ref(_fareRule._itMinutes) = boost::spirit::qi::labels::_1] + >> !(':' >> (uint2_p)[boost::phoenix::ref(_fareRule._itSeconds) = boost::spirit::qi::labels::_1]) + ] + ; - fare_id = uint1_4_p[storeFareId(_fareRule)]; - - date = boost::spirit::qi::lexeme[ - uint4_p[boost::phoenix::ref(_fareRule._itYear) = boost::spirit::qi::labels::_1] - >> '-' - >> uint2_p[boost::phoenix::ref(_fareRule._itMonth) =boost::spirit::qi::labels::_1] - >> '-' - >> uint2_p[boost::phoenix::ref(_fareRule._itDay) = boost::spirit::qi::labels::_1] ] - ; - - time = boost::spirit::qi::lexeme[ - uint2_p[boost::phoenix::ref(_fareRule._itHours) = boost::spirit::qi::labels::_1] - >> ':' - >> uint2_p[boost::phoenix::ref(_fareRule._itMinutes) = boost::spirit::qi::labels::_1] - >> !(':' >> (uint2_p)[boost::phoenix::ref(_fareRule._itSeconds) = boost::spirit::qi::labels::_1]) ] - ; + position = boost::spirit::qi::repeat(3)[boost::spirit::ascii::char_("A-Z")][storePOS(_fareRule)] + ; + - segment = boost::spirit::qi::lexeme[ - (boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")])[storeAirlineCode(_fareRule)] ] - >> ';' - >> boost::spirit::ascii::char_("A-Z")[storeClass(_fareRule)] - ; + channel = boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")][storeChannel(_fareRule)] + ; + + advancePurchase = uint1_4_p[storeAdvancePurchase(_fareRule)] + ; - //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); - BOOST_SPIRIT_DEBUG_NODE (start); - BOOST_SPIRIT_DEBUG_NODE (comments); - BOOST_SPIRIT_DEBUG_NODE (fare_rule); - BOOST_SPIRIT_DEBUG_NODE (fare_id); - BOOST_SPIRIT_DEBUG_NODE (fare_key); - BOOST_SPIRIT_DEBUG_NODE (segment); - BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); - BOOST_SPIRIT_DEBUG_NODE (date); - BOOST_SPIRIT_DEBUG_NODE (time); + saturdayStay = boost::spirit::ascii::char_("A-Z")[storeSaturdayStay(_fareRule)] + ; + + changeFees = boost::spirit::ascii::char_("A-Z")[storeChangeFees(_fareRule)] + ; + + nonRefundable = boost::spirit::ascii::char_("A-Z")[storeNonRefundable(_fareRule)] + ; + + minimumStay = uint1_4_p[storeMinimumStay(_fareRule)] + ; + + fare = boost::spirit::qi::double_[storeFare(_fareRule)] + ; + + segment = boost::spirit::qi::repeat(2)[boost::spirit::ascii::char_("A-Z")][storeAirlineCode(_fareRule)] + >> ';' + >> boost::spirit::ascii::char_("A-Z")[storeClass(_fareRule)] + ; + + //BOOST_SPIRIT_DEBUG_NODE (FareRuleParser); + BOOST_SPIRIT_DEBUG_NODE (start); + BOOST_SPIRIT_DEBUG_NODE (comments); + BOOST_SPIRIT_DEBUG_NODE (fare_rule); + BOOST_SPIRIT_DEBUG_NODE (fare_rule_end); + BOOST_SPIRIT_DEBUG_NODE (fare_key); + BOOST_SPIRIT_DEBUG_NODE (fare_id); + BOOST_SPIRIT_DEBUG_NODE (origin); + BOOST_SPIRIT_DEBUG_NODE (destination); + BOOST_SPIRIT_DEBUG_NODE (dateRangeStart); + BOOST_SPIRIT_DEBUG_NODE (dateRangeEnd); + BOOST_SPIRIT_DEBUG_NODE (date); + BOOST_SPIRIT_DEBUG_NODE (timeRangeStart); + BOOST_SPIRIT_DEBUG_NODE (timeRangeEnd); + BOOST_SPIRIT_DEBUG_NODE (time); + BOOST_SPIRIT_DEBUG_NODE (position); + BOOST_SPIRIT_DEBUG_NODE (channel); + BOOST_SPIRIT_DEBUG_NODE (advancePurchase); + BOOST_SPIRIT_DEBUG_NODE (saturdayStay); + BOOST_SPIRIT_DEBUG_NODE (changeFees); + BOOST_SPIRIT_DEBUG_NODE (nonRefundable); + BOOST_SPIRIT_DEBUG_NODE (minimumStay); + BOOST_SPIRIT_DEBUG_NODE (fare); + BOOST_SPIRIT_DEBUG_NODE (segment); } } + ///////////////////////////////////////////////////////////////////////// // // Entry class for the file parser @@ -500,8 +562,6 @@ STDAIR_LOG_DEBUG ("Parsing fare input file: " << _filename); - - // File to be parsed const std::string* lFileName = &_filename; const char *lChar = (*lFileName).c_str(); @@ -527,10 +587,9 @@ // Launch the parsing of the file and, thanks to the doEndFare // call-back structure, the building of the whole BomRoot BOM - STDAIR_LOG_DEBUG ("Begin parsing") ; + const bool hasParsingBeenSuccesful = boost::spirit::qi::phrase_parse(start, end, lFPParser, boost::spirit::ascii::space); - STDAIR_LOG_DEBUG ("End parsing") ; if (hasParsingBeenSuccesful == false) { // TODO: decide whether to throw an exceqption @@ -545,7 +604,7 @@ } if (hasParsingBeenSuccesful == true && start == end) { STDAIR_LOG_DEBUG ("Parsing of fare input file: " << _filename - << " succeeded ;)"); + << " succeeded"); } return hasParsingBeenSuccesful; } Modified: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-11-29 15:50:50 UTC (rev 25) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-12-01 10:34:54 UTC (rev 26) @@ -298,8 +298,10 @@ // Instantiation of rules boost::spirit::qi::rule<iterator_t, boost::spirit::ascii::space_type> - start, comments, fare_rule, fare_id, fare_key, segment, fare_rule_end, - date, time; + start, comments, fare_rule, fare_rule_end, fare_key, fare_id, origin, + destination, dateRangeStart, dateRangeEnd, date, timeRangeStart, + timeRangeEnd, time, position, channel, advancePurchase, saturdayStay, + changeFees, nonRefundable, minimumStay, fare, segment; // Parser Context stdair::BomRoot& _bomRoot; @@ -307,10 +309,7 @@ }; } - /** Short Description - <br> Detailed Description.*/ - ///////////////////////////////////////////////////////////////////////// // // Entry class for the file parser This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qua...@us...> - 2010-12-02 10:44:37
|
Revision: 28 http://simfqt.svn.sourceforge.net/simfqt/?rev=28&view=rev Author: quannaus Date: 2010-12-02 10:44:31 +0000 (Thu, 02 Dec 2010) Log Message: ----------- [dev] Created some specialised types for the date_time parser. These types should be moved to stdair. Modified Paths: -------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp trunk/simfqt/simfqt/batches/simfqt.cpp trunk/simfqt/simfqt/bom/FareRuleStruct.cpp trunk/simfqt/simfqt/bom/FareRuleStruct.hpp trunk/simfqt/simfqt/command/FareParserHelper.cpp Modified: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-12-01 14:54:29 UTC (rev 27) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-12-02 10:44:31 UTC (rev 28) @@ -6,6 +6,7 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> +#include <limits> // Boost Spirit (Parsing) #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> @@ -42,7 +43,48 @@ /** Up-to-4-digit-integer parser */ typedef boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p_t; -; - + + /** Time parser. */ + template <int MIN = 0, int MAX = 0> + struct date_time_element { + unsigned int _value; + + // Constructors. + date_time_element () { } + date_time_element (const date_time_element& t) + : _value (t._value) { } + date_time_element (int i) : _value (i) { } + void check () const { + if (_value < MIN || _value > MAX) { + STDAIR_LOG_ERROR ("The value: " << _value + << " is out of range (" + << MIN << ", " << MAX << ")"); + throw stdair::ParserException (); + } + } + }; + + typedef date_time_element<0, 23> hour_t; + typedef date_time_element<0, 59> minute_t; + typedef date_time_element<0, 59> second_t; + typedef date_time_element<1900, 2100> year_t; + typedef date_time_element<1, 12> month_t; + typedef date_time_element<1, 31> day_t; + typedef boost::spirit::qi::uint_parser<hour_t, 10, 2, 2> hour_p_t; + typedef boost::spirit::qi::uint_parser<minute_t, 10, 2, 2> minute_p_t; + typedef boost::spirit::qi::uint_parser<second_t, 10, 2, 2> second_p_t; + typedef boost::spirit::qi::uint_parser<year_t, 10, 4, 4> year_p_t; + typedef boost::spirit::qi::uint_parser<month_t, 10, 2, 2> month_p_t; + typedef boost::spirit::qi::uint_parser<day_t, 10, 2, 2> day_p_t; + + + template <int MIN, int MAX> + inline date_time_element<MIN, MAX> operator* (const date_time_element<MIN, MAX>& h1, const date_time_element<MIN, MAX>& h2) { + return date_time_element<MIN, MAX> (h1._value * h2._value); + } + template <int MIN, int MAX> + inline date_time_element<MIN, MAX> operator+ (const date_time_element<MIN, MAX>& h1, const date_time_element<MIN, MAX>& h2) { + return date_time_element<MIN, MAX> (h1._value + h2._value); + } } #endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/batches/simfqt.cpp =================================================================== --- trunk/simfqt/simfqt/batches/simfqt.cpp 2010-12-01 14:54:29 UTC (rev 27) +++ trunk/simfqt/simfqt/batches/simfqt.cpp 2010-12-02 10:44:31 UTC (rev 28) @@ -172,38 +172,41 @@ return 0; } + // /////////////// M A I N ///////////////// int main (int argc, char* argv[]) { - - // Query - std::string lQuery; - - // Fare input file name - stdair::Filename_T lFareInputFilename; - - // Output log File - std::string lLogFilename; - - // Call the command-line option parser - const int lOptionParserStatus = - readConfiguration (argc, argv, lQuery, lFareInputFilename, lLogFilename); - - if (lOptionParserStatus == K_SIMFQT_EARLY_RETURN_STATUS) { + try { + // Query + std::string lQuery; + + // Fare input file name + stdair::Filename_T lFareInputFilename; + + // Output log File + std::string lLogFilename; + + // Call the command-line option parser + const int lOptionParserStatus = + readConfiguration (argc, argv, lQuery, lFareInputFilename, lLogFilename); + + if (lOptionParserStatus == K_SIMFQT_EARLY_RETURN_STATUS) { + return 0; + } + + // Set the log parameters + std::ofstream logOutputFile; + // Open and clean the log outputfile + logOutputFile.open (lLogFilename.c_str()); + logOutputFile.clear(); + + // Initialise the Simfqt service object + const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); + SIMFQT::SIMFQT_Service simfqtService (lLogParams, lFareInputFilename); + + // Close the Log outputFile + logOutputFile.close(); + return 0; - } - - // Set the log parameters - std::ofstream logOutputFile; - // Open and clean the log outputfile - logOutputFile.open (lLogFilename.c_str()); - logOutputFile.clear(); - - // Initialise the Simfqt service object - const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile); - SIMFQT::SIMFQT_Service simfqtService (lLogParams, lFareInputFilename); - - // Close the Log outputFile - logOutputFile.close(); - - return 0; + + } CATCH_ALL_EXCEPTIONS } Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.cpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-12-01 14:54:29 UTC (rev 27) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.cpp 2010-12-02 10:44:31 UTC (rev 28) @@ -29,14 +29,16 @@ // //////////////////////////////////////////////////////////////////// stdair::Date_T FareRuleStruct::getDate() const { - return stdair::Date_T (_itYear, _itMonth, _itDay); + _itYear.check(); _itMonth.check(); _itDay.check(); + return stdair::Date_T (_itYear._value, _itMonth._value, _itDay._value); } // //////////////////////////////////////////////////////////////////// stdair::Duration_T FareRuleStruct::getTime() const { - return boost::posix_time::hours (_itHours) - + boost::posix_time::minutes (_itMinutes) - + boost::posix_time::seconds (_itSeconds); + _itHours.check(); _itMinutes.check(); _itSeconds.check(); + return boost::posix_time::hours (_itHours._value) + + boost::posix_time::minutes (_itMinutes._value) + + boost::posix_time::seconds (_itSeconds._value); } Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.hpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.hpp 2010-12-01 14:54:29 UTC (rev 27) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.hpp 2010-12-02 10:44:31 UTC (rev 28) @@ -12,6 +12,7 @@ #include <stdair/basic/StructAbstract.hpp> // SIMFQT #include <simfqt/SIMFQT_Types.hpp> +#include <simfqt/basic/BasParserTypes.hpp> namespace SIMFQT { @@ -33,14 +34,15 @@ // ////////////////// Attributes ///////////////// /** Staging Date. */ - unsigned int _itYear; - unsigned int _itMonth; - unsigned int _itDay; + year_t _itYear; + month_t _itMonth; + day_t _itDay; /** Staging Time. */ - long _itHours; - long _itMinutes; - long _itSeconds; + //long _itHours; + hour_t _itHours; + minute_t _itMinutes; + second_t _itSeconds; unsigned long int _nbOfAirlines; Modified: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-12-01 14:54:29 UTC (rev 27) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-12-02 10:44:31 UTC (rev 28) @@ -387,6 +387,16 @@ /** Up-to-4-digit-integer parser */ uint1_4_p_t uint1_4_p; + + /** Time element parsers. */ + hour_p_t hour_p; + minute_p_t minute_p; + second_p_t second_p; + + /** Date element parsers. */ + year_p_t year_p; + month_p_t month_p; + day_p_t day_p; // ////////////////////////////////////////////////////////////////// // (Boost Spirit) Grammar Definition @@ -434,21 +444,21 @@ dateRangeEnd = date[storeDateRangeEnd(_fareRule)]; date = bsq::lexeme - [uint4_p[boost::phoenix::ref(_fareRule._itYear) = bsq::labels::_1] + [year_p[boost::phoenix::ref(_fareRule._itYear) = bsq::labels::_1] >> '-' - >> uint2_p[boost::phoenix::ref(_fareRule._itMonth) = bsq::labels::_1] + >> month_p[boost::phoenix::ref(_fareRule._itMonth) = bsq::labels::_1] >> '-' - >> uint2_p[boost::phoenix::ref(_fareRule._itDay) = bsq::labels::_1] ]; + >> day_p[boost::phoenix::ref(_fareRule._itDay) = bsq::labels::_1] ]; timeRangeStart = time[storeStartRangeTime(_fareRule)]; timeRangeEnd = time[storeEndRangeTime(_fareRule)]; time = bsq::lexeme - [uint2_p[boost::phoenix::ref(_fareRule._itHours) = bsq::labels::_1] + [hour_p[boost::phoenix::ref(_fareRule._itHours) = bsq::labels::_1] >> ':' - >> uint2_p[boost::phoenix::ref(_fareRule._itMinutes) = bsq::labels::_1] - >> !(':' >> (uint2_p)[boost::phoenix::ref(_fareRule._itSeconds) = bsq::labels::_1]) ]; + >> minute_p[boost::phoenix::ref(_fareRule._itMinutes) = bsq::labels::_1] + >> !(':' >> (second_p)[boost::phoenix::ref(_fareRule._itSeconds) = bsq::labels::_1]) ]; position = bsq::repeat(3)[bsa::char_("A-Z")][storePOS(_fareRule)]; @@ -494,6 +504,10 @@ BOOST_SPIRIT_DEBUG_NODE (minimumStay); BOOST_SPIRIT_DEBUG_NODE (fare); BOOST_SPIRIT_DEBUG_NODE (segment); + + hour_t h1 (2); + hour_t h2 (3); + h1 = h1 * h2; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <qua...@us...> - 2010-12-02 15:46:43
|
Revision: 29 http://simfqt.svn.sourceforge.net/simfqt/?rev=29&view=rev Author: quannaus Date: 2010-12-02 15:46:37 +0000 (Thu, 02 Dec 2010) Log Message: ----------- [dev] Adapted to the new stdair with the change in the exceptions. Modified Paths: -------------- trunk/simfqt/simfqt/basic/sources.mk trunk/simfqt/simfqt/bom/FareRuleStruct.hpp trunk/simfqt/simfqt/command/FareParserHelper.cpp trunk/simfqt/simfqt/command/FareParserHelper.hpp Removed Paths: ------------- trunk/simfqt/simfqt/basic/BasParserTypes.hpp Deleted: trunk/simfqt/simfqt/basic/BasParserTypes.hpp =================================================================== --- trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-12-02 10:44:31 UTC (rev 28) +++ trunk/simfqt/simfqt/basic/BasParserTypes.hpp 2010-12-02 15:46:37 UTC (rev 29) @@ -1,90 +0,0 @@ -#ifndef __SIMFQT_BAS_BASCOMPARSERTYPES_HPP -#define __SIMFQT_BAS_BASCOMPARSERTYPES_HPP - -// ////////////////////////////////////////////////////////////////////// -// Import section -// ////////////////////////////////////////////////////////////////////// -// STL -#include <string> -#include <limits> -// Boost Spirit (Parsing) -#include <boost/spirit/include/qi.hpp> -#include <boost/spirit/include/phoenix_core.hpp> -#include <boost/spirit/include/phoenix_operator.hpp> -#include <boost/spirit/include/support_multi_pass.hpp> - -namespace SIMFQT { - - // /////////////////////////////////////////////////////////////////////// - // - // Definition of Basic Types - // - // /////////////////////////////////////////////////////////////////////// - - // The types of iterator, scanner and rule are then derived from - // the parsing unit. - typedef std::istreambuf_iterator<char> base_iterator_t; - typedef boost::spirit::multi_pass<base_iterator_t> iterator_t; - - - // /////////////////////////////////////////////////////////////////////// - // - // Parser related types - // - // /////////////////////////////////////////////////////////////////////// - /** 1-digit-integer parser */ - typedef boost::spirit::qi::int_parser<unsigned int, 10, 1, 1> int1_p_t; - - /** 2-digit-integer parser */ - typedef boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p_t; - - /** 4-digit-integer parser */ - typedef boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p_t; - - /** Up-to-4-digit-integer parser */ - typedef boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p_t; - - /** Time parser. */ - template <int MIN = 0, int MAX = 0> - struct date_time_element { - unsigned int _value; - - // Constructors. - date_time_element () { } - date_time_element (const date_time_element& t) - : _value (t._value) { } - date_time_element (int i) : _value (i) { } - void check () const { - if (_value < MIN || _value > MAX) { - STDAIR_LOG_ERROR ("The value: " << _value - << " is out of range (" - << MIN << ", " << MAX << ")"); - throw stdair::ParserException (); - } - } - }; - - typedef date_time_element<0, 23> hour_t; - typedef date_time_element<0, 59> minute_t; - typedef date_time_element<0, 59> second_t; - typedef date_time_element<1900, 2100> year_t; - typedef date_time_element<1, 12> month_t; - typedef date_time_element<1, 31> day_t; - typedef boost::spirit::qi::uint_parser<hour_t, 10, 2, 2> hour_p_t; - typedef boost::spirit::qi::uint_parser<minute_t, 10, 2, 2> minute_p_t; - typedef boost::spirit::qi::uint_parser<second_t, 10, 2, 2> second_p_t; - typedef boost::spirit::qi::uint_parser<year_t, 10, 4, 4> year_p_t; - typedef boost::spirit::qi::uint_parser<month_t, 10, 2, 2> month_p_t; - typedef boost::spirit::qi::uint_parser<day_t, 10, 2, 2> day_p_t; - - - template <int MIN, int MAX> - inline date_time_element<MIN, MAX> operator* (const date_time_element<MIN, MAX>& h1, const date_time_element<MIN, MAX>& h2) { - return date_time_element<MIN, MAX> (h1._value * h2._value); - } - template <int MIN, int MAX> - inline date_time_element<MIN, MAX> operator+ (const date_time_element<MIN, MAX>& h1, const date_time_element<MIN, MAX>& h2) { - return date_time_element<MIN, MAX> (h1._value + h2._value); - } -} -#endif // __SIMFQT_BAS_BASCOMPARSERTYPES_HPP Modified: trunk/simfqt/simfqt/basic/sources.mk =================================================================== --- trunk/simfqt/simfqt/basic/sources.mk 2010-12-02 10:44:31 UTC (rev 28) +++ trunk/simfqt/simfqt/basic/sources.mk 2010-12-02 15:46:37 UTC (rev 29) @@ -1,6 +1,5 @@ simfqt_bas_h_sources = \ $(top_srcdir)/simfqt/basic/BasConst_General.hpp \ - $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp \ - $(top_srcdir)/simfqt/basic/BasParserTypes.hpp + $(top_srcdir)/simfqt/basic/BasConst_SIMFQT_Service.hpp simfqt_bas_cc_sources = \ $(top_srcdir)/simfqt/basic/BasConst.cpp Modified: trunk/simfqt/simfqt/bom/FareRuleStruct.hpp =================================================================== --- trunk/simfqt/simfqt/bom/FareRuleStruct.hpp 2010-12-02 10:44:31 UTC (rev 28) +++ trunk/simfqt/simfqt/bom/FareRuleStruct.hpp 2010-12-02 15:46:37 UTC (rev 29) @@ -10,9 +10,9 @@ // STDAIR #include <stdair/STDAIR_Types.hpp> #include <stdair/basic/StructAbstract.hpp> +#include <stdair/basic/BasParserTypes.hpp> // SIMFQT #include <simfqt/SIMFQT_Types.hpp> -#include <simfqt/basic/BasParserTypes.hpp> namespace SIMFQT { @@ -34,15 +34,15 @@ // ////////////////// Attributes ///////////////// /** Staging Date. */ - year_t _itYear; - month_t _itMonth; - day_t _itDay; + stdair::year_t _itYear; + stdair::month_t _itMonth; + stdair::day_t _itDay; /** Staging Time. */ //long _itHours; - hour_t _itHours; - minute_t _itMinutes; - second_t _itSeconds; + stdair::hour_t _itHours; + stdair::minute_t _itMinutes; + stdair::second_t _itSeconds; unsigned long int _nbOfAirlines; Modified: trunk/simfqt/simfqt/command/FareParserHelper.cpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-12-02 10:44:31 UTC (rev 28) +++ trunk/simfqt/simfqt/command/FareParserHelper.cpp 2010-12-02 15:46:37 UTC (rev 29) @@ -377,26 +377,26 @@ namespace bsa = boost::spirit::ascii; /** 1-digit-integer parser */ - int1_p_t int1_p; + stdair::int1_p_t int1_p; /** 2-digit-integer parser */ - uint2_p_t uint2_p; + stdair::uint2_p_t uint2_p; /** 4-digit-integer parser */ - uint4_p_t uint4_p; + stdair::uint4_p_t uint4_p; /** Up-to-4-digit-integer parser */ - uint1_4_p_t uint1_4_p; + stdair::uint1_4_p_t uint1_4_p; /** Time element parsers. */ - hour_p_t hour_p; - minute_p_t minute_p; - second_p_t second_p; + stdair::hour_p_t hour_p; + stdair::minute_p_t minute_p; + stdair::second_p_t second_p; /** Date element parsers. */ - year_p_t year_p; - month_p_t month_p; - day_p_t day_p; + stdair::year_p_t year_p; + stdair::month_p_t month_p; + stdair::day_p_t day_p; // ////////////////////////////////////////////////////////////////// // (Boost Spirit) Grammar Definition @@ -504,12 +504,7 @@ BOOST_SPIRIT_DEBUG_NODE (minimumStay); BOOST_SPIRIT_DEBUG_NODE (fare); BOOST_SPIRIT_DEBUG_NODE (segment); - - hour_t h1 (2); - hour_t h2 (3); - h1 = h1 * h2; } - } ///////////////////////////////////////////////////////////////////////// @@ -559,11 +554,12 @@ } // Create an input iterator - base_iterator_t inputBegin (fileToBeParsed); - + stdair::base_iterator_t inputBegin (fileToBeParsed); + // Convert input iterator to an iterator usable by spirit parser - iterator_t start (boost::spirit::make_default_multi_pass (inputBegin)); - iterator_t end; + stdair::iterator_t + start (boost::spirit::make_default_multi_pass (inputBegin)); + stdair::iterator_t end; // Initialise the parser (grammar) with the helper/staging structure. FareParserHelper::FareRuleParser lFPParser(_bomRoot, _fareRule); @@ -579,7 +575,6 @@ // TODO: decide whether to throw an exceqption STDAIR_LOG_ERROR ("Parsing of fare input file: " << _filename << " failed"); - } if (start != end) { // TODO: decide whether to throw an exception Modified: trunk/simfqt/simfqt/command/FareParserHelper.hpp =================================================================== --- trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-12-02 10:44:31 UTC (rev 28) +++ trunk/simfqt/simfqt/command/FareParserHelper.hpp 2010-12-02 15:46:37 UTC (rev 29) @@ -8,10 +8,10 @@ #include <string> //#define BOOST_SPIRIT_DEBUG // StdAir +#include <stdair/basic/BasParserTypes.hpp> #include <stdair/command/CmdAbstract.hpp> // Simfqt #include <simfqt/SIMFQT_Types.hpp> -#include <simfqt/basic/BasParserTypes.hpp> #include <simfqt/bom/FareRuleStruct.hpp> // Forward declarations @@ -292,12 +292,14 @@ /** Grammar for the Fare-Rule parser. */ struct FareRuleParser : - public boost::spirit::qi::grammar<iterator_t, boost::spirit::ascii::space_type> { + public boost::spirit::qi::grammar<stdair::iterator_t, + boost::spirit::ascii::space_type> { FareRuleParser (stdair::BomRoot&, FareRuleStruct&); // Instantiation of rules - boost::spirit::qi::rule<iterator_t, boost::spirit::ascii::space_type> + boost::spirit::qi::rule<stdair::iterator_t, + boost::spirit::ascii::space_type> start, comments, fare_rule, fare_rule_end, fare_key, fare_id, origin, destination, dateRangeStart, dateRangeEnd, date, timeRangeStart, timeRangeEnd, time, position, channel, advancePurchase, saturdayStay, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |