You can subscribe to this list here.
| 2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(23) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2010 |
Jan
(16) |
Feb
(13) |
Mar
(1) |
Apr
(6) |
May
(4) |
Jun
(3) |
Jul
(33) |
Aug
(3) |
Sep
(16) |
Oct
(7) |
Nov
(20) |
Dec
(2) |
|
From: <den...@us...> - 2010-12-03 21:19:19
|
Revision: 166
http://dsim.svn.sourceforge.net/dsim/?rev=166&view=rev
Author: denis_arnaud
Date: 2010-12-03 21:19:13 +0000 (Fri, 03 Dec 2010)
Log Message:
-----------
[StdAir API] Adapted the code to the new StdAir API.
Modified Paths:
--------------
trunk/dsim/dsim/DSIM_Service.hpp
trunk/dsim/dsim/command/DBManager.hpp
trunk/dsim/dsim/command/Simulator.cpp
trunk/dsim/dsim/service/DSIM_ServiceContext.hpp
Modified: trunk/dsim/dsim/DSIM_Service.hpp
===================================================================
--- trunk/dsim/dsim/DSIM_Service.hpp 2010-12-01 07:44:33 UTC (rev 165)
+++ trunk/dsim/dsim/DSIM_Service.hpp 2010-12-03 21:19:13 UTC (rev 166)
@@ -5,14 +5,14 @@
// Import section
// //////////////////////////////////////////////////////////////////////
// StdAir
-#include <stdair/STDAIR_Types.hpp>
+#include <stdair/stdair_basic_types.hpp>
+#include <stdair/stdair_service_types.hpp>
// Dsim
#include <dsim/DSIM_Types.hpp>
-// Forward declarations.
+// Forward declarations
namespace stdair {
class AirlineFeatureSet;
- class STDAIR_Service;
struct BasLogParams;
struct BasDBParams;
}
Modified: trunk/dsim/dsim/command/DBManager.hpp
===================================================================
--- trunk/dsim/dsim/command/DBManager.hpp 2010-12-01 07:44:33 UTC (rev 165)
+++ trunk/dsim/dsim/command/DBManager.hpp 2010-12-03 21:19:13 UTC (rev 166)
@@ -5,7 +5,8 @@
// Import section
// //////////////////////////////////////////////////////////////////////
// StdAir
-#include <stdair/STDAIR_Types.hpp>
+#include <stdair/stdair_basic_types.hpp>
+#include <stdair/stdair_db.hpp>
// Dsim
#include <dsim/DSIM_Types.hpp>
Modified: trunk/dsim/dsim/command/Simulator.cpp
===================================================================
--- trunk/dsim/dsim/command/Simulator.cpp 2010-12-01 07:44:33 UTC (rev 165)
+++ trunk/dsim/dsim/command/Simulator.cpp 2010-12-03 21:19:13 UTC (rev 166)
@@ -7,7 +7,7 @@
#include <vector>
#include <exception>
// StdAir
-#include <stdair/STDAIR_Types.hpp>
+#include <stdair/stdair_demand_types.hpp>
#include <stdair/bom/EventStruct.hpp>
#include <stdair/bom/EventQueue.hpp>
#include <stdair/bom/BookingRequestStruct.hpp>
Modified: trunk/dsim/dsim/service/DSIM_ServiceContext.hpp
===================================================================
--- trunk/dsim/dsim/service/DSIM_ServiceContext.hpp 2010-12-01 07:44:33 UTC (rev 165)
+++ trunk/dsim/dsim/service/DSIM_ServiceContext.hpp 2010-12-03 21:19:13 UTC (rev 166)
@@ -9,7 +9,7 @@
// Boost
#include <boost/shared_ptr.hpp>
// StdAir
-#include <stdair/STDAIR_Types.hpp>
+#include <stdair/stdair_service_types.hpp>
// Dsim
#include <dsim/DSIM_Types.hpp>
#include <dsim/bom/ConfigurationParameters.hpp>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-12-01 07:44:39
|
Revision: 165
http://dsim.svn.sourceforge.net/dsim/?rev=165&view=rev
Author: denis_arnaud
Date: 2010-12-01 07:44:33 +0000 (Wed, 01 Dec 2010)
Log Message:
-----------
[Test-Boost] Fixed the Boost.Filesystem compilation error for version lower than 1.44.
Modified Paths:
--------------
trunk/dsim/test/boost/filesystem/wide_test.cpp
Modified: trunk/dsim/test/boost/filesystem/wide_test.cpp
===================================================================
--- trunk/dsim/test/boost/filesystem/wide_test.cpp 2010-11-30 21:29:54 UTC (rev 164)
+++ trunk/dsim/test/boost/filesystem/wide_test.cpp 2010-12-01 07:44:33 UTC (rev 165)
@@ -13,9 +13,11 @@
#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
# define BOOST_FILESYSTEM_NO_DEPRECATED
#endif
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
#ifndef BOOST_SYSTEM_NO_DEPRECATED
# define BOOST_SYSTEM_NO_DEPRECATED
-#endif
+#endif // BOOST_SYSTEM_NO_DEPRECATED
+#endif // BOOST_VERSION
#include <boost/filesystem/config.hpp>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-11-30 21:30:01
|
Revision: 164
http://dsim.svn.sourceforge.net/dsim/?rev=164&view=rev
Author: denis_arnaud
Date: 2010-11-30 21:29:54 +0000 (Tue, 30 Nov 2010)
Log Message:
-----------
[Test-Boost] Updated the Boost.Filesystem tests to support Boost-1.44.0.
Modified Paths:
--------------
trunk/dsim/test/boost/filesystem/Makefile.am
trunk/dsim/test/boost/filesystem/lpath.hpp
trunk/dsim/test/boost/filesystem/operations_test.cpp
trunk/dsim/test/boost/filesystem/path_test.cpp
trunk/dsim/test/boost/filesystem/wide_test.cpp
Modified: trunk/dsim/test/boost/filesystem/Makefile.am
===================================================================
--- trunk/dsim/test/boost/filesystem/Makefile.am 2010-11-23 14:03:33 UTC (rev 163)
+++ trunk/dsim/test/boost/filesystem/Makefile.am 2010-11-30 21:29:54 UTC (rev 164)
@@ -39,7 +39,7 @@
path_test_LDFLAGS = $(BOOST_LIBS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB)
#
-wide_test_SOURCES = wide_test.cpp
+wide_test_SOURCES = wide_test.cpp utf8_codecvt_facet.cpp
wide_test_CXXFLAGS = $(BOOST_CFLAGS)
wide_test_LDADD =
wide_test_LDFLAGS = $(BOOST_LIBS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB)
@@ -52,9 +52,8 @@
$(BOOST_LIBS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB)
#
-fstream_test_SOURCES = fstream_test.cpp
+fstream_test_SOURCES = fstream_test.cpp utf8_codecvt_facet.cpp
fstream_test_CXXFLAGS = $(BOOST_CFLAGS)
fstream_test_LDADD =
fstream_test_LDFLAGS = \
$(BOOST_LIBS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB)
-
Modified: trunk/dsim/test/boost/filesystem/lpath.hpp
===================================================================
--- trunk/dsim/test/boost/filesystem/lpath.hpp 2010-11-23 14:03:33 UTC (rev 163)
+++ trunk/dsim/test/boost/filesystem/lpath.hpp 2010-11-30 21:29:54 UTC (rev 164)
@@ -8,11 +8,20 @@
// See library home page at http://www.boost.org/libs/filesystem
+// Boost
+#include <boost/version.hpp> // To check whether which version API is needed
+
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+#include <boost/filesystem/v2/path.hpp>
+#else // BOOST_VERSION
#include <boost/filesystem/path.hpp>
+#endif // BOOST_VERSION
+
#include <cwchar> // for std::mbstate_t
#include <string>
#include <ios> // for std::streamoff
+
namespace std
{
// Note well: this specialization is meant only to support wide_test.cpp.
@@ -93,7 +102,11 @@
namespace boost
{
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+ namespace filesystem2
+#else // BOOST_VERSION
namespace filesystem
+#endif // BOOST_VERSION
{
template<> struct is_basic_path<user::lpath>
{ static const bool value = true; };
Modified: trunk/dsim/test/boost/filesystem/operations_test.cpp
===================================================================
--- trunk/dsim/test/boost/filesystem/operations_test.cpp 2010-11-23 14:03:33 UTC (rev 163)
+++ trunk/dsim/test/boost/filesystem/operations_test.cpp 2010-11-30 21:29:54 UTC (rev 164)
@@ -10,10 +10,14 @@
#include <cstring> // for strncmp, etc.
#include <ctime>
#include <cstdlib> // for system()
+
// Boost
+#include <boost/version.hpp> // To check whether which version API is needed
#include <boost/config/warning_disable.hpp>
+
// See deprecated_test for tests of deprecated features
#define BOOST_FILESYSTEM_NO_DEPRECATED
+
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/cerrno.hpp>
@@ -68,7 +72,11 @@
std::ofstream f( ph.file_string().c_str() );
if ( !f )
throw fs::filesystem_error( "operations_test create_file",
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+ ph, error_code(errno, system_category()) );
+#else // BOOST_VERSION
ph, error_code(errno, system_category) );
+#endif // BOOST_VERSION
if ( !contents.empty() ) f << contents;
}
@@ -77,7 +85,11 @@
std::ifstream f( ph.file_string().c_str() );
if ( !f )
throw fs::filesystem_error( "operations_test verify_file",
- ph, error_code(errno, system_category) );
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+ ph, error_code(errno, system_category()) );
+#else // BOOST_VERSION
+ ph, error_code(errno, system_category) );
+#endif // BOOST_VERSION
std::string contents;
f >> contents;
if ( contents != expected )
Modified: trunk/dsim/test/boost/filesystem/path_test.cpp
===================================================================
--- trunk/dsim/test/boost/filesystem/path_test.cpp 2010-11-23 14:03:33 UTC (rev 163)
+++ trunk/dsim/test/boost/filesystem/path_test.cpp 2010-11-30 21:29:54 UTC (rev 164)
@@ -18,6 +18,7 @@
#include <cstring>
#include <cassert>
// Boost
+#include <boost/version.hpp> // To check whether which version API is needed
#include <boost/filesystem/operations.hpp>
#include <boost/utility.hpp>
@@ -77,7 +78,13 @@
void exception_tests()
{
const std::string str_1("string-1");
+
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+ boost::system::error_code ec( 12345, boost::system::system_category());
+#else // BOOST_VERSION
boost::system::error_code ec( 12345, boost::system::system_category);
+#endif // BOOST_VERSION
+
try { throw fs::filesystem_error( str_1, ec ); }
catch ( const fs::filesystem_error & ex )
{
Modified: trunk/dsim/test/boost/filesystem/wide_test.cpp
===================================================================
--- trunk/dsim/test/boost/filesystem/wide_test.cpp 2010-11-23 14:03:33 UTC (rev 163)
+++ trunk/dsim/test/boost/filesystem/wide_test.cpp 2010-11-30 21:29:54 UTC (rev 164)
@@ -4,31 +4,51 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See library home page at http://www.boost.org/libs/filesystem
-// STL
-#include <iostream>
-#include <iomanip>
-#include <ios>
-#include <string>
-#include <cerrno>
+
// Boost
+#include <boost/version.hpp> // To check whether which version API is needed
#include <boost/config/warning_disable.hpp>
+
// See deprecated_test for tests of deprecated features
-#define BOOST_FILESYSTEM_NO_DEPRECATED
+#ifndef BOOST_FILESYSTEM_NO_DEPRECATED
+# define BOOST_FILESYSTEM_NO_DEPRECATED
+#endif
+#ifndef BOOST_SYSTEM_NO_DEPRECATED
+# define BOOST_SYSTEM_NO_DEPRECATED
+#endif
+
#include <boost/filesystem/config.hpp>
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+# ifdef BOOST_FILESYSTEM2_NARROW_ONLY
+# error This compiler or standard library does not support wide-character strings or paths
+# endif
+#else // BOOST_VERSION
# ifdef BOOST_FILESYSTEM_NARROW_ONLY
# error This compiler or standard library does not support wide-character strings or paths
# endif
+#endif // BOOST_VERSION
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/scoped_array.hpp>
#include <boost/detail/lightweight_test.hpp>
-#include "utf8_codecvt_facet.hpp"
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+# include <boost/filesystem/detail/utf8_codecvt_facet.hpp>
+#else // BOOST_VERSION
+# include "utf8_codecvt_facet.hpp"
+#endif // BOOST_VERSION
namespace fs = boost::filesystem;
+// STL
+#include <iostream>
+#include <iomanip>
+#include <ios>
+#include <string>
+#include <cerrno>
+
#include "lpath.hpp"
namespace {
@@ -47,7 +67,11 @@
if ( !f )
throw fs::basic_filesystem_error<Path>( "wide_test create_file",
ph,
- boost::system::error_code( errno, boost::system::errno_ecat ) );
+#if defined(BOOST_VERSION) && BOOST_VERSION >= 104400
+ boost::system::error_code( errno, boost::system::generic_category() ) );
+#else // BOOST_VERSION
+ boost::system::error_code( errno, boost::system::errno_ecat ) );
+#endif // BOOST_VERSION
if ( !contents.empty() ) f << contents;
}
@@ -105,8 +129,8 @@
const wchar_t * from_next;
char * to_next;
if ( convertor.out(
- state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
- work.get()+work_size, to_next ) != std::codecvt_base::ok )
+ state, src.c_str(), src.c_str()+src.size(), from_next, work.get(),
+ work.get()+work_size, to_next ) != std::codecvt_base::ok )
boost::throw_exception( std::runtime_error("to_external conversion error") );
*to_next = '\0';
return std::string( work.get() );
@@ -114,7 +138,7 @@
} // unnamed namespace
-// main ------------------------------------------------------------------------------//
+// main --------------------------------------------------------------------//
int main( int argc, char * /*argv*/[] )
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-23 14:03:40
|
Revision: 163
http://dsim.svn.sourceforge.net/dsim/?rev=163&view=rev
Author: gsabatier
Date: 2010-11-23 14:03:33 +0000 (Tue, 23 Nov 2010)
Log Message:
-----------
[test/Boost] Removed useless #include directives for spirit v2 parser (part 2)
Modified Paths:
--------------
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-23 13:36:59 UTC (rev 162)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-23 14:03:33 UTC (rev 163)
@@ -1,11 +1,6 @@
// STL
-#include <istream>
-#include <sstream>
-#include <iostream>
#include <fstream>
#include <set>
-#include <vector>
-#include <algorithm>
#include <string>
// Boost (Extended STL)
#include <boost/date_time/posix_time/posix_time.hpp>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-23 13:37:05
|
Revision: 162
http://dsim.svn.sourceforge.net/dsim/?rev=162&view=rev
Author: gsabatier
Date: 2010-11-23 13:36:59 +0000 (Tue, 23 Nov 2010)
Log Message:
-----------
[test/Boost] Removed useless #include directives for spirit v2 parser
Modified Paths:
--------------
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-22 17:07:37 UTC (rev 161)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-23 13:36:59 UTC (rev 162)
@@ -14,13 +14,7 @@
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
-#include <boost/spirit/include/qi_core.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include <boost/fusion/include/io.hpp>
-#include <boost/spirit/include/classic_position_iterator.hpp>
-#include <boost/lambda/lambda.hpp>
// ////////////////////////////////////////////////////////////////////////////
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-22 17:07:43
|
Revision: 161
http://dsim.svn.sourceforge.net/dsim/?rev=161&view=rev
Author: gsabatier
Date: 2010-11-22 17:07:37 +0000 (Mon, 22 Nov 2010)
Log Message:
-----------
[test/Boost] Improved a few things for the spirit v2 parser (namespace alias, ...)
Modified Paths:
--------------
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-19 10:25:19 UTC (rev 160)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-22 17:07:37 UTC (rev 161)
@@ -23,8 +23,15 @@
#include <boost/lambda/lambda.hpp>
+// ////////////////////////////////////////////////////////////////////////////
+//
+// Namespace aliases and type definitions
+//
+///////////////////////////////////////////////////////////////////////////////
+namespace bp = boost::phoenix;
+namespace bsa = boost::spirit::ascii;
+namespace bsq = boost::spirit::qi;
-typedef std::string::iterator iterator_t;
/** LegCabin-Details. */
struct Cabin_T {
@@ -311,14 +318,13 @@
///////////////////////////////////////////////////////////////////////////////
/** Store the parsed airline code. */
-template <typename FLIGHT_PERIOD>
struct store_airline_code {
- store_airline_code (FLIGHT_PERIOD& ioFlightPeriod)
+ store_airline_code (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lAirlineCode (iChar.begin(), iChar.end());
_flightPeriod._airlineCode = lAirlineCode;
// std::cout << "Airline code: " << lAirlineCode << std::endl;
@@ -327,34 +333,32 @@
_flightPeriod._legList.clear();
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the parsed flight number. */
-template <typename FLIGHT_PERIOD>
struct store_flight_number {
- store_flight_number (FLIGHT_PERIOD& ioFlightPeriod)
+ store_flight_number (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (unsigned int iNumber,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._flightNumber = iNumber;
//std::cout << "Flight number: " << iNumber << std::endl;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the start of the date range. */
-template <typename FLIGHT_PERIOD>
struct store_date_range_start {
- store_date_range_start (FLIGHT_PERIOD& ioFlightPeriod)
+ store_date_range_start (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ void operator() (bsq::unused_type,
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._dateRangeStart = _flightPeriod.getDate();
//std::cout << "Date Range Start: "
// << _flightPeriod._dateRangeStart << std::endl;
@@ -363,18 +367,17 @@
_flightPeriod._itSeconds = 0;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the end of the date range. */
-template <typename FLIGHT_PERIOD>
struct store_date_range_end {
- store_date_range_end (FLIGHT_PERIOD& ioFlightPeriod)
+ store_date_range_end (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ void operator() (bsq::unused_type,
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._dateRangeEnd = _flightPeriod.getDate();
//std::cout << "Date Range End: "
// << _flightPeriod._dateRangeEnd << std::endl;
@@ -387,31 +390,29 @@
};
/** Store the DOW (day of the Week). */
-template <typename FLIGHT_PERIOD>
struct store_dow {
- store_dow (FLIGHT_PERIOD& ioFlightPeriod)
+ store_dow (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lDow (iChar.begin(), iChar.end());
_flightPeriod._dow = lDow;
//std::cout << "DOW: " << lDow << std::endl;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the parsed board point. */
-template <typename FLIGHT_PERIOD>
struct store_board_point {
- store_board_point (FLIGHT_PERIOD& ioFlightPeriod)
+ store_board_point (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lBoardPoint (iChar.begin(), iChar.end());
//std::cout << "Board point: " << lBoardPoint << std::endl;
@@ -432,18 +433,17 @@
_flightPeriod.addAirport (lBoardPoint);
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the parsed off point. */
-template <typename FLIGHT_PERIOD>
struct store_off_point {
- store_off_point (FLIGHT_PERIOD& ioFlightPeriod)
+ store_off_point (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lOffPoint (iChar.begin(), iChar.end());
_flightPeriod._itLeg._offPoint = lOffPoint;
//std::cout << "Off point: " << lOffPoint << std::endl;
@@ -452,18 +452,17 @@
_flightPeriod.addAirport (lOffPoint);
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the board time. */
-template <typename FLIGHT_PERIOD>
struct store_board_time {
- store_board_time (FLIGHT_PERIOD& ioFlightPeriod)
+ store_board_time (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ void operator() (bsq::unused_type,
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._itLeg._boardTime = _flightPeriod.getTime();
//std::cout << "Board time: "
@@ -476,18 +475,17 @@
_flightPeriod._dateOffSet = 0;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the off time. */
-template <typename FLIGHT_PERIOD>
struct store_off_time {
- store_off_time (FLIGHT_PERIOD& ioFlightPeriod)
+ store_off_time (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ void operator() (bsq::unused_type,
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._itLeg._offTime = _flightPeriod.getTime();
//std::cout << "Off time: "
@@ -502,18 +500,17 @@
_flightPeriod._itLeg._boardDateOffSet = lDateOffSet;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the elapsed time. */
-template <typename FLIGHT_PERIOD>
struct store_elapsed_time {
- store_elapsed_time (FLIGHT_PERIOD& ioFlightPeriod)
+ store_elapsed_time (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ void operator() (bsq::unused_type,
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._itLeg._elapsed = _flightPeriod.getTime();
@@ -529,34 +526,32 @@
_flightPeriod._itLeg._offDateOffSet = lDateOffSet;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the parsed cabin code. */
-template <typename FLIGHT_PERIOD>
struct store_cabin_code {
- store_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
+ store_cabin_code (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (char iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._itCabin._cabinCode = iChar;
//std::cout << "Cabin code: " << _flightPeriod._itCabin._cabinCode << std::endl;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the parsed capacity. */
-template <typename FLIGHT_PERIOD>
struct store_capacity {
- store_capacity (FLIGHT_PERIOD& ioFlightPeriod)
+ store_capacity (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
void operator() (double iReal,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._itCabin._capacity = iReal;
//std::cout << "Capacity: " << iReal << std::endl;
@@ -567,19 +562,18 @@
_flightPeriod._itLeg._cabinList.push_back (_flightPeriod._itCabin);
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store whether or not all the segments are the same. */
-template <typename FLIGHT_PERIOD>
struct store_segment_specificity {
- store_segment_specificity (FLIGHT_PERIOD& ioFlightPeriod)
+ store_segment_specificity (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {
}
void operator() (char iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
if (iChar == '0') {
_flightPeriod._areSegmentDefinitionsSpecific = false;
} else {
@@ -598,72 +592,68 @@
_flightPeriod.buildSegments();
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the board point of the segment. */
-template <typename FLIGHT_PERIOD>
struct store_segment_board_point {
- store_segment_board_point (FLIGHT_PERIOD& ioFlightPeriod)
+ store_segment_board_point (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {
}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lBoardPoint (iChar.begin(), iChar.end());
_flightPeriod._itSegment._boardPoint = lBoardPoint;
//std::cout << "Board point: " << lBoardPoint << std::endl;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the off point of the segment. */
-template <typename FLIGHT_PERIOD>
struct store_segment_off_point {
- store_segment_off_point (FLIGHT_PERIOD& ioFlightPeriod)
+ store_segment_off_point (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {
}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lOffPoint (iChar.begin(), iChar.end());
_flightPeriod._itSegment._offPoint = lOffPoint;
//std::cout << "Off point: " << lOffPoint << std::endl;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the cabin code of the segment. */
-template <typename FLIGHT_PERIOD>
struct store_segment_cabin_code {
- store_segment_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
+ store_segment_cabin_code (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {
}
void operator() (char iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
_flightPeriod._itSegmentCabin._cabinCode = iChar;
//std::cout << "Cabin code: " << iChar << std::endl;
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Store the classes of the segment-cabin. */
-template <typename FLIGHT_PERIOD>
struct store_classes {
- store_classes (FLIGHT_PERIOD& ioFlightPeriod)
+ store_classes (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {
}
void operator() (std::vector<char> iChar,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ bsq::unused_type,
+ bsq::unused_type) const {
std::string lClasses (iChar.begin(), iChar.end());
_flightPeriod._itSegmentCabin._classes = lClasses;
//std::cout << "Classes: " << lClasses << std::endl;
@@ -681,18 +671,17 @@
}
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
/** Mark the end of the flight-period parsing. */
-template <typename FLIGHT_PERIOD>
struct do_end_flight {
- do_end_flight (FLIGHT_PERIOD& ioFlightPeriod)
+ do_end_flight (FlightPeriod_T& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type,
- boost::spirit::qi::unused_type) const {
+ void operator() (bsq::unused_type,
+ bsq::unused_type,
+ bsq::unused_type) const {
//std::cout << "End of Flight-Period " << std::endl;
assert (_flightPeriod._legAlreadyDefined == true);
@@ -707,23 +696,24 @@
}
- FLIGHT_PERIOD& _flightPeriod;
+ FlightPeriod_T& _flightPeriod;
};
// /////////// Utilities /////////////
/** 1-digit-integer parser */
-boost::spirit::qi::int_parser<unsigned int, 10, 1, 1> int1_p;
+bsq::int_parser<unsigned int, 10, 1, 1> int1_p;
/** 2-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p;
+bsq::uint_parser<int, 10, 2, 2> uint2_p;
/** 4-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p;
+bsq::uint_parser<int, 10, 4, 4> uint4_p;
/** Up-to-4-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p;
+bsq::uint_parser<int, 10, 1, 4> uint1_4_p;
+
///////////////////////////////////////////////////////////////////////////////
//
// Our flight-period grammar
@@ -774,116 +764,87 @@
////////////////////////////////////////////////////////////////////////////
// Parser
////////////////////////////////////////////////////////////////////////////
-template <typename ITERATOR, typename FLIGHT_PERIOD>
+template <typename ITERATOR>
struct FlightPeriodParser :
- boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> {
+ bsq::grammar<ITERATOR, bsa::space_type> {
- typedef store_airline_code<FLIGHT_PERIOD> store_airline_code_t;
- typedef store_flight_number<FLIGHT_PERIOD> store_flight_number_t;
- typedef store_date_range_start<FLIGHT_PERIOD> store_date_range_start_t;
- typedef store_date_range_end<FLIGHT_PERIOD> store_date_range_end_t;
- typedef store_dow<FLIGHT_PERIOD> store_dow_t;
- typedef store_board_point<FLIGHT_PERIOD> store_board_point_t;
- typedef store_off_point<FLIGHT_PERIOD> store_off_point_t;
- typedef store_board_time<FLIGHT_PERIOD> store_board_time_t;
- typedef store_off_time<FLIGHT_PERIOD> store_off_time_t;
- typedef store_elapsed_time<FLIGHT_PERIOD> store_elapsed_time_t;
- typedef store_cabin_code<FLIGHT_PERIOD> store_cabin_code_t;
- typedef store_capacity<FLIGHT_PERIOD> store_capacity_t;
- typedef store_segment_specificity<FLIGHT_PERIOD> store_segment_specificity_t;
- typedef store_segment_board_point<FLIGHT_PERIOD> store_segment_board_point_t;
- typedef store_segment_off_point<FLIGHT_PERIOD> store_segment_off_point_t;
- typedef store_segment_cabin_code<FLIGHT_PERIOD> store_segment_cabin_code_t;
- typedef store_classes<FLIGHT_PERIOD> store_classes_t;
- typedef do_end_flight<FLIGHT_PERIOD> do_end_flight_t;
-
- FLIGHT_PERIOD _flightPeriod;
+ FlightPeriod_T _flightPeriod;
FlightPeriodParser () :
FlightPeriodParser::base_type(start) {
- using boost::spirit::ascii::string;
- using boost::spirit::ascii::char_;
- using boost::spirit::qi::lexeme;
- using boost::spirit::qi::repeat;
- using boost::spirit::qi::double_;
- using boost::spirit::qi::on_error;
- using boost::spirit::qi::fail;
- using boost::spirit::qi::eol;
- using boost::phoenix::ref;
- using boost::phoenix::construct;
- using boost::phoenix::val;
- using namespace boost::spirit::qi::labels;
-
start = *(comment | flight_period);
- comment = lexeme[ (repeat(2)[char_("/")]) >> +(char_ - eol) >> eol ];
+ comment = (bsq::lexeme[ (bsq::repeat(2)[bsa::char_("/")]) >> +(bsa::char_ - bsq::eol) >> bsq::eol ]
+ | bsq::lexeme[ (bsa::char_("/") >> bsa::char_("*") >> +(bsa::char_ - bsa::char_("*")) >> bsa::char_("*") >> bsa::char_("/")) ])
+ ;
flight_period = flight_key
>> +( ';' >> leg )
>> +( ';' >> segment )
- >> flight_period_end[do_end_flight_t(_flightPeriod)]
+ >> flight_period_end[do_end_flight(_flightPeriod)]
;
flight_period_end = ';';
flight_key = airline_code
>> ';' >> flight_number
- >> ';' >> date[store_date_range_start_t(_flightPeriod)]
- >> ';' >> date[store_date_range_end_t(_flightPeriod)]
+ >> ';' >> date[store_date_range_start(_flightPeriod)]
+ >> ';' >> date[store_date_range_end(_flightPeriod)]
>> ';' >> dow
;
airline_code =
- lexeme[ (repeat(2)[char_("A-Z")])[store_airline_code_t(_flightPeriod)] ];
+ bsq::lexeme[ (bsq::repeat(2)[bsa::char_("A-Z")])[store_airline_code(_flightPeriod)] ];
- flight_number = uint1_4_p[store_flight_number_t(_flightPeriod)];
+ flight_number = uint1_4_p[store_flight_number(_flightPeriod)];
- date = lexeme[ uint4_p[ref(_flightPeriod._itYear) = _1]
- >> '-' >> uint2_p[ref(_flightPeriod._itMonth) = _1]
- >> '-' >> uint2_p[ref(_flightPeriod._itDay) = _1] ]
- ;
-
+ date = bsq::lexeme[ uint4_p[bp::ref(_flightPeriod._itYear) = bsq::labels::_1]
+ >> '-' >> uint2_p[bp::ref(_flightPeriod._itMonth) =bsq::labels::_1]
+ >> '-' >> uint2_p[bp::ref(_flightPeriod._itDay) = bsq::labels::_1] ]
+ ;
+
dow =
- lexeme[ (repeat(7)[char_("0-1")])[store_dow_t(_flightPeriod)] ]
+ bsq::lexeme[ (bsq::repeat(7)[bsa::char_("0-1")])[store_dow(_flightPeriod)] ]
;
leg = leg_key >> ';' >> leg_details >> +( ';' >> cabin_details )
;
leg_key =
- lexeme[ (repeat(3)[char_("A-Z")])[store_board_point_t(_flightPeriod)] ]
+ bsq::lexeme[ (bsq::repeat(3)[bsa::char_("A-Z")])[store_board_point(_flightPeriod)] ]
>> ';'
- >> lexeme[ (repeat(3)[char_("A-Z")])[store_off_point_t(_flightPeriod)] ]
+ >> bsq::lexeme[ (bsq::repeat(3)[bsa::char_("A-Z")])[store_off_point(_flightPeriod)] ]
;
leg_details =
- time[store_board_time_t(_flightPeriod)]
+ time[store_board_time(_flightPeriod)]
>> -(date_offset)
>> ';'
- >> time[store_off_time_t(_flightPeriod)]
+ >> time[store_off_time(_flightPeriod)]
>> -(date_offset)
>> ';'
- >> time[store_elapsed_time_t(_flightPeriod)]
+ >> time[store_elapsed_time(_flightPeriod)]
;
- time = lexeme[ uint2_p[ref(_flightPeriod._itHours) = _1]
- >> ':' >> uint2_p[ref(_flightPeriod._itMinutes) = _1]
- >> !(':' >> (uint2_p)[ref(_flightPeriod._itSeconds) = _1]) ]
+ time = bsq::lexeme[ uint2_p[bp::ref(_flightPeriod._itHours) = bsq::labels::_1]
+ >> ':' >> uint2_p[bp::ref(_flightPeriod._itMinutes) = bsq::labels::_1]
+ >> !(':' >> (uint2_p)[bp::ref(_flightPeriod._itSeconds) = bsq::labels::_1]) ]
;
- date_offset = char_('/')
- >> (char_("+") | char_("-"))
- >> int1_p[ref(_flightPeriod._dateOffSet) = _1]
+ date_offset = bsa::char_('/')
+ >> (bsa::char_("+") | bsa::char_("-"))
+ >> int1_p[bp::ref(_flightPeriod._dateOffSet) = bsq::labels::_1]
;
- cabin_details = char_("A-Z") [store_cabin_code_t(_flightPeriod)]
- >> ';' >> double_[store_capacity_t(_flightPeriod)]
+ cabin_details = bsa::char_("A-Z") [store_cabin_code(_flightPeriod)]
+ >> ';' >> bsq::
+ double_[store_capacity(_flightPeriod)]
;
- segment_key = (repeat(3)[char_("A-Z")])[store_segment_board_point_t(_flightPeriod)]
+ segment_key = (bsq::repeat(3)[bsa::char_("A-Z")])[store_segment_board_point(_flightPeriod)]
>> ';'
- >> (repeat(3)[char_("A-Z")])[store_segment_off_point_t(_flightPeriod)]
+ >> (bsq::repeat(3)[bsa::char_("A-Z")])[store_segment_off_point(_flightPeriod)]
;
segment =
@@ -891,12 +852,12 @@
;
general_segments =
- char_('0')[store_segment_specificity_t(_flightPeriod)]
+ bsa::char_('0')[store_segment_specificity(_flightPeriod)]
>> +(';' >> segment_cabin_details)
;
specific_segments =
- char_('1')[store_segment_specificity_t(_flightPeriod)]
+ bsa::char_('1')[store_segment_specificity(_flightPeriod)]
>> +(';' >> segment_key >> full_segment_cabin_details)
;
@@ -904,12 +865,12 @@
+(';' >> segment_cabin_details)
;
- segment_cabin_details = char_("A-Z")[store_segment_cabin_code_t(_flightPeriod)]
- >> ';' >> (repeat(1,26)[char_("A-Z")])[store_classes_t(_flightPeriod)]
+ segment_cabin_details = bsa::char_("A-Z")[store_segment_cabin_code(_flightPeriod)]
+ >> ';' >> (bsq::repeat(1,26)[bsa::char_("A-Z")])[store_classes(_flightPeriod)]
;
}
- boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type>
+ bsq::rule<ITERATOR, bsa::space_type>
start, comment, flight_period, flight_key, airline_code,
flight_number, date, dow, leg, leg_key, leg_details,
time, date_offset, cabin_details, segment, segment_key,
@@ -922,50 +883,49 @@
////////////////////////////////////////////////////////////////////////////
// Main program
////////////////////////////////////////////////////////////////////////////
-int main () {
+int main (int argc, char* argv[]) {
- try{
-
- // File to be parsed
- std::ifstream in("world_schedule.csv", std::ios_base::in);
+ // File to be parsed
+ std::ifstream fileToBeParsed("world_schedule.csv", std::ios_base::in);
- // Open the file
- if (!in) {
- std::cerr << "Error: Could not open input file: world_schedule.csv"
- << std::endl;
- return 1;
- }
+ // Open the file
+ if (fileToBeParsed == false) {
+ std::cerr << "Error: Could not open input file: world_schedule.csv"
+ << std::endl;
+ return 1;
+ }
- // Create an input iterator
- typedef std::istreambuf_iterator<char> base_iterator_type;
- base_iterator_type in_begin(in);
+ // Create an input iterator
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ base_iterator_type inputBegin(fileToBeParsed);
- // Convert input iterator to forward iterator, usable by spirit parser
- typedef boost::spirit::multi_pass<base_iterator_type> forward_iterator_type;
- forward_iterator_type fwd_begin = boost::spirit::make_default_multi_pass(in_begin);
- forward_iterator_type fwd_end;
+ // Convert input iterator to forward iterator, usable by spirit parser
+ typedef boost::spirit::multi_pass<base_iterator_type> forward_iterator_type;
+ forward_iterator_type iter = boost::spirit::make_default_multi_pass(inputBegin);
+ forward_iterator_type end;
- // Define our grammar
- typedef FlightPeriodParser<forward_iterator_type, FlightPeriod_T> lFlightPeriodParser;
- lFlightPeriodParser flightParser;
+ // Define our grammar
+ typedef FlightPeriodParser<forward_iterator_type> lFlightPeriodParser;
+ lFlightPeriodParser flightParser;
- // Parse input file
- bool r = boost::spirit::qi::phrase_parse(fwd_begin, fwd_end, flightParser, boost::spirit::ascii::space );
+ // Parse input file
+ const bool hasParsingBeenSuccesful =
+ bsq::phrase_parse(iter, end, flightParser, bsa::space);
- std::cout << "-------------------------------------------------------------------------------\n";
- if (!r || fwd_begin != fwd_end) {
- std::cout << "Parsing of schedule input failed"
- << std::endl;
- } else {
- std::cout << "Parsing of schedule input succeeded"
- << std::endl;
- }
- std::cout << "-------------------------------------------------------------------------------\n";
- } catch (const std::exception& e) {
- std::cerr << "Exception: "
- << e.what()
+ std::cout << "-------------------------------------------------------------------------------\n";
+ if (hasParsingBeenSuccesful == false) {
+ std::cout << "Parsing of schedule input failed"
<< std::endl;
- return 1;
}
+ if (iter != end) {
+ std::cout << "Parsing of schedule input failed"
+ << std::endl;
+ }
+ if (hasParsingBeenSuccesful == true && iter == end) {
+ std::cout << "Parsing of schedule input succeeded"
+ << std::endl;
+ }
+ std::cout << "-------------------------------------------------------------------------------\n";
+
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-19 10:25:25
|
Revision: 160
http://dsim.svn.sourceforge.net/dsim/?rev=160&view=rev
Author: gsabatier
Date: 2010-11-19 10:25:19 +0000 (Fri, 19 Nov 2010)
Log Message:
-----------
[Test/Boost] Documentation in schedule parser with Spirit v2
Modified Paths:
--------------
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-19 10:04:02 UTC (rev 159)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-19 10:25:19 UTC (rev 160)
@@ -726,7 +726,7 @@
///////////////////////////////////////////////////////////////////////////////
//
-// Our calculator grammar
+// Our flight-period grammar
//
///////////////////////////////////////////////////////////////////////////////
/**
@@ -776,7 +776,7 @@
////////////////////////////////////////////////////////////////////////////
template <typename ITERATOR, typename FLIGHT_PERIOD>
struct FlightPeriodParser :
- boost::spirit::qi::grammar<ITERATOR, boost::spirit::qi::locals<std::string>, boost::spirit::ascii::space_type> {
+ boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type> {
typedef store_airline_code<FLIGHT_PERIOD> store_airline_code_t;
typedef store_flight_number<FLIGHT_PERIOD> store_flight_number_t;
@@ -909,8 +909,8 @@
;
}
- boost::spirit::qi::rule<ITERATOR, boost::spirit::qi::locals<std::string>, boost::spirit::ascii::space_type> start,
- comment, flight_period, flight_key, airline_code,
+ boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type>
+ start, comment, flight_period, flight_key, airline_code,
flight_number, date, dow, leg, leg_key, leg_details,
time, date_offset, cabin_details, segment, segment_key,
general_segments, specific_segments, full_segment_cabin_details,
@@ -925,16 +925,18 @@
int main () {
try{
- char const* filename = "world_schedule.csv";
- std::ifstream in(filename, std::ios_base::in);
-
+ // File to be parsed
+ std::ifstream in("world_schedule.csv", std::ios_base::in);
+
+ // Open the file
if (!in) {
- std::cerr << "Error: Could not open input file: "
- << filename << std::endl;
+ std::cerr << "Error: Could not open input file: world_schedule.csv"
+ << std::endl;
return 1;
}
-
+
+ // Create an input iterator
typedef std::istreambuf_iterator<char> base_iterator_type;
base_iterator_type in_begin(in);
@@ -952,14 +954,18 @@
std::cout << "-------------------------------------------------------------------------------\n";
if (!r || fwd_begin != fwd_end) {
- std::cout << "Parsing failed\n";
+ std::cout << "Parsing of schedule input failed"
+ << std::endl;
} else {
- std::cout << "Parsing succeeded\n";
+ std::cout << "Parsing of schedule input succeeded"
+ << std::endl;
}
std::cout << "-------------------------------------------------------------------------------\n";
} catch (const std::exception& e) {
- std::cerr << "Exception: " << e.what() << std::endl;
- return -1;
+ std::cerr << "Exception: "
+ << e.what()
+ << std::endl;
+ return 1;
}
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-19 10:04:09
|
Revision: 159
http://dsim.svn.sourceforge.net/dsim/?rev=159&view=rev
Author: gsabatier
Date: 2010-11-19 10:04:02 +0000 (Fri, 19 Nov 2010)
Log Message:
-----------
[Test/Boost] Parsed the input file at one stroke with Spirit v2
Modified Paths:
--------------
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-16 16:49:57 UTC (rev 158)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-19 10:04:02 UTC (rev 159)
@@ -5,6 +5,8 @@
#include <fstream>
#include <set>
#include <vector>
+#include <algorithm>
+#include <string>
// Boost (Extended STL)
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
@@ -13,14 +15,17 @@
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+#include <boost/spirit/include/qi_core.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
-#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/fusion/include/io.hpp>
+#include <boost/spirit/include/classic_position_iterator.hpp>
#include <boost/lambda/lambda.hpp>
-typedef std::string::const_iterator iterator_t;
+typedef std::string::iterator iterator_t;
+
/** LegCabin-Details. */
struct Cabin_T {
// Attributes
@@ -771,7 +776,7 @@
////////////////////////////////////////////////////////////////////////////
template <typename ITERATOR, typename FLIGHT_PERIOD>
struct FlightPeriodParser :
- boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type > {
+ boost::spirit::qi::grammar<ITERATOR, boost::spirit::qi::locals<std::string>, boost::spirit::ascii::space_type> {
typedef store_airline_code<FLIGHT_PERIOD> store_airline_code_t;
typedef store_flight_number<FLIGHT_PERIOD> store_flight_number_t;
@@ -802,12 +807,17 @@
using boost::spirit::qi::lexeme;
using boost::spirit::qi::repeat;
using boost::spirit::qi::double_;
- using boost::spirit::qi::_1;
+ using boost::spirit::qi::on_error;
+ using boost::spirit::qi::fail;
+ using boost::spirit::qi::eol;
using boost::phoenix::ref;
+ using boost::phoenix::construct;
+ using boost::phoenix::val;
+ using namespace boost::spirit::qi::labels;
- start = (comment | flight_period) ;
+ start = *(comment | flight_period);
- comment = lexeme[ (repeat(2)[char_("/")]) ] >> *(char_);
+ comment = lexeme[ (repeat(2)[char_("/")]) >> +(char_ - eol) >> eol ];
flight_period = flight_key
>> +( ';' >> leg )
@@ -897,15 +907,14 @@
segment_cabin_details = char_("A-Z")[store_segment_cabin_code_t(_flightPeriod)]
>> ';' >> (repeat(1,26)[char_("A-Z")])[store_classes_t(_flightPeriod)]
;
-
- }
+ }
- boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> start,
- comment, flight_period, flight_key, airline_code, flight_number,
- date, dow, leg, leg_key, leg_details, time, date_offset,
- cabin_details, segment, segment_key, general_segments,
- specific_segments, full_segment_cabin_details,
- segment_cabin_details, flight_period_end;
+ boost::spirit::qi::rule<ITERATOR, boost::spirit::qi::locals<std::string>, boost::spirit::ascii::space_type> start,
+ comment, flight_period, flight_key, airline_code,
+ flight_number, date, dow, leg, leg_key, leg_details,
+ time, date_offset, cabin_details, segment, segment_key,
+ general_segments, specific_segments, full_segment_cabin_details,
+ segment_cabin_details, flight_period_end;
};
@@ -913,9 +922,9 @@
////////////////////////////////////////////////////////////////////////////
// Main program
////////////////////////////////////////////////////////////////////////////
-int main (int argc, char* argv[]) {
-
- try {
+int main () {
+
+ try{
char const* filename = "world_schedule.csv";
std::ifstream in(filename, std::ios_base::in);
@@ -926,34 +935,30 @@
return 1;
}
- typedef FlightPeriodParser<std::string::const_iterator, FlightPeriod_T> lFlightPeriodParser;
- lFlightPeriodParser flightParser; // Our grammar
-
- std::string::const_iterator iter;
- std::string::const_iterator end;
-
- std::string line;
- bool r = true;
- using boost::spirit::ascii::space;
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ base_iterator_type in_begin(in);
-
- while (r && std::getline(in, line)) {
- iter = line.begin();
- end = line.end();
- r = phrase_parse(iter, end, flightParser, space);
- if (iter != end) {
- r = false;
- }
- }
- std::cout << "-------------------------\n";
- if (r && iter == end) {
+ // Convert input iterator to forward iterator, usable by spirit parser
+ typedef boost::spirit::multi_pass<base_iterator_type> forward_iterator_type;
+ forward_iterator_type fwd_begin = boost::spirit::make_default_multi_pass(in_begin);
+ forward_iterator_type fwd_end;
+
+ // Define our grammar
+ typedef FlightPeriodParser<forward_iterator_type, FlightPeriod_T> lFlightPeriodParser;
+ lFlightPeriodParser flightParser;
+
+ // Parse input file
+ bool r = boost::spirit::qi::phrase_parse(fwd_begin, fwd_end, flightParser, boost::spirit::ascii::space );
+
+ std::cout << "-------------------------------------------------------------------------------\n";
+ if (!r || fwd_begin != fwd_end) {
+ std::cout << "Parsing failed\n";
+ } else {
std::cout << "Parsing succeeded\n";
- } else {
- std::cout << "Parsing failed\n";
}
- std::cout << "-------------------------\n";
- } catch (const std::exception& stde) {
- std::cerr << "Standard exception: " << stde.what() << std::endl;
+ std::cout << "-------------------------------------------------------------------------------\n";
+ } catch (const std::exception& e) {
+ std::cerr << "Exception: " << e.what() << std::endl;
return -1;
}
return 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-16 16:50:03
|
Revision: 158
http://dsim.svn.sourceforge.net/dsim/?rev=158&view=rev
Author: gsabatier
Date: 2010-11-16 16:49:57 +0000 (Tue, 16 Nov 2010)
Log Message:
-----------
[Test Boost] Good output message after parsing a schedule file with Classic version
Modified Paths:
--------------
trunk/dsim/test/boost/spirit/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spirit/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-16 13:22:37 UTC (rev 157)
+++ trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-16 16:49:57 UTC (rev 158)
@@ -886,17 +886,27 @@
boost::spirit::classic::space_p);
// DEBUG
- std::cout << "Flight Period:" << std::endl;
- lFlightPeriod.display();
+ //std::cout << "Flight Period:" << std::endl;
+ //lFlightPeriod.display();
- std::cout << "-------------------------" << std::endl;
+ const std::string hasBeenFullyReadStr = (info.full == true)?"":"not ";
+
if (info.hit) {
- std::cout << "Parsing succeeded" << std::endl;
+ std::cout << "Parsing of fare input file: " << lFilename
+ << " succeeded: read " << info.length
+ << " characters. \nThe input file has "
+ << hasBeenFullyReadStr
+ << "been fully read. Stop point: " << info.stop
+ << std::endl;
} else {
- std::cout << "Parsing failed" << std::endl;
+ std::cout << "Parsing of fare input file: " << lFilename
+ << " failed: read " << info.length
+ << " characters. The input file has "
+ << hasBeenFullyReadStr
+ << "been fully read. Stop point: " << info.stop
+ << std::endl;
}
- std::cout << "-------------------------" << std::endl;
} catch (const std::exception& stde) {
std::cerr << "Standard exception: " << stde.what() << std::endl;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-16 13:22:43
|
Revision: 157
http://dsim.svn.sourceforge.net/dsim/?rev=157&view=rev
Author: gsabatier
Date: 2010-11-16 13:22:37 +0000 (Tue, 16 Nov 2010)
Log Message:
-----------
[Test Boost] Bug correction in a spirit classic parser test
Modified Paths:
--------------
trunk/dsim/test/boost/spirit/schedule_parser.cpp
Modified: trunk/dsim/test/boost/spirit/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
+++ trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-16 13:22:37 UTC (rev 157)
@@ -890,7 +890,7 @@
lFlightPeriod.display();
std::cout << "-------------------------" << std::endl;
- if (info.full) {
+ if (info.hit) {
std::cout << "Parsing succeeded" << std::endl;
} else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-16 10:08:16
|
Revision: 156
http://dsim.svn.sourceforge.net/dsim/?rev=156&view=rev
Author: gsabatier
Date: 2010-11-16 10:08:08 +0000 (Tue, 16 Nov 2010)
Log Message:
-----------
[Boost Test] Tests for the Spirit v2 parser are mow implemented
Modified Paths:
--------------
trunk/dsim/test/boost/Makefile.am
trunk/dsim/test/boost/spirit/Makefile.am
trunk/dsim/test/boost/spirit/world_schedule.csv
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
trunk/dsim/test/boost/spiritQi/world_schedule.csv
Removed Paths:
-------------
trunk/dsim/test/boost/spirit/action_parser.cpp
trunk/dsim/test/boost/spirit/bad_input.csv
trunk/dsim/test/boost/spirit/complex_parser.cpp
trunk/dsim/test/boost/spirit/employee_parser.cpp
trunk/dsim/test/boost/spirit/good_input.csv
trunk/dsim/test/boost/spirit/num_list1_parser.cpp
trunk/dsim/test/boost/spirit/roman_parser.cpp
trunk/dsim/test/boost/spirit/stream_iterator_parser.cpp
trunk/dsim/test/boost/spirit/sum_parser.cpp
Modified: trunk/dsim/test/boost/Makefile.am
===================================================================
--- trunk/dsim/test/boost/Makefile.am 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/Makefile.am 2010-11-16 10:08:08 UTC (rev 156)
@@ -5,7 +5,7 @@
MAINTAINERCLEANFILES = Makefile.in
##
-SUBDIRS = accumulators asio filesystem intrusive mpi mpl \
+SUBDIRS = accumulators asio filesystem intrusive mpl \
serialization signals spirit spiritQi smart_pointers
EXTRA_DIST =
Modified: trunk/dsim/test/boost/spirit/Makefile.am
===================================================================
--- trunk/dsim/test/boost/spirit/Makefile.am 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/Makefile.am 2010-11-16 10:08:08 UTC (rev 156)
@@ -3,42 +3,44 @@
MAINTAINERCLEANFILES = Makefile.in
-check_PROGRAMS = employee_parser action_parser complex_parser \
- num_list1_parser roman_parser sum_parser \
- schedule_parser stream_iterator_parser levenshtein
+check_PROGRAMS = full_calculator functor_parser number_parser \
+ parameter_parser spirit_parser subrule_parser \
+ schedule_parser search_string_parser levenshtein
-levenshtein_SOURCES = levenshtein.cpp
-levenshtein_CXXFLAGS =
-levenshtein_LDFLAGS =
+full_calculator_SOURCES = full_calculator.cpp
+full_calculator_CXXFLAGS = $(BOOST_CFLAGS)
+full_calculator_LDADD = $(BOOST_LIBS)
-employee_parser_SOURCES = employee_parser.cpp
-employee_parser_CXXFLAGS = $(BOOST_CFLAGS)
-employee_parser_LDADD = $(BOOST_LIBS)
+functor_parser_SOURCES = functor_parser.cpp
+functor_parser_CXXFLAGS = $(BOOST_CFLAGS)
+functor_parser_LDADD = $(BOOST_LIBS)
-action_parser_SOURCES = action_parser.cpp
-action_parser_CXXFLAGS = $(BOOST_CFLAGS)
-action_parser_LDADD = $(BOOST_LIBS)
+number_parser_SOURCES = number_parser.cpp
+number_parser_CXXFLAGS = $(BOOST_CFLAGS)
+number_parser_LDADD = $(BOOST_LIBS)
-complex_parser_SOURCES = complex_parser.cpp
-complex_parser_CXXFLAGS = $(BOOST_CFLAGS)
-complex_parser_LDADD = $(BOOST_LIBS)
+parameter_parser_SOURCES = parameter_parser.cpp
+parameter_parser_CXXFLAGS = $(BOOST_CFLAGS)
+parameter_parser_LDADD = $(BOOST_LIBS)
-num_list1_parser_SOURCES = num_list1_parser.cpp
-num_list1_parser_CXXFLAGS = $(BOOST_CFLAGS)
-num_list1_parser_LDADD = $(BOOST_LIBS)
+spirit_parser_SOURCES = spirit_parser.cpp
+spirit_parser_CXXFLAGS = $(BOOST_CFLAGS)
+spirit_parser_LDADD = $(BOOST_LIBS)
-roman_parser_SOURCES = roman_parser.cpp
-roman_parser_CXXFLAGS = $(BOOST_CFLAGS)
-roman_parser_LDADD = $(BOOST_LIBS)
+subrule_parser_SOURCES = subrule_parser.cpp
+subrule_parser_CXXFLAGS = $(BOOST_CFLAGS)
+subrule_parser_LDADD = $(BOOST_LIBS)
-sum_parser_SOURCES = sum_parser.cpp
-sum_parser_CXXFLAGS = $(BOOST_CFLAGS)
-sum_parser_LDADD = $(BOOST_LIBS)
-
schedule_parser_SOURCES = schedule_parser.cpp
schedule_parser_CXXFLAGS = $(BOOST_CFLAGS)
schedule_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
-stream_iterator_parser_SOURCES = stream_iterator_parser.cpp
-stream_iterator_parser_CXXFLAGS = $(BOOST_CFLAGS)
-stream_iterator_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
+search_string_parser_SOURCES = search_string_parser.cpp
+search_string_parser_CXXFLAGS = $(BOOST_CFLAGS)
+search_string_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
+
+levenshtein_SOURCES = levenshtein.cpp
+levenshtein_LDADD =
+
+EXTRA_DIST = test_full_calculator.sh test_parameter_parser.sh \
+ test_schedule_parser.sh
Deleted: trunk/dsim/test/boost/spirit/action_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/action_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/action_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,104 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/lambda/lambda.hpp>
-#include <boost/bind.hpp>
-
-#include <iostream>
-
-// Presented are various ways to attach semantic actions
-// * Using plain function pointer
-// * Using simple function object
-// * Using boost.bind with a plain function
-// * Using boost.bind with a member function
-// * Using boost.lambda
-
-//[tutorial_semantic_action_functions
-namespace client
-{
- namespace qi = boost::spirit::qi;
-
- // A plain function
- void print(int const& i)
- {
- std::cout << i << std::endl;
- }
-
- // A member function
- struct writer
- {
- void print(int const& i) const
- {
- std::cout << i << std::endl;
- }
- };
-
- // A function object
- struct print_action
- {
- void operator()(int const& i, qi::unused_type, qi::unused_type) const
- {
- std::cout << i << std::endl;
- }
- };
-}
-//]
-
-int main()
-{
- using boost::spirit::qi::int_;
- using boost::spirit::qi::parse;
- using client::print;
- using client::writer;
- using client::print_action;
-
- { // example using plain function
-
- char const *first = "{42}", *last = first + std::strlen(first);
- //[tutorial_attach_actions1
- parse(first, last, '{' >> int_[&print] >> '}');
- //]
- }
-
- { // example using simple function object
-
- char const *first = "{43}", *last = first + std::strlen(first);
- //[tutorial_attach_actions2
- parse(first, last, '{' >> int_[print_action()] >> '}');
- //]
- }
-
- { // example using boost.bind with a plain function
-
- char const *first = "{44}", *last = first + std::strlen(first);
- //[tutorial_attach_actions3
- parse(first, last, '{' >> int_[boost::bind(&print, _1)] >> '}');
- //]
- }
-
- { // example using boost.bind with a member function
-
- char const *first = "{44}", *last = first + std::strlen(first);
- //[tutorial_attach_actions4
- writer w;
- parse(first, last, '{' >> int_[boost::bind(&writer::print, &w, _1)] >> '}');
- //]
- }
-
- { // example using boost.lambda
-
- namespace lambda = boost::lambda;
- char const *first = "{45}", *last = first + std::strlen(first);
- using lambda::_1;
- //[tutorial_attach_actions5
- parse(first, last, '{' >> int_[std::cout << _1 << '\n'] >> '}');
- //]
- }
-
- return 0;
-}
Deleted: trunk/dsim/test/boost/spirit/bad_input.csv
===================================================================
--- trunk/dsim/test/boost/spirit/bad_input.csv 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/bad_input.csv 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,5 +0,0 @@
-# test
-#
-# bad input
-
-123;42.0;a;1.4
Deleted: trunk/dsim/test/boost/spirit/complex_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/complex_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/complex_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,101 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A complex number micro parser.
-//
-// [ JDG May 10, 2002 ] spirit1
-// [ JDG May 9, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include <iostream>
-#include <string>
-#include <complex>
-
-///////////////////////////////////////////////////////////////////////////////
-// Our complex number parser/compiler
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_complex_number
-namespace client
-{
- template <typename Iterator>
- bool parse_complex(Iterator first, Iterator last, std::complex<double>& c)
- {
- using boost::spirit::qi::double_;
- using boost::spirit::qi::_1;
- using boost::spirit::qi::phrase_parse;
- using boost::spirit::ascii::space;
- using boost::phoenix::ref;
-
- double rN = 0.0;
- double iN = 0.0;
- bool r = phrase_parse(first, last,
-
- // Begin grammar
- (
- '(' >> double_[ref(rN) = _1]
- >> -(',' >> double_[ref(iN) = _1]) >> ')'
- | double_[ref(rN) = _1]
- ),
- // End grammar
-
- space);
-
- if (!r || first != last) // fail if we did not get a full match
- return false;
- c = std::complex<double>(rN, iN);
- return r;
- }
-}
-//]
-
-////////////////////////////////////////////////////////////////////////////
-// Main program
-////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "\t\tA complex number micro parser for Spirit...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
-
- std::cout << "Give me a complex number of the form r or (r) or (r,i) \n";
- std::cout << "Type [q or Q] to quit\n\n";
-
- std::string str;
- while (getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::complex<double> c;
- if (client::parse_complex(str.begin(), str.end(), c))
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "got: " << c << std::endl;
- std::cout << "\n-------------------------\n";
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-
Deleted: trunk/dsim/test/boost/spirit/employee_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/employee_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/employee_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,152 +0,0 @@
-
-/*=============================================================================
- Copyright (c) 2002-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A parser for arbitrary tuples. This example presents a parser
-// for an employee structure.
-//
-// [ JDG May 9, 2007 ]
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <boost/spirit/include/phoenix_object.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include <boost/fusion/include/io.hpp>
-
-#include <iostream>
-#include <string>
-#include <complex>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////
- // Our employee struct
- ///////////////////////////////////////////////////////////////////////////
- //[tutorial_employee_struct
- struct employee
- {
- int age;
- std::string surname;
- std::string forename;
- double salary;
- };
- //]
-}
-
-// We need to tell fusion about our employee struct
-// to make it a first-class fusion citizen. This has to
-// be in global scope.
-
-//[tutorial_employee_adapt_struct
-BOOST_FUSION_ADAPT_STRUCT(
- client::employee,
- (int, age)
- (std::string, surname)
- (std::string, forename)
- (double, salary)
-)
-//]
-
-namespace client
-{
- ///////////////////////////////////////////////////////////////////////////////
- // Our employee parser
- ///////////////////////////////////////////////////////////////////////////////
- //[tutorial_employee_parser
- template <typename Iterator>
- struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
- {
- employee_parser() : employee_parser::base_type(start)
- {
- using qi::int_;
- using qi::lit;
- using qi::double_;
- using qi::lexeme;
- using ascii::char_;
-
- quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
-
- start %=
- lit("employee")
- >> '{'
- >> int_ >> ','
- >> quoted_string >> ','
- >> quoted_string >> ','
- >> double_
- >> '}'
- ;
- }
-
- qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
- qi::rule<Iterator, employee(), ascii::space_type> start;
- };
- //]
-}
-
-////////////////////////////////////////////////////////////////////////////
-// Main program
-////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "\t\tAn employee parser for Spirit...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
-
- std::cout
- << "Give me an employee of the form :"
- << "employee{age, \"surname\", \"forename\", salary } \n";
- std::cout << "Type [q or Q] to quit\n\n";
-
- using boost::spirit::ascii::space;
- typedef std::string::const_iterator iterator_type;
- typedef client::employee_parser<iterator_type> employee_parser;
-
- employee_parser g; // Our grammar
- std::string str;
- while (getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- client::employee emp;
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, g, space, emp);
-
- if (r && iter == end)
- {
- std::cout << boost::fusion::tuple_open('[');
- std::cout << boost::fusion::tuple_close(']');
- std::cout << boost::fusion::tuple_delimiter(", ");
-
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "got: " << boost::fusion::as_vector(emp) << std::endl;
- std::cout << "\n-------------------------\n";
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-
Deleted: trunk/dsim/test/boost/spirit/good_input.csv
===================================================================
--- trunk/dsim/test/boost/spirit/good_input.csv 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/good_input.csv 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,5 +0,0 @@
-# test
-#
-# good input
-8 ;
-6; 7;
Deleted: trunk/dsim/test/boost/spirit/num_list1_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/num_list1_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/num_list1_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,90 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// This sample demontrates a parser for a comma separated list of numbers.
-// No actions.
-//
-// [ JDG May 10, 2002 ] spirit1
-// [ JDG March 24, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-
-#include <iostream>
-#include <string>
-#include <vector>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////
- // Our number list parser
- ///////////////////////////////////////////////////////////////////////////
- //[tutorial_numlist1
- template <typename Iterator>
- bool parse_numbers(Iterator first, Iterator last)
- {
- using qi::double_;
- using qi::phrase_parse;
- using ascii::space;
-
- bool r = phrase_parse(
- first, /*< start iterator >*/
- last, /*< end iterator >*/
- double_ >> *(',' >> double_), /*< the parser >*/
- space /*< the skip-parser >*/
- );
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
- }
- //]
-}
-
-////////////////////////////////////////////////////////////////////////////
-// Main program
-////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "\t\tA comma separated list parser for Spirit...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
-
- std::cout << "Give me a comma separated list of numbers.\n";
- std::cout << "Type [q or Q] to quit\n\n";
-
- std::string str;
- while (getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- if (client::parse_numbers(str.begin(), str.end()))
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << str << " Parses OK: " << std::endl;
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-
Deleted: trunk/dsim/test/boost/spirit/roman_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/roman_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/roman_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,186 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A Roman Numerals Parser (demonstrating the symbol table). This is
-// discussed in the "Symbols" chapter in the Spirit User's Guide.
-//
-// [ JDG August 22, 2002 ] spirit1
-// [ JDG March 13, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include <iostream>
-#include <string>
-
-namespace client
-{
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
-
- ///////////////////////////////////////////////////////////////////////////////
- // Parse roman hundreds (100..900) numerals using the symbol table.
- // Notice that the data associated with each slot is the parser's attribute
- // (which is passed to attached semantic actions).
- ///////////////////////////////////////////////////////////////////////////////
- //[tutorial_roman_hundreds
- struct hundreds_ : qi::symbols<char, unsigned>
- {
- hundreds_()
- {
- add
- ("C" , 100)
- ("CC" , 200)
- ("CCC" , 300)
- ("CD" , 400)
- ("D" , 500)
- ("DC" , 600)
- ("DCC" , 700)
- ("DCCC" , 800)
- ("CM" , 900)
- ;
- }
-
- } hundreds;
- //]
-
- ///////////////////////////////////////////////////////////////////////////////
- // Parse roman tens (10..90) numerals using the symbol table.
- ///////////////////////////////////////////////////////////////////////////////
- //[tutorial_roman_tens
- struct tens_ : qi::symbols<char, unsigned>
- {
- tens_()
- {
- add
- ("X" , 10)
- ("XX" , 20)
- ("XXX" , 30)
- ("XL" , 40)
- ("L" , 50)
- ("LX" , 60)
- ("LXX" , 70)
- ("LXXX" , 80)
- ("XC" , 90)
- ;
- }
-
- } tens;
- //]
-
- ///////////////////////////////////////////////////////////////////////////////
- // Parse roman ones (1..9) numerals using the symbol table.
- ///////////////////////////////////////////////////////////////////////////////
- //[tutorial_roman_ones
- struct ones_ : qi::symbols<char, unsigned>
- {
- ones_()
- {
- add
- ("I" , 1)
- ("II" , 2)
- ("III" , 3)
- ("IV" , 4)
- ("V" , 5)
- ("VI" , 6)
- ("VII" , 7)
- ("VIII" , 8)
- ("IX" , 9)
- ;
- }
-
- } ones;
- //]
-
- ///////////////////////////////////////////////////////////////////////////////
- // roman (numerals) grammar
- //
- // Note the use of the || operator. The expression
- // a || b reads match a or b and in sequence. Try
- // defining the roman numerals grammar in YACC or
- // PCCTS. Spirit rules! :-)
- ///////////////////////////////////////////////////////////////////////////////
- //[tutorial_roman_grammar
- template <typename Iterator>
- struct roman : qi::grammar<Iterator, unsigned()>
- {
- roman() : roman::base_type(start)
- {
- using qi::eps;
- using qi::lit;
- using qi::_val;
- using qi::_1;
- using ascii::char_;
-
- start = eps [_val = 0] >>
- (
- +lit('M') [_val += 1000]
- || hundreds [_val += _1]
- || tens [_val += _1]
- || ones [_val += _1]
- )
- ;
- }
-
- qi::rule<Iterator, unsigned()> start;
- };
- //]
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "\t\tRoman Numerals Parser\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type a Roman Numeral ...or [q or Q] to quit\n\n";
-
- typedef std::string::const_iterator iterator_type;
- typedef client::roman<iterator_type> roman;
-
- roman roman_parser; // Our grammar
-
- std::string str;
- unsigned result;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- //[tutorial_roman_grammar_parse
- bool r = parse(iter, end, roman_parser, result);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "result = " << result << std::endl;
- std::cout << "-------------------------\n";
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- //]
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
Deleted: trunk/dsim/test/boost/spirit/stream_iterator_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/stream_iterator_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/stream_iterator_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,91 +0,0 @@
-// Copyright (c) 2010 Peter Schueller
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-#include <vector>
-#include <istream>
-#include <sstream>
-#include <iostream>
-#include <fstream>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/support_multi_pass.hpp>
-
-namespace qi = boost::spirit::qi;
-namespace ascii = boost::spirit::ascii;
-
-
-////////////////////////////////////////////////////////////////////////////
-// Parser
-////////////////////////////////////////////////////////////////////////////
-template <typename iterator_t>
-bool parse(iterator_t& iStr, iterator_t& iStrEnd,
- std::vector<double>& output) {
-
- // Parse list of doubles from input stream
- bool r = qi::phrase_parse(
- iStr, iStrEnd, // Iterators
- *(qi::double_ >> ';'), // Recognize list of doubles
- ascii::space | '#' >> *(ascii::char_ - qi::eol) >> qi::eol, // Skip comment
- output); // Store double into this object
-
- // Return result of parsing
- return r;
-
-}
-
-////////////////////////////////////////////////////////////////////////////
-// Main program
-////////////////////////////////////////////////////////////////////////////
-int main (int argc, char* argv[]) {
-
- std::string lFilename("good_input.csv");
- std::ifstream File;
-
- // Read the command-line parameters
- if (argc >= 1 && argv[1] != NULL) {
- lFilename = argv[1];
- File.open (argv[1],std::ios_base::in);
- } else {
- // Default File to be parsed
- File.open ("good_input.csv",std::ios_base::in);
- }
-
- // Check the File existence
- if (!File) {
- std::cerr << "Unknown file named" << lFilename << std::endl;
- return 1;
- }
-
- // Iterate over stream input
- typedef std::istreambuf_iterator<char> base_iterator_type;
- base_iterator_type in_begin(File.rdbuf());
-
- // Convert input iterator to forward iterator, usable by spirit parser
- typedef boost::spirit::multi_pass<base_iterator_type>forward_iterator_type;
- forward_iterator_type fwd_begin =
- boost::spirit::make_default_multi_pass(in_begin);
- forward_iterator_type fwd_end;
-
- // Prepare output
- std::vector<double> output;
-
- try {
- bool r = parse(fwd_begin, fwd_end, output);
- // Error detection
- if( !r || fwd_begin != fwd_end ) {
- throw std::runtime_error("parse error in "+lFilename);
- } else {
- std::cout << "--------------------------------------------\n";
- std::cout << "Parsing of the file " << lFilename <<" succeeded\n";
- std::cout << "Got: ";
- for (unsigned int i = 0; i < output.size(); i++) {
- std::cout << output[i] << " ";
- }
- std::cout << "\n--------------------------------------------\n";
- }
- } catch(const std::exception& e) {
- std::cerr << "Exception: " << e.what() << std::endl;
- }
- return 0;
-}
-
Deleted: trunk/dsim/test/boost/spirit/sum_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/sum_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/sum_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -1,104 +0,0 @@
-/*=============================================================================
- Copyright (c) 2002-2010 Joel de Guzman
-
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A parser for summing a comma-separated list of numbers using phoenix.
-//
-// [ JDG June 28, 2002 ] spirit1
-// [ JDG March 24, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-//[tutorial_adder_includes
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-#include <iostream>
-#include <string>
-//]
-
-namespace client
-{
- //[tutorial_adder_using
- namespace qi = boost::spirit::qi;
- namespace ascii = boost::spirit::ascii;
- namespace phoenix = boost::phoenix;
-
- using qi::double_;
- using qi::_1;
- using ascii::space;
- using phoenix::ref;
- //]
-
- ///////////////////////////////////////////////////////////////////////////
- // Our adder
- ///////////////////////////////////////////////////////////////////////////
-
- //[tutorial_adder
- template <typename Iterator>
- bool adder(Iterator first, Iterator last, double& n)
- {
- bool r = qi::phrase_parse(first, last,
-
- // Begin grammar
- (
- double_[ref(n) = _1] >> *(',' >> double_[ref(n) += _1])
- )
- ,
- // End grammar
-
- space);
-
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
- }
- //]
-}
-
-////////////////////////////////////////////////////////////////////////////
-// Main program
-////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "\t\tA parser for summing a list of numbers...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
-
- std::cout << "Give me a comma separated list of numbers.\n";
- std::cout << "The numbers are added using Phoenix.\n";
- std::cout << "Type [q or Q] to quit\n\n";
-
- std::string str;
- while (getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- double n;
- if (client::adder(str.begin(), str.end(), n))
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << str << " Parses OK: " << std::endl;
-
- std::cout << "sum = " << n;
- std::cout << "\n-------------------------\n";
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
Modified: trunk/dsim/test/boost/spirit/world_schedule.csv
===================================================================
--- trunk/dsim/test/boost/spirit/world_schedule.csv 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spirit/world_schedule.csv 2010-11-16 10:08:08 UTC (rev 156)
@@ -3,9 +3,9 @@
// ElapsedTime; LegCabins;
// LegCabins: CabinCode; Capacity;
// Segments: Specific;
-BA; 9; 2007-04-20; 2007-06-30; 0000011; LHR; BKK; 22:00; 15:15; 11:15; F; 5; J; 12; W; 20; Y; 300; BKK; SYD; 18:10; 06:05; 08:55; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
-BA; 9; 2007-04-20; 2007-06-30; 1111100; LHR; BKK; 22:00; 15:15; 11:15; F; 5; J; 12; W; 20; Y; 300; BKK; SYD; 18:10; 06:05; 08:55; F; 5; J; 12; W; 20; Y; 300; 1; LHR; BKK; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ; BKK; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ; LHR; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
-BA; 117; 2007-04-20; 3000-06-30; 1111111; LHR; JFK; 08:20; 11:00; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKM;
+BA; 9; 2007-04-20; 2007-06-30; 0000011; LHR; BKK; 22:00; 15:15 / +1; 11:15; F; 5; J; 12; W; 20; Y; 300; BKK; SYD; 18:10 / +1; 06:05 / +2; 08:55; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+BA; 9; 2007-04-20; 2007-06-30; 1111100; LHR; BKK; 22:00; 15:15 / +1; 11:15; F; 5; J; 12; W; 20; Y; 300; BKK; SYD; 18:10 / +1; 06:05 / +2; 08:55; F; 5; J; 12; W; 20; Y; 300; 1; LHR; BKK; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ; BKK; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ; LHR; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+BA; 117; 2007-04-20; 2007-06-30; 1111111; LHR; JFK; 08:20; 11:00; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKM;
BA; 175; 2007-04-20; 2007-06-30; 1111111; LHR; JFK; 10:55; 13:35; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRL;
BA; 179; 2007-04-20; 2007-06-30; 1111111; LHR; JFK; 18:05; 20:45; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRVNELSQO;
BA; 207; 2007-04-20; 2007-06-30; 1111111; LHR; MIA; 09:40; 14:25; 09:45; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRVNELSQO;
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-10 20:15:47 UTC (rev 155)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-16 10:08:08 UTC (rev 156)
@@ -20,52 +20,695 @@
typedef std::string::const_iterator iterator_t;
+
+/** LegCabin-Details. */
+struct Cabin_T {
+ // Attributes
+ std::string _cabinCode;
+ double _capacity;
+
+ void display() const {
+ std::cout << " " << _cabinCode << " " << _capacity << ", ";
+ }
+};
+
+/** List of Cabin-Detail strucutres. */
+typedef std::vector<Cabin_T> CabinList_T;
+
+/** Leg. */
+struct Leg_T {
+ // Attributes
+ std::string _boardPoint;
+ boost::posix_time::time_duration _boardTime;
+ boost::gregorian::date_duration _boardDateOffSet;
+ std::string _offPoint;
+ boost::posix_time::time_duration _offTime;
+ boost::gregorian::date_duration _offDateOffSet;
+ boost::posix_time::time_duration _elapsed;
+ CabinList_T _cabinList;
+
+ /** Constructor. */
+ Leg_T () : _boardDateOffSet (0), _offDateOffSet (0) {}
+
+ void display() const {
+ std::cout << " " << _boardPoint << " / "
+ << boost::posix_time::to_simple_string (_boardTime)
+ << " -- " << _offPoint << " / "
+ << boost::posix_time::to_simple_string (_offTime)
+ << " --> " << boost::posix_time::to_simple_string (_elapsed)
+ << std::endl;
+ for (CabinList_T::const_iterator itCabin = _cabinList.begin();
+ itCabin != _cabinList.end(); itCabin++) {
+ const Cabin_T& lCabin = *itCabin;
+ lCabin.display();
+ }
+ std::cout << std::endl;
+ }
+};
+
+/** List of Leg strucutres. */
+typedef std::vector<Leg_T> LegList_T;
+
+/** SegmentCabin-Details. */
+struct SegmentCabin_T {
+ // Attributes
+ std::string _cabinCode;
+ std::string _classes;
+
+ void display() const {
+ std::cout << " " << _cabinCode << " " << _classes << ", ";
+ }
+};
+
+/** List of SegmentCabin-Detail strucutres. */
+typedef std::vector<SegmentCabin_T> SegmentCabinList_T;
+
+/** Segment. */
+struct Segment_T {
+ // Attributes
+ std::string _boardPoint;
+ boost::posix_time::time_duration _boardTime;
+ boost::gregorian::date_duration _boardDateOffSet;
+ std::string _offPoint;
+ boost::posix_time::time_duration _offTime;
+ boost::gregorian::date_duration _offDateOffSet;
+ boost::posix_time::time_duration _elapsed;
+ SegmentCabinList_T _cabinList;
+
+ /** Constructor. */
+ Segment_T () : _boardDateOffSet (0), _offDateOffSet (0) {}
+
+ void display() const {
+ std::cout << " " << _boardPoint << " / "
+ << boost::posix_time::to_simple_string (_boardTime)
+ << " -- " << _offPoint << " / "
+ << boost::posix_time::to_simple_string (_offTime)
+ << " --> " << boost::posix_time::to_simple_string (_elapsed)
+ << std::endl;
+ for (SegmentCabinList_T::const_iterator itCabin = _cabinList.begin();
+ itCabin != _cabinList.end(); itCabin++) {
+ const SegmentCabin_T& lCabin = *itCabin;
+ lCabin.display();
+ }
+ std::cout << std::endl;
+ }
+};
+
+/** List of Segment strucutres. */
+typedef std::vector<Segment_T> SegmentList_T;
+
/** Flight-Period. */
struct FlightPeriod_T {
+
// Attributes
std::string _airlineCode;
unsigned int _flightNumber;
boost::gregorian::date _dateRangeStart;
boost::gregorian::date _dateRangeEnd;
std::string _dow;
- std::string _cabinCode;
+ LegList_T _legList;
+ SegmentList_T _segmentList;
+
+ /** Constructor. */
+ FlightPeriod_T () : _legAlreadyDefined (false), _itSeconds (0) {}
+
+ /** Set the date from the staging details. */
+ boost::gregorian::date getDate() const {
+ return boost::gregorian::date (_itYear, _itMonth, _itDay);
+ }
+
+ /** Set the time from the staging details. */
+ boost::posix_time::time_duration getTime() const {
+ return boost::posix_time::hours (_itHours)
+ + boost::posix_time::minutes (_itMinutes)
+ + boost::posix_time::seconds (_itSeconds);
+ }
+
+ void display() const {
+ std::cout << _airlineCode << _flightNumber
+ << ", " << boost::gregorian::to_simple_string (_dateRangeStart)
+ << " - " << boost::gregorian::to_simple_string (_dateRangeEnd)
+ << " - " << _dow
+ << std::endl;
+
+ for (LegList_T::const_iterator itLeg = _legList.begin();
+ itLeg != _legList.end(); itLeg++) {
+ const Leg_T& lLeg = *itLeg;
+ lLeg.display();
+ }
+
+ for (SegmentList_T::const_iterator itSegment = _segmentList.begin();
+ itSegment != _segmentList.end(); itSegment++) {
+ const Segment_T& lSegment = *itSegment;
+ lSegment.display();
+ }
+
+ //std::cout << "[Debug] - Staging Leg: ";
+ //_itLeg.display();
+ //std::cout << "[Debug] - Staging Cabin: ";
+ //_itCabin.display();
+ //std::cout << "[Debug] - Staging Segment: ";
+ //_itSegment.display();
+ }
+
+ /** Add the given airport to the internal lists (if not already existing). */
+ void addAirport (const std::string& iAirport) {
+ std::set<std::string>::const_iterator itAirport =
+ _airportList.find (iAirport);
+ if (itAirport == _airportList.end()) {
+ // Add the airport code to the airport set
+ const bool insertSuccessful = _airportList.insert (iAirport).second;
+
+ if (insertSuccessful == false) {
+ // TODO: throw an exception
+ }
+ // Add the airport code to the airport vector
+ _airportOrderedList.push_back (iAirport);
+ }
+ }
+
+ /** Build the routing (segments). */
+ void buildSegments () {
+ // The list of airports encompasses all the airports on which
+ // the flight takes off or lands. Moreover, that list is
+ // time-ordered: the first airport is the initial departure of
+ // the flight, and the last airport is the eventual point of
+ // rest of the flight.
+ // Be l the size of the ordered list of airports.
+ // We want to generate all the segment combinations from the legs
+ // and, hence, from all the possible (time-ordered) airport pairs.
+ // Thus, we both iterator on i=0...l-1 and j=i+1...l
+ assert (_airportOrderedList.size() >= 2);
+
+ _segmentList.clear();
+ for (std::vector<std::string>::const_iterator itAirport_i =
+ _airportOrderedList.begin();
+ itAirport_i != _airportOrderedList.end()-1; ++itAirport_i) {
+ for (std::vector<std::string>::const_iterator itAirport_j =
+ itAirport_i + 1;
+ itAirport_j != _airportOrderedList.end(); ++itAirport_j) {
+ Segment_T lSegment;
+ lSegment._boardPoint = *itAirport_i;
+ lSegment._offPoint = *itAirport_j;
+
+ _segmentList.push_back (lSegment);
+ }
+ }
+
+ // Clear the lists of airports, so that it is ready for the next flight
+ _airportList.clear();
+ _airportOrderedList.clear();
+ }
+
+ /** Add, to the Segment whose key corresponds to the
+ given (board point, off point) pair, the specific segment cabin
+ details (mainly, the list of the class codes).
+ <br>Note that the Segment structure is retrieved from the internal
+ list, already filled by a previous step (the buildSegments()
+ method). */
+ void addSegmentCabin (const Segment_T& iSegment,
+ const SegmentCabin_T& iCabin) {
+ // Retrieve the Segment structure corresponding to the (board, off) point
+ // pair.
+ SegmentList_T::iterator itSegment = _segmentList.begin();
+ for ( ; itSegment != _segmentList.end(); ++itSegment) {
+ const Segment_T& lSegment = *itSegment;
+
+ const std::string& lBoardPoint = iSegment._boardPoint;
+ const std::string& lOffPoint = iSegment._offPoint;
+ if (lSegment._boardPoint == lBoardPoint
+ && lSegment._offPoint == lOffPoint) {
+ break;
+ }
+ }
+
+ // If the segment key (airport pair) given in the schedule input file
+ // does not correspond to the leg (board, off) points, throw an exception
+ // so that the user knows the schedule input file is corrupted.
+ if (itSegment == _segmentList.end()) {
+ std::cerr << "Within the schedule input file, there is a flight for which the airports of segments and those of the legs do not correspond.";
+ throw std::exception();
+ }
+
+ // Add the Cabin structure to the Segment Cabin structure.
+ assert (itSegment != _segmentList.end());
+ Segment_T& lSegment = *itSegment;
+ lSegment._cabinList.push_back (iCabin);
+ }
+
+ /** Add, to all the Segment, the general segment cabin details
+ (mainly, the list of the class codes).
+ <br>Note that the Segment structures are stored within the internal
+ list, already filled by a previous step (the buildSegments()
+ method). */
+ void addSegmentCabin (const SegmentCabin_T& iCabin) {
+ // Iterate on all the Segment (as they get the same cabin definitions)
+ for (SegmentList_T::iterator itSegment = _segmentList.begin();
+ itSegment != _segmentList.end(); ++itSegment) {
+ Segment_T& lSegment = *itSegment;
+ lSegment._cabinList.push_back (iCabin);
+ }
+ }
+
+ /** Staging Leg (resp. Cabin) structure, gathering the result of the iteration
+ on one leg (resp. cabin). */
+ bool _legAlreadyDefined;
+ Leg_T _itLeg;
+ Cabin_T _itCabin;
+
+ /** Staging Date. */
+ unsigned int _itYear;
+ unsigned int _itMonth;
+ unsigned int _itDay;
+
+ /** Staging Time. */
+ long _itHours;
+ long _itMinutes;
+ long _itSeconds;
+ int _dateOffSet;
+
+ /** Staging Airport List (helper to derive the list of Segment
+ structures). */
+ std::set<std::string> _airportList;
+ std::vector<std::string> _airportOrderedList;
+
+ /** Staging Segment-related attributes. */
+ bool _areSegmentDefinitionsSpecific;
+ Segment_T _itSegment;
+ SegmentCabin_T _itSegmentCabin;
+
};
+///////////////////////////////////////////////////////////////////////////////
+//
+// Semantic actions
+//
+///////////////////////////////////////////////////////////////////////////////
+
/** Store the parsed airline code. */
template <typename FLIGHT_PERIOD>
struct store_airline_code {
store_airline_code (FLIGHT_PERIOD& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lAirlineCode (iStr, iStrEnd);
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lAirlineCode (iChar.begin(), iChar.end());
_flightPeriod._airlineCode = lAirlineCode;
// std::cout << "Airline code: " << lAirlineCode << std::endl;
+
+ // As that's the beginning of a new flight, the list of legs must be reset
+ _flightPeriod._legList.clear();
}
FLIGHT_PERIOD& _flightPeriod;
};
+/** Store the parsed flight number. */
+template <typename FLIGHT_PERIOD>
+struct store_flight_number {
+ store_flight_number (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (unsigned int iNumber,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._flightNumber = iNumber;
+ //std::cout << "Flight number: " << iNumber << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the start of the date range. */
+template <typename FLIGHT_PERIOD>
+struct store_date_range_start {
+ store_date_range_start (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._dateRangeStart = _flightPeriod.getDate();
+ //std::cout << "Date Range Start: "
+ // << _flightPeriod._dateRangeStart << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the end of the date range. */
+template <typename FLIGHT_PERIOD>
+struct store_date_range_end {
+ store_date_range_end (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._dateRangeEnd = _flightPeriod.getDate();
+ //std::cout << "Date Range End: "
+ // << _flightPeriod._dateRangeEnd << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+};
+
+/** Store the DOW (day of the Week). */
+template <typename FLIGHT_PERIOD>
+struct store_dow {
+ store_dow (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lDow (iChar.begin(), iChar.end());
+ _flightPeriod._dow = lDow;
+ //std::cout << "DOW: " << lDow << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the parsed board point. */
+template <typename FLIGHT_PERIOD>
+struct store_board_point {
+ store_board_point (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lBoardPoint (iChar.begin(), iChar.end());
+ //std::cout << "Board point: " << lBoardPoint << std::endl;
+
+ // If a leg has already been parsed, add it to the FlightPeriod
+ if (_flightPeriod._legAlreadyDefined == true) {
+ _flightPeriod._legList.push_back (_flightPeriod._itLeg);
+ } else {
+ _flightPeriod._legAlreadyDefined = true;
+ }
+
+ // Set the (new) board point
+ _flightPeriod._itLeg._boardPoint = lBoardPoint;
+
+ // As that's the beginning of a new leg, the list of cabins must be reset
+ _flightPeriod._itLeg._cabinList.clear();
+
+ // Add the airport code if it is not already stored in the airport lists
+ _flightPeriod.addAirport (lBoardPoint);
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the parsed off point. */
+template <typename FLIGHT_PERIOD>
+struct store_off_point {
+ store_off_point (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lOffPoint (iChar.begin(), iChar.end());
+ _flightPeriod._itLeg._offPoint = lOffPoint;
+ //std::cout << "Off point: " << lOffPoint << std::endl;
+
+ // Add the airport code if it is not already stored in the airport lists
+ _flightPeriod.addAirport (lOffPoint);
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the board time. */
+template <typename FLIGHT_PERIOD>
+struct store_board_time {
+ store_board_time (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._itLeg._boardTime = _flightPeriod.getTime();
+
+ //std::cout << "Board time: "
+ //<< _flightPeriod._itLeg._boardTime << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+
+ // Reset the date off-set
+ _flightPeriod._dateOffSet = 0;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the off time. */
+template <typename FLIGHT_PERIOD>
+struct store_off_time {
+ store_off_time (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._itLeg._offTime = _flightPeriod.getTime();
+
+ //std::cout << "Off time: "
+ // << _flightPeriod._itLeg._offTime << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+
+ // As the board date off set is optional, it can be set only afterwards,
+ // based on the staging date off-set value (_flightPeriod._dateOffSet).
+ const boost::gregorian::date_duration lDateOffSet (_flightPeriod._dateOffSet);
+ _flightPeriod._itLeg._boardDateOffSet = lDateOffSet;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the elapsed time. */
+template <typename FLIGHT_PERIOD>
+struct store_elapsed_time {
+ store_elapsed_time (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+
+ _flightPeriod._itLeg._elapsed = _flightPeriod.getTime();
+
+ //std::cout << "Elapsed time: "
+ // << _flightPeriod._itLeg._elapsed << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+
+ // As the board date off set is optional, it can be set only afterwards,
+ // based on the staging date off-set value (_flightPeriod._dateOffSet).
+ const boost::gregorian::date_duration lDateOffSet (_flightPeriod._dateOffSet);
+ _flightPeriod._itLeg._offDateOffSet = lDateOffSet;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
/** Store the parsed cabin code. */
template <typename FLIGHT_PERIOD>
struct store_cabin_code {
store_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (char iChar, boost::spirit::qi::unused_type,
+ void operator() (char iChar,
+ boost::spirit::qi::unused_type,
boost::spirit::qi::unused_type) const {
- _flightPeriod._cabinCode = iChar;
- // std::cout << "Cabin code: " << lCabinCode << std::endl;
+ _flightPeriod._itCabin._cabinCode = iChar;
+ //std::cout << "Cabin code: " << _flightPeriod._itCabin._cabinCode << std::endl;
}
FLIGHT_PERIOD& _flightPeriod;
};
+
+/** Store the parsed capacity. */
+template <typename FLIGHT_PERIOD>
+struct store_capacity {
+ store_capacity (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (double iReal,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._itCabin._capacity = iReal;
+ //std::cout << "Capacity: " << iReal << std::endl;
+
+ // The capacity is the last (according to arrival order) detail
+ // of the cabin. Hence, when a capacity is parsed, it means that
+ // the full cabin details have already been parsed as well: the
+ // cabin can thus be added to the leg.
+ _flightPeriod._itLeg._cabinList.push_back (_flightPeriod._itCabin);
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store whether or not all the segments are the same. */
+template <typename FLIGHT_PERIOD>
+struct store_segment_specificity {
+ store_segment_specificity (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (char iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ if (iChar == '0') {
+ _flightPeriod._areSegmentDefinitionsSpecific = false;
+ } else {
+ _flightPeriod._areSegmentDefinitionsSpecific = true;
+ }
+
+ // Do a few sanity checks: the two lists should get exactly the same
+ // content (in terms of airport codes). The only difference is that one
+ // is a STL set, and the other a STL vector.
+ assert (_flightPeriod._airportList.size()
+ == _flightPeriod._airportOrderedList.size());
+ assert (_flightPeriod._airportList.size() >= 2);
+
+ // Since all the legs have now been parsed, we get all the airports
+ // and the segments may be built.
+ _flightPeriod.buildSegments();
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the board point of the segment. */
+template <typename FLIGHT_PERIOD>
+struct store_segment_board_point {
+ store_segment_board_point (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lBoardPoint (iChar.begin(), iChar.end());
+ _flightPeriod._itSegment._boardPoint = lBoardPoint;
+ //std::cout << "Board point: " << lBoardPoint << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the off point of the segment. */
+template <typename FLIGHT_PERIOD>
+struct store_segment_off_point {
+ store_segment_off_point (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lOffPoint (iChar.begin(), iChar.end());
+ _flightPeriod._itSegment._offPoint = lOffPoint;
+ //std::cout << "Off point: " << lOffPoint << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the cabin code of the segment. */
+template <typename FLIGHT_PERIOD>
+struct store_segment_cabin_code {
+ store_segment_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (char iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ _flightPeriod._itSegmentCabin._cabinCode = iChar;
+ //std::cout << "Cabin code: " << iChar << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the classes of the segment-cabin. */
+template <typename FLIGHT_PERIOD>
+struct store_classes {
+ store_classes (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (std::vector<char> iChar,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ std::string lClasses (iChar.begin(), iChar.end());
+ _flightPeriod._itSegmentCabin._classes = lClasses;
+ //std::cout << "Classes: " << lClasses << std::endl;
+
+ // The list of classes is the last (according to the arrival order
+ // within the schedule input file) detail of the segment cabin. Hence,
+ // when a list of classes is parsed, it means that the full segment
+ // cabin details have already been parsed as well: the segment cabin
+ // can thus be added to the segment.
+ if (_flightPeriod._areSegmentDefinitionsSpecific == true) {
+ _flightPeriod.addSegmentCabin (_flightPeriod._itSegment,
+ _flightPeriod._itSegmentCabin);
+ } else {
+ _flightPeriod.addSegmentCabin (_flightPeriod._itSegmentCabin);
+ }
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+/** Mark the end of the flight-period parsing. */
+template <typename FLIGHT_PERIOD>
+struct do_end_flight {
+ do_end_flight (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
+ //std::cout << "End of Flight-Period " << std::endl;
+ assert (_flightPeriod._legAlreadyDefined == true);
+ _flightPeriod._legList.push_back (_flightPeriod._itLeg);
+
+ // Display the result
+ _flightPeriod.display();
+
+ // The lists of legs and cabins must be reset
+ _flightPeriod._legAlreadyDefined = false;
+ _flightPeriod._itLeg._cabinList.clear();
+
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
// /////////// Utilities /////////////
/** 1-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 1, 1> int1_p;
+boost::spirit::qi::int_parser<unsigned int, 10, 1, 1> int1_p;
/** 2-digit-integer parser */
boost::spirit::qi::uint_parser<int, 10, 2, 2> ...
[truncated message content] |
|
From: <den...@us...> - 2010-11-10 20:15:53
|
Revision: 155
http://dsim.svn.sourceforge.net/dsim/?rev=155&view=rev
Author: denis_arnaud
Date: 2010-11-10 20:15:47 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[Boost Test] Fixed the Boost.Spirit make-file.
Modified Paths:
--------------
trunk/dsim/test/boost/spirit/Makefile.am
Modified: trunk/dsim/test/boost/spirit/Makefile.am
===================================================================
--- trunk/dsim/test/boost/spirit/Makefile.am 2010-11-10 19:53:22 UTC (rev 154)
+++ trunk/dsim/test/boost/spirit/Makefile.am 2010-11-10 20:15:47 UTC (rev 155)
@@ -7,6 +7,10 @@
num_list1_parser roman_parser sum_parser \
schedule_parser stream_iterator_parser levenshtein
+levenshtein_SOURCES = levenshtein.cpp
+levenshtein_CXXFLAGS =
+levenshtein_LDFLAGS =
+
employee_parser_SOURCES = employee_parser.cpp
employee_parser_CXXFLAGS = $(BOOST_CFLAGS)
employee_parser_LDADD = $(BOOST_LIBS)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-11-10 19:53:28
|
Revision: 154
http://dsim.svn.sourceforge.net/dsim/?rev=154&view=rev
Author: denis_arnaud
Date: 2010-11-10 19:53:22 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[Test] Removed generated binaries.
Removed Paths:
-------------
trunk/dsim/test/boost/spirit/action_parser
trunk/dsim/test/boost/spirit/complex_parser
trunk/dsim/test/boost/spirit/employee_parser
trunk/dsim/test/boost/spirit/num_list1_parser
trunk/dsim/test/boost/spirit/roman_parser
trunk/dsim/test/boost/spirit/stream_iterator_parser
trunk/dsim/test/boost/spirit/sum_parser
Property Changed:
----------------
trunk/dsim/test/boost/spirit/
Property changes on: trunk/dsim/test/boost/spirit
___________________________________________________________________
Modified: svn:ignore
- .deps
.libs
Makefile.in
Makefile
levenshtein
parameter_parser
search_string_parser
schedule_parser
full_calculator
spirit_parser
subrule_parser
number_parser
functor_parser
+ .deps
.libs
Makefile.in
Makefile
levenshtein
parameter_parser
search_string_parser
schedule_parser
full_calculator
spirit_parser
subrule_parser
number_parser
functor_parser
stream_iterator_parser
complex_parser
num_list1_parser
roman_parser
action_parser
employee_parser
sum_parser
Deleted: trunk/dsim/test/boost/spirit/action_parser
===================================================================
(Binary files differ)
Deleted: trunk/dsim/test/boost/spirit/complex_parser
===================================================================
(Binary files differ)
Deleted: trunk/dsim/test/boost/spirit/employee_parser
===================================================================
(Binary files differ)
Deleted: trunk/dsim/test/boost/spirit/num_list1_parser
===================================================================
(Binary files differ)
Deleted: trunk/dsim/test/boost/spirit/roman_parser
===================================================================
(Binary files differ)
Deleted: trunk/dsim/test/boost/spirit/stream_iterator_parser
===================================================================
(Binary files differ)
Deleted: trunk/dsim/test/boost/spirit/sum_parser
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-11-10 18:18:42
|
Revision: 153
http://dsim.svn.sourceforge.net/dsim/?rev=153&view=rev
Author: denis_arnaud
Date: 2010-11-10 18:18:36 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[Boost Test] Re-activated the Spirit v2 parser tests, as they now work (but they are still limited).
Modified Paths:
--------------
trunk/dsim/test/boost/Makefile.am
trunk/dsim/test/boost/random/SimulateTestSuite.log
trunk/dsim/test/boost/spiritQi/Makefile.am
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
Modified: trunk/dsim/test/boost/Makefile.am
===================================================================
--- trunk/dsim/test/boost/Makefile.am 2010-11-10 17:57:20 UTC (rev 152)
+++ trunk/dsim/test/boost/Makefile.am 2010-11-10 18:18:36 UTC (rev 153)
@@ -6,6 +6,6 @@
##
SUBDIRS = accumulators asio filesystem intrusive mpi mpl \
- serialization signals spirit smart_pointers
+ serialization signals spirit spiritQi smart_pointers
EXTRA_DIST =
Modified: trunk/dsim/test/boost/random/SimulateTestSuite.log
===================================================================
--- trunk/dsim/test/boost/random/SimulateTestSuite.log 2010-11-10 17:57:20 UTC (rev 152)
+++ trunk/dsim/test/boost/random/SimulateTestSuite.log 2010-11-10 18:18:36 UTC (rev 153)
@@ -19,7 +19,7 @@
Simulation#; Sum of Lambdas; Total nb of events; Random draw (following normal law);
9; 299.178; 303; 276.597;
Statistics for sum of Lambdas (min, max, mean, variance);
-299.178, 299.178, 299.178, 8.5123e-12;
+299.178, 299.178, 299.178, 0;
Statistics for total nb of events (min, max, mean, variance);
286, 336, 301.3, 193.41;
Statistics for random draws (min, max, mean, variance);
Modified: trunk/dsim/test/boost/spiritQi/Makefile.am
===================================================================
--- trunk/dsim/test/boost/spiritQi/Makefile.am 2010-11-10 17:57:20 UTC (rev 152)
+++ trunk/dsim/test/boost/spiritQi/Makefile.am 2010-11-10 18:18:36 UTC (rev 153)
@@ -5,7 +5,7 @@
check_PROGRAMS = employee_parser action_parser complex_parser \
num_list1_parser roman_parser sum_parser \
- schedule_parser stream_iterator_parser levenshtein
+ schedule_parser stream_iterator_parser
employee_parser_SOURCES = employee_parser.cpp
employee_parser_CXXFLAGS = $(BOOST_CFLAGS)
Modified: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-10 17:57:20 UTC (rev 152)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-10 18:18:36 UTC (rev 153)
@@ -52,7 +52,8 @@
store_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
: _flightPeriod (ioFlightPeriod) {}
- void operator() (char iChar) const {
+ void operator() (char iChar, boost::spirit::qi::unused_type,
+ boost::spirit::qi::unused_type) const {
_flightPeriod._cabinCode = iChar;
// std::cout << "Cabin code: " << lCabinCode << std::endl;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-11-10 17:57:26
|
Revision: 152
http://dsim.svn.sourceforge.net/dsim/?rev=152&view=rev
Author: denis_arnaud
Date: 2010-11-10 17:57:20 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[Boost Test] De-activated (temporarily) the Spirit v2 parser tests.
Modified Paths:
--------------
trunk/dsim/test/boost/Makefile.am
Modified: trunk/dsim/test/boost/Makefile.am
===================================================================
--- trunk/dsim/test/boost/Makefile.am 2010-11-10 17:56:17 UTC (rev 151)
+++ trunk/dsim/test/boost/Makefile.am 2010-11-10 17:57:20 UTC (rev 152)
@@ -6,6 +6,6 @@
##
SUBDIRS = accumulators asio filesystem intrusive mpi mpl \
- serialization signals spirit spiritQi smart_pointers
+ serialization signals spirit smart_pointers
EXTRA_DIST =
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-11-10 17:56:24
|
Revision: 151
http://dsim.svn.sourceforge.net/dsim/?rev=151&view=rev
Author: denis_arnaud
Date: 2010-11-10 17:56:17 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[Boost Test] The (classic) Spirit parser is back to working version for the schedule parsing.
Modified Paths:
--------------
trunk/dsim/test/boost/spirit/action_parser
trunk/dsim/test/boost/spirit/complex_parser
trunk/dsim/test/boost/spirit/employee_parser
trunk/dsim/test/boost/spirit/num_list1_parser
trunk/dsim/test/boost/spirit/roman_parser
trunk/dsim/test/boost/spirit/schedule_parser.cpp
trunk/dsim/test/boost/spirit/stream_iterator_parser
trunk/dsim/test/boost/spirit/sum_parser
Modified: trunk/dsim/test/boost/spirit/action_parser
===================================================================
(Binary files differ)
Modified: trunk/dsim/test/boost/spirit/complex_parser
===================================================================
(Binary files differ)
Modified: trunk/dsim/test/boost/spirit/employee_parser
===================================================================
(Binary files differ)
Modified: trunk/dsim/test/boost/spirit/num_list1_parser
===================================================================
(Binary files differ)
Modified: trunk/dsim/test/boost/spirit/roman_parser
===================================================================
(Binary files differ)
Modified: trunk/dsim/test/boost/spirit/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-10 17:25:14 UTC (rev 150)
+++ trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-10 17:56:17 UTC (rev 151)
@@ -1,25 +1,130 @@
// STL
-#include <istream>
+#include <cassert>
+#include <iostream>
#include <sstream>
-#include <iostream>
#include <fstream>
+#include <string>
+#include <map>
#include <set>
#include <vector>
// Boost (Extended STL)
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.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/phoenix_object.hpp>
-#include <boost/fusion/include/adapt_struct.hpp>
-#include <boost/spirit/include/support_multi_pass.hpp>
-#include <boost/fusion/include/io.hpp>
-#include <boost/lambda/lambda.hpp>
+//#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>
+// Type definitions
+typedef char char_t;
+//typedef char const* iterator_t;
+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::string::const_iterator iterator_t;
+/** LegCabin-Details. */
+struct Cabin_T {
+ // Attributes
+ std::string _cabinCode;
+ double _capacity;
+
+ void display() const {
+ std::cout << " " << _cabinCode << " " << _capacity << ", ";
+ }
+};
+
+/** List of Cabin-Detail strucutres. */
+typedef std::vector<Cabin_T> CabinList_T;
+
+/** Leg. */
+struct Leg_T {
+ // Attributes
+ std::string _boardPoint;
+ boost::posix_time::time_duration _boardTime;
+ boost::gregorian::date_duration _boardDateOffSet;
+ std::string _offPoint;
+ boost::posix_time::time_duration _offTime;
+ boost::gregorian::date_duration _offDateOffSet;
+ boost::posix_time::time_duration _elapsed;
+ CabinList_T _cabinList;
+
+ /** Constructor. */
+ Leg_T () : _boardDateOffSet (0), _offDateOffSet (0) {}
+
+ void display() const {
+ std::cout << " " << _boardPoint << " / "
+ << boost::posix_time::to_simple_string (_boardTime)
+ << " -- " << _offPoint << " / "
+ << boost::posix_time::to_simple_string (_offTime)
+ << " --> " << boost::posix_time::to_simple_string (_elapsed)
+ << std::endl;
+ for (CabinList_T::const_iterator itCabin = _cabinList.begin();
+ itCabin != _cabinList.end(); itCabin++) {
+ const Cabin_T& lCabin = *itCabin;
+ lCabin.display();
+ }
+ std::cout << std::endl;
+ }
+};
+
+/** List of Leg strucutres. */
+typedef std::vector<Leg_T> LegList_T;
+
+/** SegmentCabin-Details. */
+struct SegmentCabin_T {
+ // Attributes
+ std::string _cabinCode;
+ std::string _classes;
+
+ void display() const {
+ std::cout << " " << _cabinCode << " " << _classes << ", ";
+ }
+};
+
+/** List of SegmentCabin-Detail strucutres. */
+typedef std::vector<SegmentCabin_T> SegmentCabinList_T;
+
+/** Segment. */
+struct Segment_T {
+ // Attributes
+ std::string _boardPoint;
+ boost::posix_time::time_duration _boardTime;
+ boost::gregorian::date_duration _boardDateOffSet;
+ std::string _offPoint;
+ boost::posix_time::time_duration _offTime;
+ boost::gregorian::date_duration _offDateOffSet;
+ boost::posix_time::time_duration _elapsed;
+ SegmentCabinList_T _cabinList;
+
+ /** Constructor. */
+ Segment_T () : _boardDateOffSet (0), _offDateOffSet (0) {}
+
+ void display() const {
+ std::cout << " " << _boardPoint << " / "
+ << boost::posix_time::to_simple_string (_boardTime)
+ << " -- " << _offPoint << " / "
+ << boost::posix_time::to_simple_string (_offTime)
+ << " --> " << boost::posix_time::to_simple_string (_elapsed)
+ << std::endl;
+ for (SegmentCabinList_T::const_iterator itCabin = _cabinList.begin();
+ itCabin != _cabinList.end(); itCabin++) {
+ const SegmentCabin_T& lCabin = *itCabin;
+ lCabin.display();
+ }
+ std::cout << std::endl;
+ }
+};
+
+/** List of Segment strucutres. */
+typedef std::vector<Segment_T> SegmentList_T;
+
/** Flight-Period. */
struct FlightPeriod_T {
// Attributes
@@ -28,225 +133,778 @@
boost::gregorian::date _dateRangeStart;
boost::gregorian::date _dateRangeEnd;
std::string _dow;
- std::string _cabinCode;
-};
+ LegList_T _legList;
+ SegmentList_T _segmentList;
+
+ /** Constructor. */
+ FlightPeriod_T () : _legAlreadyDefined (false), _itSeconds (0) {}
-/** Store the parsed airline code. */
-template <typename FLIGHT_PERIOD>
-struct store_airline_code {
- store_airline_code (FLIGHT_PERIOD& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lAirlineCode (iStr, iStrEnd);
- _flightPeriod._airlineCode = lAirlineCode;
- // std::cout << "Airline code: " << lAirlineCode << std::endl;
+ /** Set the date from the staging details. */
+ boost::gregorian::date getDate() const {
+ return boost::gregorian::date (_itYear, _itMonth, _itDay);
}
+
+ /** Set the time from the staging details. */
+ boost::posix_time::time_duration getTime() const {
+ return boost::posix_time::hours (_itHours)
+ + boost::posix_time::minutes (_itMinutes)
+ + boost::posix_time::seconds (_itSeconds);
+ }
+
+ void display() const {
+ std::cout << _airlineCode << _flightNumber
+ << ", " << boost::gregorian::to_simple_string (_dateRangeStart)
+ << " - " << boost::gregorian::to_simple_string (_dateRangeEnd)
+ << " - " << _dow
+ << std::endl;
- FLIGHT_PERIOD& _flightPeriod;
-};
+ for (LegList_T::const_iterator itLeg = _legList.begin();
+ itLeg != _legList.end(); itLeg++) {
+ const Leg_T& lLeg = *itLeg;
+ lLeg.display();
+ }
-/** Store the parsed cabin code. */
-template <typename FLIGHT_PERIOD>
-struct store_cabin_code {
- store_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
+ for (SegmentList_T::const_iterator itSegment = _segmentList.begin();
+ itSegment != _segmentList.end(); itSegment++) {
+ const Segment_T& lSegment = *itSegment;
+ lSegment.display();
+ }
- void operator() (char iChar) const {
- _flightPeriod._cabinCode = iChar;
- // std::cout << "Cabin code: " << lCabinCode << std::endl;
+ //std::cout << "[Debug] - Staging Leg: ";
+ //_itLeg.display();
+ //std::cout << "[Debug] - Staging Cabin: ";
+ //_itCabin.display();
+ //std::cout << "[Debug] - Staging Segment: ";
+ //_itSegment.display();
}
+
+ /** Add the given airport to the internal lists (if not already existing). */
+ void addAirport (const std::string& iAirport) {
+ std::set<std::string>::const_iterator itAirport =
+ _airportList.find (iAirport);
+ if (itAirport == _airportList.end()) {
+ // Add the airport code to the airport set
+ const bool insertSuccessful = _airportList.insert (iAirport).second;
+
+ if (insertSuccessful == false) {
+ // TODO: throw an exception
+ }
+ // Add the airport code to the airport vector
+ _airportOrderedList.push_back (iAirport);
+ }
+ }
+
+ /** Build the routing (segments). */
+ void buildSegments () {
+ // The list of airports encompasses all the airports on which
+ // the flight takes off or lands. Moreover, that list is
+ // time-ordered: the first airport is the initial departure of
+ // the flight, and the last airport is the eventual point of
+ // rest of the flight.
+ // Be l the size of the ordered list of airports.
+ // We want to generate all the segment combinations from the legs
+ // and, hence, from all the possible (time-ordered) airport pairs.
+ // Thus, we both iterator on i=0...l-1 and j=i+1...l
+ assert (_airportOrderedList.size() >= 2);
+
+ _segmentList.clear();
+ for (std::vector<std::string>::const_iterator itAirport_i =
+ _airportOrderedList.begin();
+ itAirport_i != _airportOrderedList.end()-1; ++itAirport_i) {
+ for (std::vector<std::string>::const_iterator itAirport_j =
+ itAirport_i + 1;
+ itAirport_j != _airportOrderedList.end(); ++itAirport_j) {
+ Segment_T lSegment;
+ lSegment._boardPoint = *itAirport_i;
+ lSegment._offPoint = *itAirport_j;
+
+ _segmentList.push_back (lSegment);
+ }
+ }
+
+ // Clear the lists of airports, so that it is ready for the next flight
+ _airportList.clear();
+ _airportOrderedList.clear();
+ }
+
+ /** Add, to the Segment whose key corresponds to the
+ given (board point, off point) pair, the specific segment cabin
+ details (mainly, the list of the class codes).
+ <br>Note that the Segment structure is retrieved from the internal
+ list, already filled by a previous step (the buildSegments()
+ method). */
+ void addSegmentCabin (const Segment_T& iSegment,
+ const SegmentCabin_T& iCabin) {
+ // Retrieve the Segment structure corresponding to the (board, off) point
+ // pair.
+ SegmentList_T::iterator itSegment = _segmentList.begin();
+ for ( ; itSegment != _segmentList.end(); ++itSegment) {
+ const Segment_T& lSegment = *itSegment;
+
+ const std::string& lBoardPoint = iSegment._boardPoint;
+ const std::string& lOffPoint = iSegment._offPoint;
+ if (lSegment._boardPoint == lBoardPoint
+ && lSegment._offPoint == lOffPoint) {
+ break;
+ }
+ }
- FLIGHT_PERIOD& _flightPeriod;
+ // If the segment key (airport pair) given in the schedule input file
+ // does not correspond to the leg (board, off) points, throw an exception
+ // so that the user knows the schedule input file is corrupted.
+ if (itSegment == _segmentList.end()) {
+ std::cerr << "Within the schedule input file, there is a flight for which the airports of segments and those of the legs do not correspond.";
+ throw std::exception();
+ }
+
+ // Add the Cabin structure to the Segment Cabin structure.
+ assert (itSegment != _segmentList.end());
+ Segment_T& lSegment = *itSegment;
+ lSegment._cabinList.push_back (iCabin);
+ }
+
+ /** Add, to all the Segment, the general segment cabin details
+ (mainly, the list of the class codes).
+ <br>Note that the Segment structures are stored within the internal
+ list, already filled by a previous step (the buildSegments()
+ method). */
+ void addSegmentCabin (const SegmentCabin_T& iCabin) {
+ // Iterate on all the Segment (as they get the same cabin definitions)
+ for (SegmentList_T::iterator itSegment = _segmentList.begin();
+ itSegment != _segmentList.end(); ++itSegment) {
+ Segment_T& lSegment = *itSegment;
+ lSegment._cabinList.push_back (iCabin);
+ }
+ }
+
+ /** Staging Leg (resp. Cabin) structure, gathering the result of the iteration
+ on one leg (resp. cabin). */
+ bool _legAlreadyDefined;
+ Leg_T _itLeg;
+ Cabin_T _itCabin;
+
+ /** Staging Date. */
+ unsigned int _itYear;
+ unsigned int _itMonth;
+ unsigned int _itDay;
+
+ /** Staging Time. */
+ long _itHours;
+ long _itMinutes;
+ long _itSeconds;
+ int _dateOffSet;
+
+ /** Staging Airport List (helper to derive the list of Segment
+ structures). */
+ std::set<std::string> _airportList;
+ std::vector<std::string> _airportOrderedList;
+
+ /** Staging Segment-related attributes. */
+ bool _areSegmentDefinitionsSpecific;
+ Segment_T _itSegment;
+ SegmentCabin_T _itSegmentCabin;
};
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Semantic actions
+//
+///////////////////////////////////////////////////////////////////////////////
+namespace {
+ /** Store the parsed airline code. */
+ struct store_airline_code {
+ store_airline_code (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lAirlineCode (iStr, iStrEnd);
+ _flightPeriod._airlineCode = lAirlineCode;
+ // std::cout << "Airline code: " << lAirlineCode << std::endl;
-// /////////// Utilities /////////////
+ // As that's the beginning of a new flight, the list of legs must be reset
+ _flightPeriod._legList.clear();
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the parsed flight number. */
+ struct store_flight_number {
+ store_flight_number (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
-/** 1-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 1, 1> int1_p;
+ void operator() (unsigned int iNumber) const {
+ _flightPeriod._flightNumber = iNumber;
+ // std::cout << "Flight number: " << iNumber << std::endl;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the start of the date range. */
+ struct store_date_range_start {
+ store_date_range_start (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ _flightPeriod._dateRangeStart = _flightPeriod.getDate();
+ // std::cout << "Date Range Start: "
+ // << _flightPeriod._dateRangeStart << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
-/** 2-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p;
+ /** Store the end of the date range. */
+ struct store_date_range_end {
+ store_date_range_end (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ _flightPeriod._dateRangeEnd = _flightPeriod.getDate();
+ // std::cout << "Date Range End: "
+ // << _flightPeriod._dateRangeEnd << std::endl;
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
-/** 4-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p;
+ /** Store the DOW (day of the Week). */
+ struct store_dow {
+ store_dow (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
-/** Up-to-4-digit-integer parser */
-boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p;
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lDow (iStr, iStrEnd);
+ _flightPeriod._dow = lDow;
+ // std::cout << "DOW: " << lDow << std::endl;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+ /** Store the parsed board point. */
+ struct store_board_point {
+ store_board_point (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lBoardPoint (iStr, iStrEnd);
+ // std::cout << "Board point: " << lBoardPoint << std::endl;
+
+ // If a leg has already been parsed, add it to the FlightPeriod
+ if (_flightPeriod._legAlreadyDefined == true) {
+ _flightPeriod._legList.push_back (_flightPeriod._itLeg);
+ } else {
+ _flightPeriod._legAlreadyDefined = true;
+ }
+
+ // Set the (new) board point
+ _flightPeriod._itLeg._boardPoint = lBoardPoint;
+
+ // As that's the beginning of a new leg, the list of cabins must be reset
+ _flightPeriod._itLeg._cabinList.clear();
+
+ // Add the airport code if it is not already stored in the airport lists
+ _flightPeriod.addAirport (lBoardPoint);
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
-////////////////////////////////////////////////////////////////////////////
-// Parser
-////////////////////////////////////////////////////////////////////////////
-template <typename ITERATOR, typename FLIGHT_PERIOD>
-struct FlightPeriodParser :
- boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type > {
+ /** Store the parsed off point. */
+ struct store_off_point {
+ store_off_point (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
- typedef store_airline_code<FLIGHT_PERIOD> store_airline_code_t;
- typedef store_cabin_code<FLIGHT_PERIOD> store_cabin_code_t;
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lOffPoint (iStr, iStrEnd);
+ _flightPeriod._itLeg._offPoint = lOffPoint;
+ // std::cout << "Off point: " << lOffPoint << std::endl;
+
+ // Add the airport code if it is not already stored in the airport lists
+ _flightPeriod.addAirport (lOffPoint);
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the board time. */
+ struct store_board_time {
+ store_board_time (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ _flightPeriod._itLeg._boardTime = _flightPeriod.getTime();
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+
+ // Reset the date off-set
+ _flightPeriod._dateOffSet = 0;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the off time. */
+ struct store_off_time {
+ store_off_time (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ _flightPeriod._itLeg._offTime = _flightPeriod.getTime();
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+
+ // As the board date off set is optional, it can be set only afterwards,
+ // based on the staging date off-set value (_flightPeriod._dateOffSet).
+ const boost::gregorian::date_duration lDateOffSet (_flightPeriod._dateOffSet);
+ _flightPeriod._itLeg._boardDateOffSet = lDateOffSet;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the elapsed time. */
+ struct store_elapsed_time {
+ store_elapsed_time (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ _flightPeriod._itLeg._elapsed = _flightPeriod.getTime();
+
+ // Reset the number of seconds
+ _flightPeriod._itSeconds = 0;
+
+ // As the board date off set is optional, it can be set only afterwards,
+ // based on the staging date off-set value (_flightPeriod._dateOffSet).
+ const boost::gregorian::date_duration lDateOffSet (_flightPeriod._dateOffSet);
+ _flightPeriod._itLeg._offDateOffSet = lDateOffSet;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the parsed cabin code. */
+ struct store_cabin_code {
+ store_cabin_code (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (char iChar) const {
+ _flightPeriod._itCabin._cabinCode = iChar;
+ // std::cout << "Cabin code: " << iChar << std::endl;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
- FLIGHT_PERIOD _t;
+ /** Store the parsed capacity. */
+ struct store_capacity {
+ store_capacity (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
- FlightPeriodParser () :
- FlightPeriodParser::base_type(start) {
+ void operator() (double iReal) const {
+ _flightPeriod._itCabin._capacity = iReal;
+ // std::cout << "Capacity: " << iReal << std::endl;
- using boost::spirit::ascii::string;
- using boost::spirit::ascii::char_;
- using boost::spirit::qi::lexeme;
- using boost::spirit::qi::repeat;
- using boost::spirit::qi::double_;
- using boost::lambda::_1;
+ // The capacity is the last (according to arrival order) detail
+ // of the cabin. Hence, when a capacity is parsed, it means that
+ // the full cabin details have already been parsed as well: the
+ // cabin can thus be added to the leg.
+ _flightPeriod._itLeg._cabinList.push_back (_flightPeriod._itCabin);
+ }
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store whether or not all the segments are the same. */
+ struct store_segment_specificity {
+ store_segment_specificity (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
- start = (comment | flight_period) ;
+ void operator() (char iChar) const {
+ if (iChar == '0') {
+ _flightPeriod._areSegmentDefinitionsSpecific = false;
+ } else {
+ _flightPeriod._areSegmentDefinitionsSpecific = true;
+ }
- comment = lexeme[ (repeat(2)[char_("/")]) ] >> *(char_);
+ // Do a few sanity checks: the two lists should get exactly the same
+ // content (in terms of airport codes). The only difference is that one
+ // is a STL set, and the other a STL vector.
+ assert (_flightPeriod._airportList.size()
+ == _flightPeriod._airportOrderedList.size());
+ assert (_flightPeriod._airportList.size() >= 2);
+
+ // Since all the legs have now been parsed, we get all the airports
+ // and the segments may be built.
+ _flightPeriod.buildSegments();
+ }
- flight_period = airline_code
- >> ';' >> flight_number
- >> ';' >> date
- >> ';' >> date
- >> ';' >> dow
- >> ';'
- >> leg_list
- >> segment_list
- ;
+ FlightPeriod_T& _flightPeriod;
+ };
- airline_code = lexeme[ (repeat(2)[char_("A-Z")]) ];
+ /** Store the board point of the segment. */
+ struct store_segment_board_point {
+ store_segment_board_point (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lBoardPoint (iStr, iStrEnd);
+ _flightPeriod._itSegment._boardPoint = lBoardPoint;
+ // std::cout << "Board point: " << lBoardPoint << std::endl;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the off point of the segment. */
+ struct store_segment_off_point {
+ store_segment_off_point (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lOffPoint (iStr, iStrEnd);
+ _flightPeriod._itSegment._offPoint = lOffPoint;
+ // std::cout << "Off point: " << lOffPoint << std::endl;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the off point of the segment. */
+ struct store_segment_cabin_code {
+ store_segment_cabin_code (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+ void operator() (char iChar) const {
+ _flightPeriod._itSegmentCabin._cabinCode = iChar;
+ // std::cout << "Cabin code: " << iChar << std::endl;
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Store the classes of the segment-cabin. */
+ struct store_classes {
+ store_classes (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lClasses (iStr, iStrEnd);
+ _flightPeriod._itSegmentCabin._classes = lClasses;
+ // std::cout << "Classes: " << lClasses << std::endl;
+
+ // The list of classes is the last (according to the arrival order
+ // within the schedule input file) detail of the segment cabin. Hence,
+ // when a list of classes is parsed, it means that the full segment
+ // cabin details have already been parsed as well: the segment cabin
+ // can thus be added to the segment.
+ if (_flightPeriod._areSegmentDefinitionsSpecific == true) {
+ _flightPeriod.addSegmentCabin (_flightPeriod._itSegment,
+ _flightPeriod._itSegmentCabin);
+ } else {
+ _flightPeriod.addSegmentCabin (_flightPeriod._itSegmentCabin);
+ }
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+
+ /** Mark the end of the flight-period parsing. */
+ struct do_end_flight {
+ do_end_flight (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ // void operator() (char iChar) const {
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ // std::cout << "End of Flight-Period " << std::endl;
+
+ assert (_flightPeriod._legAlreadyDefined == true);
+ _flightPeriod._legList.push_back (_flightPeriod._itLeg);
- flight_number = uint1_4_p;
+ // The lists of legs and cabins must be reset
+ _flightPeriod._legAlreadyDefined = false;
+ _flightPeriod._itLeg._cabinList.clear();
+
+ // Display the result
+ _flightPeriod.display();
+ }
+
+ FlightPeriod_T& _flightPeriod;
+ };
+}
+
+// /////////// Utilities /////////////
+/** 1-digit-integer parser */
+boost::spirit::classic::int_parser<unsigned int, 10, 1, 1> int1_p;
+/** 2-digit-integer parser */
+boost::spirit::classic::uint_parser<int, 10, 2, 2> uint2_p;
+/** 4-digit-integer parser */
+boost::spirit::classic::uint_parser<int, 10, 4, 4> uint4_p;
+/** Up-to-4-digit-integer parser */
+boost::spirit::classic::uint_parser<int, 10, 1, 4> uint1_4_p;
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Our calculator grammar (using subrules)
+//
+///////////////////////////////////////////////////////////////////////////////
+ /**
+ AirlineCode; FlightNumber; DateRangeStart; DateRangeEnd; DOW;
+ (list) BoardPoint; OffPoint; BoardTime; DateOffSet; OffTime;
+ ElapsedTime;
+ (list) CabinCode; Capacity;
+ SegmentSpecificty (0 or 1);
+ (list) (optional BoardPoint; OffPoint); CabinCode; Classes
+
+ BA; 9; 2007-04-20; 2007-06-30; 0000011;
+ LHR; BKK; 22:00; 15:15 / +1; 11:15; F; 5; J; 12; W; 20; Y; 300;
+ BKK; SYD; 18:10 / +1; 06:05 / +2; 08:55; F; 5; J; 12; W; 20; Y; 300;
+ 0; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+ BA; 9; 2007-04-20; 2007-06-30; 1111100;
+ LHR; BKK; 22:00; 15:15 / +1; 11:15; F; 5; J; 12; W; 20; Y; 300;
+ BKK; SYD; 18:10 / +1; 06:05 / +2; 08:55; F; 5; J; 12; W; 20; Y; 300;
+ 1; LHR; BKK; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+ BKK; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+ LHR; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+
+ Grammar:
+ DOW ::= int
+ FlightKey ::= AirlineCode ';' FlightNumber
+ ';' DateRangeStart ';' DateRangeEnd ';' DOW
+ LegKey ::= BoardPoint ';' OffPoint
+ LegDetails ::= BoardTime ['/' BoardDateOffSet]
+ ';' OffTime ['/' BoardDateOffSet]
+ ';' Elapsed
+ LegCabinDetails ::= CabinCode ';' Capacity
+ Leg ::= LegKey ';' LegDetails (';' CabinDetails)+
+ SegmentKey ::= BoardPoint ';' OffPoint
+ SegmentCabinDetails ::= CabinCode ';' Classes
+ FullSegmentCabinDetails::= (';' SegmentCabinDetails)+
+ GeneralSegments ::= '0' (';' SegmentCabinDetails)+
+ SpecificSegments ::= '1' (';' SegmentKey
+ ';' FullSegmentCabinDetails)+
+ Segment ::= GeneralSegment | SpecificSegment
+ FlightPeriod ::= FlightKey (';' Leg)+
+ (';' Segment)+ ';' EndOfFlight
+ EndOfFlight ::= ';'
+ */
+
+using namespace boost::spirit::classic;
+
+/** Grammar for the Flight-Period parser. */
+struct FlightPeriodParser :
+ public boost::spirit::classic::grammar<FlightPeriodParser> {
+
+ FlightPeriodParser (FlightPeriod_T& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {
+ }
+
+ template <typename ScannerT>
+ struct definition {
+ definition (FlightPeriodParser const& self) {
+
+ flight_period_list = *( boost::spirit::classic::comment_p("//")
+ | boost::spirit::classic::comment_p("/*", "*/")
+ | flight_period )
+ ;
- date = lexeme[ uint4_p
- >> '-' >> uint2_p
- >> '-' >> uint2_p ]
+ flight_period = flight_key
+ >> +( ';' >> leg )
+ >> +( ';' >> segment )
+ >> flight_period_end[do_end_flight(self._flightPeriod)]
;
- dow =
- lexeme[ repeat(7)[char_("0-1")] ]
+ flight_period_end =
+ boost::spirit::classic::ch_p(';')
;
+
+ flight_key = airline_code
+ >> ';' >> flight_number
+ >> ';' >> date[store_date_range_start(self._flightPeriod)]
+ >> ';' >> date[store_date_range_end(self._flightPeriod)]
+ >> ';' >> dow[store_dow(self._flightPeriod)]
+ ;
- leg_list = +(leg);
-
- leg = leg_key
- >> leg_details
- >> +(cabin_details)
+ airline_code =
+ lexeme_d[ (repeat_p(2,3)[chset_p("0-9A-Z")])[store_airline_code(self._flightPeriod)] ]
;
+
+ flight_number =
+ lexeme_d[ limit_d(0u, 9999u)[uint1_4_p][store_flight_number(self._flightPeriod)] ]
+ ;
+
+ date =
+ lexeme_d[ limit_d(2000u,2099u)[uint4_p][assign_a(self._flightPeriod._itYear)]
+ >> '-' >> limit_d(1u,12u)[uint2_p][assign_a(self._flightPeriod._itMonth)]
+ >> '-' >> limit_d(1u,31u)[uint2_p][assign_a(self._flightPeriod._itDay)] ]
+ ;
+
+ dow =
+ lexeme_d[ repeat_p(7)[chset_p("0-1")] ]
+ ;
+
+ leg = leg_key >> ';' >> leg_details >> +( ';' >> cabin_details )
+ ;
- leg_key =
- lexeme[ repeat(3)[char_("A-Z")] ]
- >> ';'
- >> lexeme[ repeat(3)[char_("A-Z")] ]
- >> ';'
- ;
+ leg_key =
+ (repeat_p(3)[chset_p("0-9A-Z")])[store_board_point(self._flightPeriod)]
+ >> ';'
+ >> (repeat_p(3)[chset_p("0-9A-Z")])[store_off_point(self._flightPeriod)]
+ ;
- leg_details =
- time
- >> ';' >> time
- >> ';' >> time
- >> ';'
- ;
+ leg_details =
+ time[store_board_time(self._flightPeriod)]
+ >> !(date_offset)
+ >> ';'
+ >> time[store_off_time(self._flightPeriod)]
+ >> !(date_offset)
+ >> ';'
+ >> time[store_elapsed_time(self._flightPeriod)]
+ ;
- time = lexeme[ uint2_p
- >> ':' >> uint2_p
- >> !(':' >> uint2_p) ]
- ;
-
- cabin_details = char_("A-Z") [store_cabin_code_t(_t)]
- >> ';' >> double_
- >> ';'
- ;
+ time = lexeme_d[ limit_d(0u,23u)[uint2_p][assign_a(self._flightPeriod._itHours)]
+ >> ':' >> limit_d(0u,59u)[uint2_p][assign_a(self._flightPeriod._itMinutes)]
+ >> !(':' >> limit_d(0u,59u)[uint2_p][assign_a(self._flightPeriod._itSeconds)]) ]
+ ;
- segment_key =
- repeat(3)[char_("0-9A-Z")]
- >> ';'
- >>repeat(3)[char_("0-9A-Z")]
- >> ';'
- ;
-
- segment_list = +(segment);
+ date_offset =
+ boost::spirit::classic::ch_p('/')
+ >> (int1_p)[boost::spirit::classic::assign_a(self._flightPeriod._dateOffSet)]
+ ;
+
+ cabin_details = (chset_p("A-Z"))[store_cabin_code(self._flightPeriod)]
+ >> ';' >> (boost::spirit::classic::ureal_p)[store_capacity(self._flightPeriod)]
+ ;
+
+ segment_key =
+ (repeat_p(3)[chset_p("0-9A-Z")])[store_segment_board_point(self._flightPeriod)]
+ >> ';'
+ >> (repeat_p(3)[chset_p("0-9A-Z")])[store_segment_off_point(self._flightPeriod)]
+ ;
- segment =
- general_segments | specific_segments
- ;
+ segment =
+ general_segments | specific_segments
+ ;
- general_segments =
- char_('0')
- >> ';'
- >> +(segment_cabin_details)
- ;
+ general_segments =
+ boost::spirit::classic::ch_p('0')[store_segment_specificity(self._flightPeriod)]
+ >> +(';' >> segment_cabin_details)
+ ;
- specific_segments =
- char_('1')
- >> ';'
- >> +(segment_key >> full_segment_cabin_details)
- ;
+ specific_segments =
+ boost::spirit::classic::ch_p('1')[store_segment_specificity(self._flightPeriod)]
+ >> +(';' >> segment_key >> full_segment_cabin_details)
+ ;
- full_segment_cabin_details =
- +(segment_cabin_details)
- ;
+ full_segment_cabin_details =
+ +(';' >> segment_cabin_details)
+ ;
- segment_cabin_details =
- char_("A-Z")
- >> ';' >> (repeat(1,26)[char_("A-Z")])
- >> ';'
- ;
-
- }
-
- boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> start,
- comment, flight_period, airline_code, flight_number, date, dow, leg, leg_list,
- leg_key, leg_details, time, cabin_details, segment, segment_list, segment_key,
- general_segments, specific_segments, full_segment_cabin_details, segment_cabin_details;
-
+ segment_cabin_details =
+ (chset_p("A-Z"))[store_segment_cabin_code(self._flightPeriod)]
+ >> ';' >> (repeat_p(1,26)[chset_p("A-Z")])[store_classes(self._flightPeriod)]
+ ;
+
+ BOOST_SPIRIT_DEBUG_NODE (flight_period_list);
+ BOOST_SPIRIT_DEBUG_NODE (flight_period);
+ BOOST_SPIRIT_DEBUG_NODE (flight_period_end);
+ BOOST_SPIRIT_DEBUG_NODE (flight_key);
+ BOOST_SPIRIT_DEBUG_NODE (airline_code);
+ BOOST_SPIRIT_DEBUG_NODE (flight_number);
+ BOOST_SPIRIT_DEBUG_NODE (date);
+ BOOST_SPIRIT_DEBUG_NODE (dow);
+ BOOST_SPIRIT_DEBUG_NODE (leg);
+ BOOST_SPIRIT_DEBUG_NODE (leg_key);
+ BOOST_SPIRIT_DEBUG_NODE (leg_details);
+ BOOST_SPIRIT_DEBUG_NODE (time);
+ BOOST_SPIRIT_DEBUG_NODE (date_offset);
+ BOOST_SPIRIT_DEBUG_NODE (cabin_details);
+ BOOST_SPIRIT_DEBUG_NODE (segment);
+ BOOST_SPIRIT_DEBUG_NODE (segment_key);
+ BOOST_SPIRIT_DEBUG_NODE (general_segments);
+ BOOST_SPIRIT_DEBUG_NODE (specific_segments);
+ BOOST_SPIRIT_DEBUG_NODE (full_segment_cabin_details);
+ BOOST_SPIRIT_DEBUG_NODE (segment_cabin_details);
+ }
+
+ boost::spirit::classic::rule<ScannerT> flight_period_list, flight_period,
+ flight_period_end, flight_key, airline_code, flight_number,
+ date, dow, leg, leg_key, leg_details, time, date_offset, cabin_details,
+ segment, segment_key, general_segments, specific_segments,
+ full_segment_cabin_details, segment_cabin_details;
+
+ boost::spirit::classic::rule<ScannerT> const& start() const { return flight_period_list; }
+ };
+
+ FlightPeriod_T& _flightPeriod;
};
-
-////////////////////////////////////////////////////////////////////////////
-// Main program
-////////////////////////////////////////////////////////////////////////////
+// /////////////// M A I N /////////////////
int main (int argc, char* argv[]) {
+ try {
+
+ // File to be parsed
+ std::string lFilename ("world_schedule.csv");
+
+ // Read the command-line parameters
+ if (argc >= 1 && argv[1] != NULL) {
+ std::istringstream istr (argv[1]);
+ istr >> lFilename;
+ }
- char const* filename = "world_schedule.csv";
+ // Open the file
+ iterator_t lFileIterator (lFilename);
+ if (!lFileIterator) {
+ std::cerr << "The file " << lFilename << " can not be open." << std::endl;
+ }
- std::ifstream in(filename, std::ios_base::in);
+ // Create an EOF iterator
+ iterator_t lFileIteratorEnd = lFileIterator.make_end();
+
+ // Instantiate the structure that will hold the result of the parsing.
+ FlightPeriod_T lFlightPeriod;
+ FlightPeriodParser lFlightPeriodParser (lFlightPeriod);
+ boost::spirit::classic::parse_info<iterator_t> info =
+ boost::spirit::classic::parse (lFileIterator, lFileIteratorEnd,
+ lFlightPeriodParser,
+ boost::spirit::classic::space_p);
- if (!in) {
- std::cerr << "Error: Could not open input file: "
- << filename << std::endl;
- return 1;
- }
+ // DEBUG
+ std::cout << "Flight Period:" << std::endl;
+ lFlightPeriod.display();
- typedef FlightPeriodParser<std::string::const_iterator, FlightPeriod_T > lFlightPeriodParser;
- lFlightPeriodParser flightParser; // Our grammar
-
- std::string::const_iterator iter;
- std::string::const_iterator end;
-
- std::string line;
- bool r = true;
- using boost::spirit::ascii::space;
+ std::cout << "-------------------------" << std::endl;
+ if (info.full) {
+ std::cout << "Parsing succeeded" << std::endl;
+
+ } else {
+ std::cout << "Parsing failed" << std::endl;
+ }
+ std::cout << "-------------------------" << std::endl;
-
- while (r && std::getline(in, line)) {
- iter = line.begin();
- end = line.end();
- r = phrase_parse(iter, end, flightParser, space);
- if (iter != end) {
- r = false;
- }
- }
-
- if (r && iter == end) {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "-------------------------\n";
- return 0;
- } else {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- return 0;
+ } catch (const std::exception& stde) {
+ std::cerr << "Standard exception: " << stde.what() << std::endl;
+ return -1;
+
+ } catch (...) {
+ return -1;
+ }
+
+ return 0;
}
Modified: trunk/dsim/test/boost/spirit/stream_iterator_parser
===================================================================
(Binary files differ)
Modified: trunk/dsim/test/boost/spirit/sum_parser
===================================================================
(Binary files differ)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-10 17:25:20
|
Revision: 150
http://dsim.svn.sourceforge.net/dsim/?rev=150&view=rev
Author: gsabatier
Date: 2010-11-10 17:25:14 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[dev] Added boost/spiritQi makefile.
Modified Paths:
--------------
trunk/dsim/configure.ac
Modified: trunk/dsim/configure.ac
===================================================================
--- trunk/dsim/configure.ac 2010-11-10 17:20:23 UTC (rev 149)
+++ trunk/dsim/configure.ac 2010-11-10 17:25:14 UTC (rev 150)
@@ -495,6 +495,7 @@
test/boost/mpl/Makefile
test/boost/random/Makefile
test/boost/spirit/Makefile
+ test/boost/spiritQi/Makefile
test/boost/serialization/Makefile
test/boost/signals/Makefile
test/boost/smart_pointers/Makefile
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-10 17:20:31
|
Revision: 149
http://dsim.svn.sourceforge.net/dsim/?rev=149&view=rev
Author: gsabatier
Date: 2010-11-10 17:20:23 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[test] Added boost/spiritQi
Modified Paths:
--------------
trunk/dsim/test/boost/Makefile.am
Added Paths:
-----------
trunk/dsim/test/boost/spiritQi/
trunk/dsim/test/boost/spiritQi/Makefile.am
trunk/dsim/test/boost/spiritQi/action_parser.cpp
trunk/dsim/test/boost/spiritQi/bad_input.csv
trunk/dsim/test/boost/spiritQi/complex_parser.cpp
trunk/dsim/test/boost/spiritQi/employee_parser.cpp
trunk/dsim/test/boost/spiritQi/good_input.csv
trunk/dsim/test/boost/spiritQi/num_list1_parser.cpp
trunk/dsim/test/boost/spiritQi/roman_parser.cpp
trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
trunk/dsim/test/boost/spiritQi/stream_iterator_parser.cpp
trunk/dsim/test/boost/spiritQi/sum_parser.cpp
trunk/dsim/test/boost/spiritQi/world_schedule.csv
Modified: trunk/dsim/test/boost/Makefile.am
===================================================================
--- trunk/dsim/test/boost/Makefile.am 2010-11-10 16:56:23 UTC (rev 148)
+++ trunk/dsim/test/boost/Makefile.am 2010-11-10 17:20:23 UTC (rev 149)
@@ -6,6 +6,6 @@
##
SUBDIRS = accumulators asio filesystem intrusive mpi mpl \
- serialization signals spirit smart_pointers
+ serialization signals spirit spiritQi smart_pointers
EXTRA_DIST =
Property changes on: trunk/dsim/test/boost/spiritQi
___________________________________________________________________
Added: svn:ignore
+ employee_parser
action_parser
complex_parser
num_list1_parser
roman_parser
sum_parser
schedule_parser
stream_iterator_parser
.deps
.libs
Makefile
Makefile.in
Added: trunk/dsim/test/boost/spiritQi/Makefile.am
===================================================================
--- trunk/dsim/test/boost/spiritQi/Makefile.am (rev 0)
+++ trunk/dsim/test/boost/spiritQi/Makefile.am 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,40 @@
+## command sub-directory
+include $(top_srcdir)/Makefile.common
+
+MAINTAINERCLEANFILES = Makefile.in
+
+check_PROGRAMS = employee_parser action_parser complex_parser \
+ num_list1_parser roman_parser sum_parser \
+ schedule_parser stream_iterator_parser levenshtein
+
+employee_parser_SOURCES = employee_parser.cpp
+employee_parser_CXXFLAGS = $(BOOST_CFLAGS)
+employee_parser_LDADD = $(BOOST_LIBS)
+
+action_parser_SOURCES = action_parser.cpp
+action_parser_CXXFLAGS = $(BOOST_CFLAGS)
+action_parser_LDADD = $(BOOST_LIBS)
+
+complex_parser_SOURCES = complex_parser.cpp
+complex_parser_CXXFLAGS = $(BOOST_CFLAGS)
+complex_parser_LDADD = $(BOOST_LIBS)
+
+num_list1_parser_SOURCES = num_list1_parser.cpp
+num_list1_parser_CXXFLAGS = $(BOOST_CFLAGS)
+num_list1_parser_LDADD = $(BOOST_LIBS)
+
+roman_parser_SOURCES = roman_parser.cpp
+roman_parser_CXXFLAGS = $(BOOST_CFLAGS)
+roman_parser_LDADD = $(BOOST_LIBS)
+
+sum_parser_SOURCES = sum_parser.cpp
+sum_parser_CXXFLAGS = $(BOOST_CFLAGS)
+sum_parser_LDADD = $(BOOST_LIBS)
+
+schedule_parser_SOURCES = schedule_parser.cpp
+schedule_parser_CXXFLAGS = $(BOOST_CFLAGS)
+schedule_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
+
+stream_iterator_parser_SOURCES = stream_iterator_parser.cpp
+stream_iterator_parser_CXXFLAGS = $(BOOST_CFLAGS)
+stream_iterator_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
Added: trunk/dsim/test/boost/spiritQi/action_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/action_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/action_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,104 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/bind.hpp>
+
+#include <iostream>
+
+// Presented are various ways to attach semantic actions
+// * Using plain function pointer
+// * Using simple function object
+// * Using boost.bind with a plain function
+// * Using boost.bind with a member function
+// * Using boost.lambda
+
+//[tutorial_semantic_action_functions
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+
+ // A plain function
+ void print(int const& i)
+ {
+ std::cout << i << std::endl;
+ }
+
+ // A member function
+ struct writer
+ {
+ void print(int const& i) const
+ {
+ std::cout << i << std::endl;
+ }
+ };
+
+ // A function object
+ struct print_action
+ {
+ void operator()(int const& i, qi::unused_type, qi::unused_type) const
+ {
+ std::cout << i << std::endl;
+ }
+ };
+}
+//]
+
+int main()
+{
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::parse;
+ using client::print;
+ using client::writer;
+ using client::print_action;
+
+ { // example using plain function
+
+ char const *first = "{42}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions1
+ parse(first, last, '{' >> int_[&print] >> '}');
+ //]
+ }
+
+ { // example using simple function object
+
+ char const *first = "{43}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions2
+ parse(first, last, '{' >> int_[print_action()] >> '}');
+ //]
+ }
+
+ { // example using boost.bind with a plain function
+
+ char const *first = "{44}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions3
+ parse(first, last, '{' >> int_[boost::bind(&print, _1)] >> '}');
+ //]
+ }
+
+ { // example using boost.bind with a member function
+
+ char const *first = "{44}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions4
+ writer w;
+ parse(first, last, '{' >> int_[boost::bind(&writer::print, &w, _1)] >> '}');
+ //]
+ }
+
+ { // example using boost.lambda
+
+ namespace lambda = boost::lambda;
+ char const *first = "{45}", *last = first + std::strlen(first);
+ using lambda::_1;
+ //[tutorial_attach_actions5
+ parse(first, last, '{' >> int_[std::cout << _1 << '\n'] >> '}');
+ //]
+ }
+
+ return 0;
+}
Added: trunk/dsim/test/boost/spiritQi/bad_input.csv
===================================================================
--- trunk/dsim/test/boost/spiritQi/bad_input.csv (rev 0)
+++ trunk/dsim/test/boost/spiritQi/bad_input.csv 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,5 @@
+# test
+#
+# bad input
+
+123;42.0;a;1.4
Added: trunk/dsim/test/boost/spiritQi/complex_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/complex_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/complex_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,101 @@
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A complex number micro parser.
+//
+// [ JDG May 10, 2002 ] spirit1
+// [ JDG May 9, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iostream>
+#include <string>
+#include <complex>
+
+///////////////////////////////////////////////////////////////////////////////
+// Our complex number parser/compiler
+///////////////////////////////////////////////////////////////////////////////
+//[tutorial_complex_number
+namespace client
+{
+ template <typename Iterator>
+ bool parse_complex(Iterator first, Iterator last, std::complex<double>& c)
+ {
+ using boost::spirit::qi::double_;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::phrase_parse;
+ using boost::spirit::ascii::space;
+ using boost::phoenix::ref;
+
+ double rN = 0.0;
+ double iN = 0.0;
+ bool r = phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ '(' >> double_[ref(rN) = _1]
+ >> -(',' >> double_[ref(iN) = _1]) >> ')'
+ | double_[ref(rN) = _1]
+ ),
+ // End grammar
+
+ space);
+
+ if (!r || first != last) // fail if we did not get a full match
+ return false;
+ c = std::complex<double>(rN, iN);
+ return r;
+ }
+}
+//]
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tA complex number micro parser for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout << "Give me a complex number of the form r or (r) or (r,i) \n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ std::complex<double> c;
+ if (client::parse_complex(str.begin(), str.end(), c))
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "got: " << c << std::endl;
+ std::cout << "\n-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Added: trunk/dsim/test/boost/spiritQi/employee_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/employee_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/employee_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,152 @@
+
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A parser for arbitrary tuples. This example presents a parser
+// for an employee structure.
+//
+// [ JDG May 9, 2007 ]
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/io.hpp>
+
+#include <iostream>
+#include <string>
+#include <complex>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our employee struct
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_employee_struct
+ struct employee
+ {
+ int age;
+ std::string surname;
+ std::string forename;
+ double salary;
+ };
+ //]
+}
+
+// We need to tell fusion about our employee struct
+// to make it a first-class fusion citizen. This has to
+// be in global scope.
+
+//[tutorial_employee_adapt_struct
+BOOST_FUSION_ADAPT_STRUCT(
+ client::employee,
+ (int, age)
+ (std::string, surname)
+ (std::string, forename)
+ (double, salary)
+)
+//]
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our employee parser
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_employee_parser
+ template <typename Iterator>
+ struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
+ {
+ employee_parser() : employee_parser::base_type(start)
+ {
+ using qi::int_;
+ using qi::lit;
+ using qi::double_;
+ using qi::lexeme;
+ using ascii::char_;
+
+ quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
+
+ start %=
+ lit("employee")
+ >> '{'
+ >> int_ >> ','
+ >> quoted_string >> ','
+ >> quoted_string >> ','
+ >> double_
+ >> '}'
+ ;
+ }
+
+ qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
+ qi::rule<Iterator, employee(), ascii::space_type> start;
+ };
+ //]
+}
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tAn employee parser for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout
+ << "Give me an employee of the form :"
+ << "employee{age, \"surname\", \"forename\", salary } \n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ using boost::spirit::ascii::space;
+ typedef std::string::const_iterator iterator_type;
+ typedef client::employee_parser<iterator_type> employee_parser;
+
+ employee_parser g; // Our grammar
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ client::employee emp;
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ bool r = phrase_parse(iter, end, g, space, emp);
+
+ if (r && iter == end)
+ {
+ std::cout << boost::fusion::tuple_open('[');
+ std::cout << boost::fusion::tuple_close(']');
+ std::cout << boost::fusion::tuple_delimiter(", ");
+
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "got: " << boost::fusion::as_vector(emp) << std::endl;
+ std::cout << "\n-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Added: trunk/dsim/test/boost/spiritQi/good_input.csv
===================================================================
--- trunk/dsim/test/boost/spiritQi/good_input.csv (rev 0)
+++ trunk/dsim/test/boost/spiritQi/good_input.csv 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,5 @@
+# test
+#
+# good input
+8 ;
+6; 7;
Added: trunk/dsim/test/boost/spiritQi/num_list1_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/num_list1_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/num_list1_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,90 @@
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// This sample demontrates a parser for a comma separated list of numbers.
+// No actions.
+//
+// [ JDG May 10, 2002 ] spirit1
+// [ JDG March 24, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our number list parser
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_numlist1
+ template <typename Iterator>
+ bool parse_numbers(Iterator first, Iterator last)
+ {
+ using qi::double_;
+ using qi::phrase_parse;
+ using ascii::space;
+
+ bool r = phrase_parse(
+ first, /*< start iterator >*/
+ last, /*< end iterator >*/
+ double_ >> *(',' >> double_), /*< the parser >*/
+ space /*< the skip-parser >*/
+ );
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
+}
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tA comma separated list parser for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout << "Give me a comma separated list of numbers.\n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ if (client::parse_numbers(str.begin(), str.end()))
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << str << " Parses OK: " << std::endl;
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Added: trunk/dsim/test/boost/spiritQi/roman_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/roman_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/roman_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,186 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A Roman Numerals Parser (demonstrating the symbol table). This is
+// discussed in the "Symbols" chapter in the Spirit User's Guide.
+//
+// [ JDG August 22, 2002 ] spirit1
+// [ JDG March 13, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iostream>
+#include <string>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman hundreds (100..900) numerals using the symbol table.
+ // Notice that the data associated with each slot is the parser's attribute
+ // (which is passed to attached semantic actions).
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_hundreds
+ struct hundreds_ : qi::symbols<char, unsigned>
+ {
+ hundreds_()
+ {
+ add
+ ("C" , 100)
+ ("CC" , 200)
+ ("CCC" , 300)
+ ("CD" , 400)
+ ("D" , 500)
+ ("DC" , 600)
+ ("DCC" , 700)
+ ("DCCC" , 800)
+ ("CM" , 900)
+ ;
+ }
+
+ } hundreds;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman tens (10..90) numerals using the symbol table.
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_tens
+ struct tens_ : qi::symbols<char, unsigned>
+ {
+ tens_()
+ {
+ add
+ ("X" , 10)
+ ("XX" , 20)
+ ("XXX" , 30)
+ ("XL" , 40)
+ ("L" , 50)
+ ("LX" , 60)
+ ("LXX" , 70)
+ ("LXXX" , 80)
+ ("XC" , 90)
+ ;
+ }
+
+ } tens;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman ones (1..9) numerals using the symbol table.
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_ones
+ struct ones_ : qi::symbols<char, unsigned>
+ {
+ ones_()
+ {
+ add
+ ("I" , 1)
+ ("II" , 2)
+ ("III" , 3)
+ ("IV" , 4)
+ ("V" , 5)
+ ("VI" , 6)
+ ("VII" , 7)
+ ("VIII" , 8)
+ ("IX" , 9)
+ ;
+ }
+
+ } ones;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // roman (numerals) grammar
+ //
+ // Note the use of the || operator. The expression
+ // a || b reads match a or b and in sequence. Try
+ // defining the roman numerals grammar in YACC or
+ // PCCTS. Spirit rules! :-)
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_grammar
+ template <typename Iterator>
+ struct roman : qi::grammar<Iterator, unsigned()>
+ {
+ roman() : roman::base_type(start)
+ {
+ using qi::eps;
+ using qi::lit;
+ using qi::_val;
+ using qi::_1;
+ using ascii::char_;
+
+ start = eps [_val = 0] >>
+ (
+ +lit('M') [_val += 1000]
+ || hundreds [_val += _1]
+ || tens [_val += _1]
+ || ones [_val += _1]
+ )
+ ;
+ }
+
+ qi::rule<Iterator, unsigned()> start;
+ };
+ //]
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tRoman Numerals Parser\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "Type a Roman Numeral ...or [q or Q] to quit\n\n";
+
+ typedef std::string::const_iterator iterator_type;
+ typedef client::roman<iterator_type> roman;
+
+ roman roman_parser; // Our grammar
+
+ std::string str;
+ unsigned result;
+ while (std::getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ //[tutorial_roman_grammar_parse
+ bool r = parse(iter, end, roman_parser, result);
+
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "result = " << result << std::endl;
+ std::cout << "-------------------------\n";
+ }
+ else
+ {
+ std::string rest(iter, end);
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "stopped at: \": " << rest << "\"\n";
+ std::cout << "-------------------------\n";
+ }
+ //]
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
Added: trunk/dsim/test/boost/spiritQi/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/schedule_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/schedule_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,252 @@
+// STL
+#include <istream>
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include <set>
+#include <vector>
+// Boost (Extended STL)
+#include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/date_time/gregorian/gregorian.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/phoenix_object.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+#include <boost/fusion/include/io.hpp>
+#include <boost/lambda/lambda.hpp>
+
+
+typedef std::string::const_iterator iterator_t;
+/** Flight-Period. */
+struct FlightPeriod_T {
+ // Attributes
+ std::string _airlineCode;
+ unsigned int _flightNumber;
+ boost::gregorian::date _dateRangeStart;
+ boost::gregorian::date _dateRangeEnd;
+ std::string _dow;
+ std::string _cabinCode;
+};
+
+/** Store the parsed airline code. */
+template <typename FLIGHT_PERIOD>
+struct store_airline_code {
+ store_airline_code (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lAirlineCode (iStr, iStrEnd);
+ _flightPeriod._airlineCode = lAirlineCode;
+ // std::cout << "Airline code: " << lAirlineCode << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+/** Store the parsed cabin code. */
+template <typename FLIGHT_PERIOD>
+struct store_cabin_code {
+ store_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (char iChar) const {
+ _flightPeriod._cabinCode = iChar;
+ // std::cout << "Cabin code: " << lCabinCode << std::endl;
+ }
+
+ FLIGHT_PERIOD& _flightPeriod;
+};
+
+
+// /////////// Utilities /////////////
+
+/** 1-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 1, 1> int1_p;
+
+/** 2-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p;
+
+/** 4-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p;
+
+/** Up-to-4-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p;
+
+
+////////////////////////////////////////////////////////////////////////////
+// Parser
+////////////////////////////////////////////////////////////////////////////
+template <typename ITERATOR, typename FLIGHT_PERIOD>
+struct FlightPeriodParser :
+ boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type > {
+
+ typedef store_airline_code<FLIGHT_PERIOD> store_airline_code_t;
+ typedef store_cabin_code<FLIGHT_PERIOD> store_cabin_code_t;
+
+ FLIGHT_PERIOD _t;
+
+ FlightPeriodParser () :
+ FlightPeriodParser::base_type(start) {
+
+ using boost::spirit::ascii::string;
+ using boost::spirit::ascii::char_;
+ using boost::spirit::qi::lexeme;
+ using boost::spirit::qi::repeat;
+ using boost::spirit::qi::double_;
+ using boost::lambda::_1;
+
+
+ start = (comment | flight_period) ;
+
+ comment = lexeme[ (repeat(2)[char_("/")]) ] >> *(char_);
+
+ flight_period = airline_code
+ >> ';' >> flight_number
+ >> ';' >> date
+ >> ';' >> date
+ >> ';' >> dow
+ >> ';'
+ >> leg_list
+ >> segment_list
+ ;
+
+ airline_code = lexeme[ (repeat(2)[char_("A-Z")]) ];
+
+
+ flight_number = uint1_4_p;
+
+ date = lexeme[ uint4_p
+ >> '-' >> uint2_p
+ >> '-' >> uint2_p ]
+ ;
+
+ dow =
+ lexeme[ repeat(7)[char_("0-1")] ]
+ ;
+
+ leg_list = +(leg);
+
+ leg = leg_key
+ >> leg_details
+ >> +(cabin_details)
+ ;
+
+ leg_key =
+ lexeme[ repeat(3)[char_("A-Z")] ]
+ >> ';'
+ >> lexeme[ repeat(3)[char_("A-Z")] ]
+ >> ';'
+ ;
+
+ leg_details =
+ time
+ >> ';' >> time
+ >> ';' >> time
+ >> ';'
+ ;
+
+ time = lexeme[ uint2_p
+ >> ':' >> uint2_p
+ >> !(':' >> uint2_p) ]
+ ;
+
+ cabin_details = char_("A-Z") [store_cabin_code_t(_t)]
+ >> ';' >> double_
+ >> ';'
+ ;
+
+ segment_key =
+ repeat(3)[char_("0-9A-Z")]
+ >> ';'
+ >>repeat(3)[char_("0-9A-Z")]
+ >> ';'
+ ;
+
+ segment_list = +(segment);
+
+ segment =
+ general_segments | specific_segments
+ ;
+
+ general_segments =
+ char_('0')
+ >> ';'
+ >> +(segment_cabin_details)
+ ;
+
+ specific_segments =
+ char_('1')
+ >> ';'
+ >> +(segment_key >> full_segment_cabin_details)
+ ;
+
+ full_segment_cabin_details =
+ +(segment_cabin_details)
+ ;
+
+ segment_cabin_details =
+ char_("A-Z")
+ >> ';' >> (repeat(1,26)[char_("A-Z")])
+ >> ';'
+ ;
+
+ }
+
+ boost::spirit::qi::rule<ITERATOR, boost::spirit::ascii::space_type> start,
+ comment, flight_period, airline_code, flight_number, date, dow, leg, leg_list,
+ leg_key, leg_details, time, cabin_details, segment, segment_list, segment_key,
+ general_segments, specific_segments, full_segment_cabin_details, segment_cabin_details;
+
+};
+
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int main (int argc, char* argv[]) {
+
+ char const* filename = "world_schedule.csv";
+
+ std::ifstream in(filename, std::ios_base::in);
+
+ if (!in) {
+ std::cerr << "Error: Could not open input file: "
+ << filename << std::endl;
+ return 1;
+ }
+
+ typedef FlightPeriodParser<std::string::const_iterator, FlightPeriod_T > lFlightPeriodParser;
+ lFlightPeriodParser flightParser; // Our grammar
+
+ std::string::const_iterator iter;
+ std::string::const_iterator end;
+
+ std::string line;
+ bool r = true;
+ using boost::spirit::ascii::space;
+
+
+ while (r && std::getline(in, line)) {
+ iter = line.begin();
+ end = line.end();
+ r = phrase_parse(iter, end, flightParser, space);
+ if (iter != end) {
+ r = false;
+ }
+ }
+
+ if (r && iter == end) {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "-------------------------\n";
+ return 0;
+ } else {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ return 0;
+}
Added: trunk/dsim/test/boost/spiritQi/stream_iterator_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/stream_iterator_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/stream_iterator_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,91 @@
+// Copyright (c) 2010 Peter Schueller
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+#include <vector>
+#include <istream>
+#include <sstream>
+#include <iostream>
+#include <fstream>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+
+namespace qi = boost::spirit::qi;
+namespace ascii = boost::spirit::ascii;
+
+
+////////////////////////////////////////////////////////////////////////////
+// Parser
+////////////////////////////////////////////////////////////////////////////
+template <typename iterator_t>
+bool parse(iterator_t& iStr, iterator_t& iStrEnd,
+ std::vector<double>& output) {
+
+ // Parse list of doubles from input stream
+ bool r = qi::phrase_parse(
+ iStr, iStrEnd, // Iterators
+ *(qi::double_ >> ';'), // Recognize list of doubles
+ ascii::space | '#' >> *(ascii::char_ - qi::eol) >> qi::eol, // Skip comment
+ output); // Store double into this object
+
+ // Return result of parsing
+ return r;
+
+}
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int main (int argc, char* argv[]) {
+
+ std::string lFilename("good_input.csv");
+ std::ifstream File;
+
+ // Read the command-line parameters
+ if (argc >= 1 && argv[1] != NULL) {
+ lFilename = argv[1];
+ File.open (argv[1],std::ios_base::in);
+ } else {
+ // Default File to be parsed
+ File.open ("good_input.csv",std::ios_base::in);
+ }
+
+ // Check the File existence
+ if (!File) {
+ std::cerr << "Unknown file named" << lFilename << std::endl;
+ return 1;
+ }
+
+ // Iterate over stream input
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ base_iterator_type in_begin(File.rdbuf());
+
+ // Convert input iterator to forward iterator, usable by spirit parser
+ typedef boost::spirit::multi_pass<base_iterator_type>forward_iterator_type;
+ forward_iterator_type fwd_begin =
+ boost::spirit::make_default_multi_pass(in_begin);
+ forward_iterator_type fwd_end;
+
+ // Prepare output
+ std::vector<double> output;
+
+ try {
+ bool r = parse(fwd_begin, fwd_end, output);
+ // Error detection
+ if( !r || fwd_begin != fwd_end ) {
+ throw std::runtime_error("parse error in "+lFilename);
+ } else {
+ std::cout << "--------------------------------------------\n";
+ std::cout << "Parsing of the file " << lFilename <<" succeeded\n";
+ std::cout << "Got: ";
+ for (unsigned int i = 0; i < output.size(); i++) {
+ std::cout << output[i] << " ";
+ }
+ std::cout << "\n--------------------------------------------\n";
+ }
+ } catch(const std::exception& e) {
+ std::cerr << "Exception: " << e.what() << std::endl;
+ }
+ return 0;
+}
+
Added: trunk/dsim/test/boost/spiritQi/sum_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spiritQi/sum_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spiritQi/sum_parser.cpp 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,104 @@
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A parser for summing a comma-separated list of numbers using phoenix.
+//
+// [ JDG June 28, 2002 ] spirit1
+// [ JDG March 24, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+//[tutorial_adder_includes
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <iostream>
+#include <string>
+//]
+
+namespace client
+{
+ //[tutorial_adder_using
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+ namespace phoenix = boost::phoenix;
+
+ using qi::double_;
+ using qi::_1;
+ using ascii::space;
+ using phoenix::ref;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our adder
+ ///////////////////////////////////////////////////////////////////////////
+
+ //[tutorial_adder
+ template <typename Iterator>
+ bool adder(Iterator first, Iterator last, double& n)
+ {
+ bool r = qi::phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ double_[ref(n) = _1] >> *(',' >> double_[ref(n) += _1])
+ )
+ ,
+ // End grammar
+
+ space);
+
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
+}
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tA parser for summing a list of numbers...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout << "Give me a comma separated list of numbers.\n";
+ std::cout << "The numbers are added using Phoenix.\n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ double n;
+ if (client::adder(str.begin(), str.end(), n))
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << str << " Parses OK: " << std::endl;
+
+ std::cout << "sum = " << n;
+ std::cout << "\n-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
Added: trunk/dsim/test/boost/spiritQi/world_schedule.csv
===================================================================
--- trunk/dsim/test/boost/spiritQi/world_schedule.csv (rev 0)
+++ trunk/dsim/test/boost/spiritQi/world_schedule.csv 2010-11-10 17:20:23 UTC (rev 149)
@@ -0,0 +1,21 @@
+// Flights: AirlineCode; FlightNumber; Date-Range; ; DOW; Legs; Segments;
+// Legs: BoardPoint; OffPoint; BoardTime; ArrivalDateOffSet; ArrivalTime;
+// ElapsedTime; LegCabins;
+// LegCabins: CabinCode; Capacity;
+// Segments: Specific;
+BA; 9; 2007-04-20; 2007-06-30; 0000011; LHR; BKK; 22:00; 15:15; 11:15; F; 5; J; 12; W; 20; Y; 300; BKK; SYD; 18:10; 06:05; 08:55; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+BA; 9; 2007-04-20; 2007-06-30; 1111100; LHR; BKK; 22:00; 15:15; 11:15; F; 5; J; 12; W; 20; Y; 300; BKK; SYD; 18:10; 06:05; 08:55; F; 5; J; 12; W; 20; Y; 300; 1; LHR; BKK; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ; BKK; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ; LHR; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
+BA; 117; 2007-04-20; 3000-06-30; 1111111; LHR; JFK; 08:20; 11:00; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKM;
+BA; 175; 2007-04-20; 2007-06-30; 1111111; LHR; JFK; 10:55; 13:35; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRL;
+BA; 179; 2007-04-20; 2007-06-30; 1111111; LHR; JFK; 18:05; 20:45; 07:40; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRVNELSQO;
+BA; 207; 2007-04-20; 2007-06-30; 1111111; LHR; MIA; 09:40; 14:25; 09:45; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRVNELSQO;
+BA; 279; 2007-04-20; 2007-06-30; 1111111; LHR; LAX; 10:05; 13:10; 11:05; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRVNELSQO;
+BA; 295; 2007-04-20; 2007-06-30; 1111111; LHR; ORD; 11:35; 14:00; 08:25; F; 5; J; 12; W; 20; Y; 300; 0; F; FA; J; JCDI; W; WT; Y; YBHKMRVNELSQO;
+BA; 341; 2007-04-20; 2007-06-30; 1111111; NCE; LHR; 08:55; 10:05; 02:10; J; 12; Y; 300; 0; J; JCDI; Y; YBHKMRVNEQLSO;
+BA; 343; 2007-04-20; 2007-06-30; 1111111; NCE; LHR; 11:00; 12:15; 02:15; J; 12; Y; 300; 0; J; JCDI; Y; YBHKMRVNEQLSO;
+BA; 345; 2007-04-20; 2007-06-30; 1111111; NCE; LHR; 16:20; 17:25; 02:05; J; 12; Y; 300; 0; J; JCDI; Y; YBHKMRVNEQLSO;
+BA; 347; 2007-04-20; 2007-06-30; 1111111; NCE; LHR; 13:55; 15:00; 02:05; J; 12; Y; 300; 0; J; JCDI; Y; YBHKMRVNEQLSO;
+AA; 101; 2007-04-20; 2007-06-30; 1111111; LHR; JFK; 09:55; 12:50; 07:55; G; 300; 0; G; GHQKLMVSOWN;
+AA; 117; 2007-04-20; 2007-06-30; 1111111; JFK; LAX; 14:20; 17:25; 06:05; F; 12; J; 20; Y; 300; 0; F; FA; J; JDI; Y; YBGHQKLMVSOWN;
+AA; 181; 2007-04-20; 2007-06-30; 1111111; JFK; LAX; 17:00; 20:00; 06:00; F; 12; J; 20; Y; 300; 0; F; FA; J; JDI; Y; YBHKMLWVGSNOQ;
+AA; 585; 2007-04-20; 2007-06-30; 1111111; JFK; MIA; 15:40; 18:50; 03:10; F; 12; Y; 300; 0; F; FAP; Y; YBHKMLWVGSONQ;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-10 16:56:34
|
Revision: 148
http://dsim.svn.sourceforge.net/dsim/?rev=148&view=rev
Author: gsabatier
Date: 2010-11-10 16:56:23 +0000 (Wed, 10 Nov 2010)
Log Message:
-----------
[test/boostQi] to be continued.
Modified Paths:
--------------
trunk/dsim/test/boost/spirit/Makefile.am
trunk/dsim/test/boost/spirit/schedule_parser.cpp
trunk/dsim/test/boost/spirit/world_schedule.csv
Added Paths:
-----------
trunk/dsim/test/boost/spirit/action_parser
trunk/dsim/test/boost/spirit/action_parser.cpp
trunk/dsim/test/boost/spirit/bad_input.csv
trunk/dsim/test/boost/spirit/complex_parser
trunk/dsim/test/boost/spirit/complex_parser.cpp
trunk/dsim/test/boost/spirit/employee_parser
trunk/dsim/test/boost/spirit/employee_parser.cpp
trunk/dsim/test/boost/spirit/good_input.csv
trunk/dsim/test/boost/spirit/num_list1_parser
trunk/dsim/test/boost/spirit/num_list1_parser.cpp
trunk/dsim/test/boost/spirit/roman_parser
trunk/dsim/test/boost/spirit/roman_parser.cpp
trunk/dsim/test/boost/spirit/stream_iterator_parser
trunk/dsim/test/boost/spirit/stream_iterator_parser.cpp
trunk/dsim/test/boost/spirit/sum_parser
trunk/dsim/test/boost/spirit/sum_parser.cpp
Modified: trunk/dsim/test/boost/spirit/Makefile.am
===================================================================
--- trunk/dsim/test/boost/spirit/Makefile.am 2010-11-02 17:47:57 UTC (rev 147)
+++ trunk/dsim/test/boost/spirit/Makefile.am 2010-11-10 16:56:23 UTC (rev 148)
@@ -3,44 +3,38 @@
MAINTAINERCLEANFILES = Makefile.in
-check_PROGRAMS = full_calculator functor_parser number_parser \
- parameter_parser spirit_parser subrule_parser \
- schedule_parser search_string_parser levenshtein
+check_PROGRAMS = employee_parser action_parser complex_parser \
+ num_list1_parser roman_parser sum_parser \
+ schedule_parser stream_iterator_parser levenshtein
-full_calculator_SOURCES = full_calculator.cpp
-full_calculator_CXXFLAGS = $(BOOST_CFLAGS)
-full_calculator_LDADD = $(BOOST_LIBS)
+employee_parser_SOURCES = employee_parser.cpp
+employee_parser_CXXFLAGS = $(BOOST_CFLAGS)
+employee_parser_LDADD = $(BOOST_LIBS)
-functor_parser_SOURCES = functor_parser.cpp
-functor_parser_CXXFLAGS = $(BOOST_CFLAGS)
-functor_parser_LDADD = $(BOOST_LIBS)
+action_parser_SOURCES = action_parser.cpp
+action_parser_CXXFLAGS = $(BOOST_CFLAGS)
+action_parser_LDADD = $(BOOST_LIBS)
-number_parser_SOURCES = number_parser.cpp
-number_parser_CXXFLAGS = $(BOOST_CFLAGS)
-number_parser_LDADD = $(BOOST_LIBS)
+complex_parser_SOURCES = complex_parser.cpp
+complex_parser_CXXFLAGS = $(BOOST_CFLAGS)
+complex_parser_LDADD = $(BOOST_LIBS)
-parameter_parser_SOURCES = parameter_parser.cpp
-parameter_parser_CXXFLAGS = $(BOOST_CFLAGS)
-parameter_parser_LDADD = $(BOOST_LIBS)
+num_list1_parser_SOURCES = num_list1_parser.cpp
+num_list1_parser_CXXFLAGS = $(BOOST_CFLAGS)
+num_list1_parser_LDADD = $(BOOST_LIBS)
-spirit_parser_SOURCES = spirit_parser.cpp
-spirit_parser_CXXFLAGS = $(BOOST_CFLAGS)
-spirit_parser_LDADD = $(BOOST_LIBS)
+roman_parser_SOURCES = roman_parser.cpp
+roman_parser_CXXFLAGS = $(BOOST_CFLAGS)
+roman_parser_LDADD = $(BOOST_LIBS)
-subrule_parser_SOURCES = subrule_parser.cpp
-subrule_parser_CXXFLAGS = $(BOOST_CFLAGS)
-subrule_parser_LDADD = $(BOOST_LIBS)
+sum_parser_SOURCES = sum_parser.cpp
+sum_parser_CXXFLAGS = $(BOOST_CFLAGS)
+sum_parser_LDADD = $(BOOST_LIBS)
schedule_parser_SOURCES = schedule_parser.cpp
schedule_parser_CXXFLAGS = $(BOOST_CFLAGS)
schedule_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
-search_string_parser_SOURCES = search_string_parser.cpp
-search_string_parser_CXXFLAGS = $(BOOST_CFLAGS)
-search_string_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
-
-levenshtein_SOURCES = levenshtein.cpp
-levenshtein_LDADD =
-
-EXTRA_DIST = test_full_calculator.sh test_parameter_parser.sh \
- test_schedule_parser.sh
+stream_iterator_parser_SOURCES = stream_iterator_parser.cpp
+stream_iterator_parser_CXXFLAGS = $(BOOST_CFLAGS)
+stream_iterator_parser_LDADD = $(BOOST_LIBS) $(BOOST_DATE_TIME_LIB)
Added: trunk/dsim/test/boost/spirit/action_parser
===================================================================
(Binary files differ)
Property changes on: trunk/dsim/test/boost/spirit/action_parser
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/dsim/test/boost/spirit/action_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/action_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spirit/action_parser.cpp 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,104 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/bind.hpp>
+
+#include <iostream>
+
+// Presented are various ways to attach semantic actions
+// * Using plain function pointer
+// * Using simple function object
+// * Using boost.bind with a plain function
+// * Using boost.bind with a member function
+// * Using boost.lambda
+
+//[tutorial_semantic_action_functions
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+
+ // A plain function
+ void print(int const& i)
+ {
+ std::cout << i << std::endl;
+ }
+
+ // A member function
+ struct writer
+ {
+ void print(int const& i) const
+ {
+ std::cout << i << std::endl;
+ }
+ };
+
+ // A function object
+ struct print_action
+ {
+ void operator()(int const& i, qi::unused_type, qi::unused_type) const
+ {
+ std::cout << i << std::endl;
+ }
+ };
+}
+//]
+
+int main()
+{
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::parse;
+ using client::print;
+ using client::writer;
+ using client::print_action;
+
+ { // example using plain function
+
+ char const *first = "{42}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions1
+ parse(first, last, '{' >> int_[&print] >> '}');
+ //]
+ }
+
+ { // example using simple function object
+
+ char const *first = "{43}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions2
+ parse(first, last, '{' >> int_[print_action()] >> '}');
+ //]
+ }
+
+ { // example using boost.bind with a plain function
+
+ char const *first = "{44}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions3
+ parse(first, last, '{' >> int_[boost::bind(&print, _1)] >> '}');
+ //]
+ }
+
+ { // example using boost.bind with a member function
+
+ char const *first = "{44}", *last = first + std::strlen(first);
+ //[tutorial_attach_actions4
+ writer w;
+ parse(first, last, '{' >> int_[boost::bind(&writer::print, &w, _1)] >> '}');
+ //]
+ }
+
+ { // example using boost.lambda
+
+ namespace lambda = boost::lambda;
+ char const *first = "{45}", *last = first + std::strlen(first);
+ using lambda::_1;
+ //[tutorial_attach_actions5
+ parse(first, last, '{' >> int_[std::cout << _1 << '\n'] >> '}');
+ //]
+ }
+
+ return 0;
+}
Added: trunk/dsim/test/boost/spirit/bad_input.csv
===================================================================
--- trunk/dsim/test/boost/spirit/bad_input.csv (rev 0)
+++ trunk/dsim/test/boost/spirit/bad_input.csv 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,5 @@
+# test
+#
+# bad input
+
+123;42.0;a;1.4
Added: trunk/dsim/test/boost/spirit/complex_parser
===================================================================
(Binary files differ)
Property changes on: trunk/dsim/test/boost/spirit/complex_parser
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/dsim/test/boost/spirit/complex_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/complex_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spirit/complex_parser.cpp 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,101 @@
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A complex number micro parser.
+//
+// [ JDG May 10, 2002 ] spirit1
+// [ JDG May 9, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iostream>
+#include <string>
+#include <complex>
+
+///////////////////////////////////////////////////////////////////////////////
+// Our complex number parser/compiler
+///////////////////////////////////////////////////////////////////////////////
+//[tutorial_complex_number
+namespace client
+{
+ template <typename Iterator>
+ bool parse_complex(Iterator first, Iterator last, std::complex<double>& c)
+ {
+ using boost::spirit::qi::double_;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::phrase_parse;
+ using boost::spirit::ascii::space;
+ using boost::phoenix::ref;
+
+ double rN = 0.0;
+ double iN = 0.0;
+ bool r = phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ '(' >> double_[ref(rN) = _1]
+ >> -(',' >> double_[ref(iN) = _1]) >> ')'
+ | double_[ref(rN) = _1]
+ ),
+ // End grammar
+
+ space);
+
+ if (!r || first != last) // fail if we did not get a full match
+ return false;
+ c = std::complex<double>(rN, iN);
+ return r;
+ }
+}
+//]
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tA complex number micro parser for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout << "Give me a complex number of the form r or (r) or (r,i) \n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ std::complex<double> c;
+ if (client::parse_complex(str.begin(), str.end(), c))
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "got: " << c << std::endl;
+ std::cout << "\n-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Added: trunk/dsim/test/boost/spirit/employee_parser
===================================================================
(Binary files differ)
Property changes on: trunk/dsim/test/boost/spirit/employee_parser
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/dsim/test/boost/spirit/employee_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/employee_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spirit/employee_parser.cpp 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,152 @@
+
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A parser for arbitrary tuples. This example presents a parser
+// for an employee structure.
+//
+// [ JDG May 9, 2007 ]
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/fusion/include/io.hpp>
+
+#include <iostream>
+#include <string>
+#include <complex>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our employee struct
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_employee_struct
+ struct employee
+ {
+ int age;
+ std::string surname;
+ std::string forename;
+ double salary;
+ };
+ //]
+}
+
+// We need to tell fusion about our employee struct
+// to make it a first-class fusion citizen. This has to
+// be in global scope.
+
+//[tutorial_employee_adapt_struct
+BOOST_FUSION_ADAPT_STRUCT(
+ client::employee,
+ (int, age)
+ (std::string, surname)
+ (std::string, forename)
+ (double, salary)
+)
+//]
+
+namespace client
+{
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our employee parser
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_employee_parser
+ template <typename Iterator>
+ struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
+ {
+ employee_parser() : employee_parser::base_type(start)
+ {
+ using qi::int_;
+ using qi::lit;
+ using qi::double_;
+ using qi::lexeme;
+ using ascii::char_;
+
+ quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
+
+ start %=
+ lit("employee")
+ >> '{'
+ >> int_ >> ','
+ >> quoted_string >> ','
+ >> quoted_string >> ','
+ >> double_
+ >> '}'
+ ;
+ }
+
+ qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
+ qi::rule<Iterator, employee(), ascii::space_type> start;
+ };
+ //]
+}
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tAn employee parser for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout
+ << "Give me an employee of the form :"
+ << "employee{age, \"surname\", \"forename\", salary } \n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ using boost::spirit::ascii::space;
+ typedef std::string::const_iterator iterator_type;
+ typedef client::employee_parser<iterator_type> employee_parser;
+
+ employee_parser g; // Our grammar
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ client::employee emp;
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ bool r = phrase_parse(iter, end, g, space, emp);
+
+ if (r && iter == end)
+ {
+ std::cout << boost::fusion::tuple_open('[');
+ std::cout << boost::fusion::tuple_close(']');
+ std::cout << boost::fusion::tuple_delimiter(", ");
+
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "got: " << boost::fusion::as_vector(emp) << std::endl;
+ std::cout << "\n-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Added: trunk/dsim/test/boost/spirit/good_input.csv
===================================================================
--- trunk/dsim/test/boost/spirit/good_input.csv (rev 0)
+++ trunk/dsim/test/boost/spirit/good_input.csv 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,5 @@
+# test
+#
+# good input
+8 ;
+6; 7;
Added: trunk/dsim/test/boost/spirit/num_list1_parser
===================================================================
(Binary files differ)
Property changes on: trunk/dsim/test/boost/spirit/num_list1_parser
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/dsim/test/boost/spirit/num_list1_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/num_list1_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spirit/num_list1_parser.cpp 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,90 @@
+/*=============================================================================
+ Copyright (c) 2002-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// This sample demontrates a parser for a comma separated list of numbers.
+// No actions.
+//
+// [ JDG May 10, 2002 ] spirit1
+// [ JDG March 24, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+
+#include <iostream>
+#include <string>
+#include <vector>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our number list parser
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_numlist1
+ template <typename Iterator>
+ bool parse_numbers(Iterator first, Iterator last)
+ {
+ using qi::double_;
+ using qi::phrase_parse;
+ using ascii::space;
+
+ bool r = phrase_parse(
+ first, /*< start iterator >*/
+ last, /*< end iterator >*/
+ double_ >> *(',' >> double_), /*< the parser >*/
+ space /*< the skip-parser >*/
+ );
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
+}
+
+////////////////////////////////////////////////////////////////////////////
+// Main program
+////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tA comma separated list parser for Spirit...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+
+ std::cout << "Give me a comma separated list of numbers.\n";
+ std::cout << "Type [q or Q] to quit\n\n";
+
+ std::string str;
+ while (getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ if (client::parse_numbers(str.begin(), str.end()))
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << str << " Parses OK: " << std::endl;
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Added: trunk/dsim/test/boost/spirit/roman_parser
===================================================================
(Binary files differ)
Property changes on: trunk/dsim/test/boost/spirit/roman_parser
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ application/octet-stream
Added: trunk/dsim/test/boost/spirit/roman_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/roman_parser.cpp (rev 0)
+++ trunk/dsim/test/boost/spirit/roman_parser.cpp 2010-11-10 16:56:23 UTC (rev 148)
@@ -0,0 +1,186 @@
+/*=============================================================================
+ Copyright (c) 2001-2010 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// A Roman Numerals Parser (demonstrating the symbol table). This is
+// discussed in the "Symbols" chapter in the Spirit User's Guide.
+//
+// [ JDG August 22, 2002 ] spirit1
+// [ JDG March 13, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iostream>
+#include <string>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman hundreds (100..900) numerals using the symbol table.
+ // Notice that the data associated with each slot is the parser's attribute
+ // (which is passed to attached semantic actions).
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_hundreds
+ struct hundreds_ : qi::symbols<char, unsigned>
+ {
+ hundreds_()
+ {
+ add
+ ("C" , 100)
+ ("CC" , 200)
+ ("CCC" , 300)
+ ("CD" , 400)
+ ("D" , 500)
+ ("DC" , 600)
+ ("DCC" , 700)
+ ("DCCC" , 800)
+ ("CM" , 900)
+ ;
+ }
+
+ } hundreds;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman tens (10..90) numerals using the symbol table.
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_tens
+ struct tens_ : qi::symbols<char, unsigned>
+ {
+ tens_()
+ {
+ add
+ ("X" , 10)
+ ("XX" , 20)
+ ("XXX" , 30)
+ ("XL" , 40)
+ ("L" , 50)
+ ("LX" , 60)
+ ("LXX" , 70)
+ ("LXXX" , 80)
+ ("XC" , 90)
+ ;
+ }
+
+ } tens;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman ones (1..9) numerals using the symbol table.
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_ones
+ struct ones_ : qi::symbols<char, unsigned>
+ {
+ ones_()
+ {
+ add
+ ("I" , 1)
+ ("II" , 2)
+ ("III" , 3)
+ ("IV" , 4)
+ ("V" , 5)
+ ("VI" , 6)
+ ("VII" , 7)
+ ("VIII" , 8)
+ ("IX" , 9)
+ ;
+ }
+
+ } ones;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // roman (numerals) grammar
+ //
+ // Note the use of the || operator. The expression
+ // a || b reads match a or b and in sequence. Try
+ // defining the roman numerals grammar in YACC or
+ // PCCTS. Spirit rules! :-)
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_grammar
+ template <typename Iterator>
+ struct roman : qi::grammar<Iterator, unsigned()>
+ {
+ roman() : roman::base_type(start)
+ {
+ using qi::eps;
+ using qi::lit;
+ using qi::_val;
+ using qi::_1;
+ using ascii::char_;
+
+ start = eps [_val = 0] >>
+ (
+ +lit('M') [_val += 1000]
+ || hundreds [_val += _1]
+ || tens [_val += _1]
+ || ones [_val += _1]
+ )
+ ;
+ }
+
+ qi::rule<Iterator, unsigned()> start;
+ };
+ //]
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "\t\tRoman Numerals Parser\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "Type a Roman Numeral ...or [q or Q] to quit\n\n";
+
+ typedef std::string::const_iterator iterator_type;
+ typedef client::roman<iterator_type> roman;
+
+ roman roman_parser; // Our grammar
+
+ std::string str;
+ unsigned result;
+ while (std::getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ //[tutorial_roman_grammar_parse
+ bool r = parse(iter, end, roman_parser, result);
+
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "result = " << result << std::endl;
+ std::cout << "-------------------------\n";
+ }
+ else
+ {
+ std::string rest(iter, end);
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "stopped at: \": " << rest << "\"\n";
+ std::cout << "-------------------------\n";
+ }
+ //]
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
Modified: trunk/dsim/test/boost/spirit/schedule_parser.cpp
===================================================================
--- trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-02 17:47:57 UTC (rev 147)
+++ trunk/dsim/test/boost/spirit/schedule_parser.cpp 2010-11-10 16:56:23 UTC (rev 148)
@@ -1,130 +1,25 @@
// STL
-#include <cassert>
-#include <iostream>
+#include <istream>
#include <sstream>
+#include <iostream>
#include <fstream>
-#include <string>
-#include <map>
#include <set>
#include <vector>
// Boost (Extended STL)
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
// Boost Spirit (Parsing)
-//#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>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+#include <boost/fusion/include/io.hpp>
+#include <boost/lambda/lambda.hpp>
-// Type definitions
-typedef char char_t;
-//typedef char const* iterator_t;
-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;
-/** LegCabin-Details. */
-struct Cabin_T {
- // Attributes
- std::string _cabinCode;
- double _capacity;
-
- void display() const {
- std::cout << " " << _cabinCode << " " << _capacity << ", ";
- }
-};
-
-/** List of Cabin-Detail strucutres. */
-typedef std::vector<Cabin_T> CabinList_T;
-
-/** Leg. */
-struct Leg_T {
- // Attributes
- std::string _boardPoint;
- boost::posix_time::time_duration _boardTime;
- boost::gregorian::date_duration _boardDateOffSet;
- std::string _offPoint;
- boost::posix_time::time_duration _offTime;
- boost::gregorian::date_duration _offDateOffSet;
- boost::posix_time::time_duration _elapsed;
- CabinList_T _cabinList;
-
- /** Constructor. */
- Leg_T () : _boardDateOffSet (0), _offDateOffSet (0) {}
-
- void display() const {
- std::cout << " " << _boardPoint << " / "
- << boost::posix_time::to_simple_string (_boardTime)
- << " -- " << _offPoint << " / "
- << boost::posix_time::to_simple_string (_offTime)
- << " --> " << boost::posix_time::to_simple_string (_elapsed)
- << std::endl;
- for (CabinList_T::const_iterator itCabin = _cabinList.begin();
- itCabin != _cabinList.end(); itCabin++) {
- const Cabin_T& lCabin = *itCabin;
- lCabin.display();
- }
- std::cout << std::endl;
- }
-};
-
-/** List of Leg strucutres. */
-typedef std::vector<Leg_T> LegList_T;
-
-/** SegmentCabin-Details. */
-struct SegmentCabin_T {
- // Attributes
- std::string _cabinCode;
- std::string _classes;
-
- void display() const {
- std::cout << " " << _cabinCode << " " << _classes << ", ";
- }
-};
-
-/** List of SegmentCabin-Detail strucutres. */
-typedef std::vector<SegmentCabin_T> SegmentCabinList_T;
-
-/** Segment. */
-struct Segment_T {
- // Attributes
- std::string _boardPoint;
- boost::posix_time::time_duration _boardTime;
- boost::gregorian::date_duration _boardDateOffSet;
- std::string _offPoint;
- boost::posix_time::time_duration _offTime;
- boost::gregorian::date_duration _offDateOffSet;
- boost::posix_time::time_duration _elapsed;
- SegmentCabinList_T _cabinList;
-
- /** Constructor. */
- Segment_T () : _boardDateOffSet (0), _offDateOffSet (0) {}
-
- void display() const {
- std::cout << " " << _boardPoint << " / "
- << boost::posix_time::to_simple_string (_boardTime)
- << " -- " << _offPoint << " / "
- << boost::posix_time::to_simple_string (_offTime)
- << " --> " << boost::posix_time::to_simple_string (_elapsed)
- << std::endl;
- for (SegmentCabinList_T::const_iterator itCabin = _cabinList.begin();
- itCabin != _cabinList.end(); itCabin++) {
- const SegmentCabin_T& lCabin = *itCabin;
- lCabin.display();
- }
- std::cout << std::endl;
- }
-};
-
-/** List of Segment strucutres. */
-typedef std::vector<Segment_T> SegmentList_T;
-
+typedef std::string::const_iterator iterator_t;
/** Flight-Period. */
struct FlightPeriod_T {
// Attributes
@@ -133,778 +28,225 @@
boost::gregorian::date _dateRangeStart;
boost::gregorian::date _dateRangeEnd;
std::string _dow;
- LegList_T _legList;
- SegmentList_T _segmentList;
-
- /** Constructor. */
- FlightPeriod_T () : _legAlreadyDefined (false), _itSeconds (0) {}
+ std::string _cabinCode;
+};
- /** Set the date from the staging details. */
- boost::gregorian::date getDate() const {
- return boost::gregorian::date (_itYear, _itMonth, _itDay);
+/** Store the parsed airline code. */
+template <typename FLIGHT_PERIOD>
+struct store_airline_code {
+ store_airline_code (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
+
+ void operator() (iterator_t iStr, iterator_t iStrEnd) const {
+ std::string lAirlineCode (iStr, iStrEnd);
+ _flightPeriod._airlineCode = lAirlineCode;
+ // std::cout << "Airline code: " << lAirlineCode << std::endl;
}
-
- /** Set the time from the staging details. */
- boost::posix_time::time_duration getTime() const {
- return boost::posix_time::hours (_itHours)
- + boost::posix_time::minutes (_itMinutes)
- + boost::posix_time::seconds (_itSeconds);
- }
-
- void display() const {
- std::cout << _airlineCode << _flightNumber
- << ", " << boost::gregorian::to_simple_string (_dateRangeStart)
- << " - " << boost::gregorian::to_simple_string (_dateRangeEnd)
- << " - " << _dow
- << std::endl;
- for (LegList_T::const_iterator itLeg = _legList.begin();
- itLeg != _legList.end(); itLeg++) {
- const Leg_T& lLeg = *itLeg;
- lLeg.display();
- }
+ FLIGHT_PERIOD& _flightPeriod;
+};
- for (SegmentList_T::const_iterator itSegment = _segmentList.begin();
- itSegment != _segmentList.end(); itSegment++) {
- const Segment_T& lSegment = *itSegment;
- lSegment.display();
- }
+/** Store the parsed cabin code. */
+template <typename FLIGHT_PERIOD>
+struct store_cabin_code {
+ store_cabin_code (FLIGHT_PERIOD& ioFlightPeriod)
+ : _flightPeriod (ioFlightPeriod) {}
- //std::cout << "[Debug] - Staging Leg: ";
- //_itLeg.display();
- //std::cout << "[Debug] - Staging Cabin: ";
- //_itCabin.display();
- //std::cout << "[Debug] - Staging Segment: ";
- //_itSegment.display();
+ void operator() (char iChar) const {
+ _flightPeriod._cabinCode = iChar;
+ // std::cout << "Cabin code: " << lCabinCode << std::endl;
}
-
- /** Add the given airport to the internal lists (if not already existing). */
- void addAirport (const std::string& iAirport) {
- std::set<std::string>::const_iterator itAirport =
- _airportList.find (iAirport);
- if (itAirport == _airportList.end()) {
- // Add the airport code to the airport set
- const bool insertSuccessful = _airportList.insert (iAirport).second;
-
- if (insertSuccessful == false) {
- // TODO: throw an exception
- }
- // Add the airport code to the airport vector
- _airportOrderedList.push_back (iAirport);
- }
- }
-
- /** Build the routing (segments). */
- void buildSegments () {
- // The list of airports encompasses all the airports on which
- // the flight takes off or lands. Moreover, that list is
- // time-ordered: the first airport is the initial departure of
- // the flight, and the last airport is the eventual point of
- // rest of the flight.
- // Be l the size of the ordered list of airports.
- // We want to generate all the segment combinations from the legs
- // and, hence, from all the possible (time-ordered) airport pairs.
- // Thus, we both iterator on i=0...l-1 and j=i+1...l
- assert (_airportOrderedList.size() >= 2);
-
- _segmentList.clear();
- for (std::vector<std::string>::const_iterator itAirport_i =
- _airportOrderedList.begin();
- itAirport_i != _airportOrderedList.end()-1; ++itAirport_i) {
- for (std::vector<std::string>::const_iterator itAirport_j =
- itAirport_i + 1;
- itAirport_j != _airportOrderedList.end(); ++itAirport_j) {
- Segment_T lSegment;
- lSegment._boardPoint = *itAirport_i;
- lSegment._offPoint = *itAirport_j;
-
- _segmentList.push_back (lSegment);
- }
- }
-
- // Clear the lists of airports, so that it is ready for the next flight
- _airportList.clear();
- _airportOrderedList.clear();
- }
-
- /** Add, to the Segment whose key corresponds to the
- given (board point, off point) pair, the specific segment cabin
- details (mainly, the list of the class codes).
- <br>Note that the Segment structure is retrieved from the internal
- list, already filled by a previous step (the buildSegments()
- method). */
- void addSegmentCabin (const Segment_T& iSegment,
- const SegmentCabin_T& iCabin) {
- // Retrieve the Segment structure corresponding to the (board, off) point
- // pair.
- SegmentList_T::iterator itSegment = _segmentList.begin();
- for ( ; itSegment != _segmentList.end(); ++itSegment) {
- const Segment_T& lSegment = *itSegment;
-
- const std::string& lBoardPoint = iSegment._boardPoint;
- const std::string& lOffPoint = iSegment._offPoint;
- if (lSegment._boardPoint == lBoardPoint
- && lSegment._offPoint == lOffPoint) {
- break;
- }
- }
- // If the segment key (airport pair) given in the schedule input file
- // does not correspond to the leg (board, off) points, throw an exception
- // so that the user knows the schedule input file is corrupted.
- if (itSegment == _segmentList.end()) {
- std::cerr << "Within the schedule input file, there is a flight for which the airports of segments and those of the legs do not correspond.";
- throw std::exception();
- }
-
- // Add the Cabin structure to the Segment Cabin structure.
- assert (itSegment != _segmentList.end());
- Segment_T& lSegment = *itSegment;
- lSegment._cabinList.push_back (iCabin);
- }
-
- /** Add, to all the Segment, the general segment cabin details
- (mainly, the list of the class codes).
- <br>Note that the Segment structures are stored within the internal
- list, already filled by a previous step (the buildSegments()
- method). */
- void addSegmentCabin (const SegmentCabin_T& iCabin) {
- // Iterate on all the Segment (as they get the same cabin definitions)
- for (SegmentList_T::iterator itSegment = _segmentList.begin();
- itSegment != _segmentList.end(); ++itSegment) {
- Segment_T& lSegment = *itSegment;
- lSegment._cabinList.push_back (iCabin);
- }
- }
-
- /** Staging Leg (resp. Cabin) structure, gathering the result of the iteration
- on one leg (resp. cabin). */
- bool _legAlreadyDefined;
- Leg_T _itLeg;
- Cabin_T _itCabin;
-
- /** Staging Date. */
- unsigned int _itYear;
- unsigned int _itMonth;
- unsigned int _itDay;
-
- /** Staging Time. */
- long _itHours;
- long _itMinutes;
- long _itSeconds;
- int _dateOffSet;
-
- /** Staging Airport List (helper to derive the list of Segment
- structures). */
- std::set<std::string> _airportList;
- std::vector<std::string> _airportOrderedList;
-
- /** Staging Segment-related attributes. */
- bool _areSegmentDefinitionsSpecific;
- Segment_T _itSegment;
- SegmentCabin_T _itSegmentCabin;
+ FLIGHT_PERIOD& _flightPeriod;
};
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Semantic actions
-//
-///////////////////////////////////////////////////////////////////////////////
-namespace {
- /** Store the parsed airline code. */
- struct store_airline_code {
- store_airline_code (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lAirlineCode (iStr, iStrEnd);
- _flightPeriod._airlineCode = lAirlineCode;
- // std::cout << "Airline code: " << lAirlineCode << std::endl;
- // As that's the beginning of a new flight, the list of legs must be reset
- _flightPeriod._legList.clear();
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the parsed flight number. */
- struct store_flight_number {
- store_flight_number (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
+// /////////// Utilities /////////////
- void operator() (unsigned int iNumber) const {
- _flightPeriod._flightNumber = iNumber;
- // std::cout << "Flight number: " << iNumber << std::endl;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the start of the date range. */
- struct store_date_range_start {
- store_date_range_start (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- _flightPeriod._dateRangeStart = _flightPeriod.getDate();
- // std::cout << "Date Range Start: "
- // << _flightPeriod._dateRangeStart << std::endl;
-
- // Reset the number of seconds
- _flightPeriod._itSeconds = 0;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
+/** 1-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 1, 1> int1_p;
- /** Store the end of the date range. */
- struct store_date_range_end {
- store_date_range_end (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- _flightPeriod._dateRangeEnd = _flightPeriod.getDate();
- // std::cout << "Date Range End: "
- // << _flightPeriod._dateRangeEnd << std::endl;
-
- // Reset the number of seconds
- _flightPeriod._itSeconds = 0;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
+/** 2-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p;
- /** Store the DOW (day of the Week). */
- struct store_dow {
- store_dow (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
+/** 4-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p;
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lDow (iStr, iStrEnd);
- _flightPeriod._dow = lDow;
- // std::cout << "DOW: " << lDow << std::endl;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
+/** Up-to-4-digit-integer parser */
+boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p;
- /** Store the parsed board point. */
- struct store_board_point {
- store_board_point (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lBoardPoint (iStr, iStrEnd);
- // std::cout << "Board point: " << lBoardPoint << std::endl;
-
- // If a leg has already been parsed, add it to the FlightPeriod
- if (_flightPeriod._legAlreadyDefined == true) {
- _flightPeriod._legList.push_back (_flightPeriod._itLeg);
- } else {
- _flightPeriod._legAlreadyDefined = true;
- }
-
- // Set the (new) board point
- _flightPeriod._itLeg._boardPoint = lBoardPoint;
-
- // As that's the beginning of a new leg, the list of cabins must be reset
- _flightPeriod._itLeg._cabinList.clear();
-
- // Add the airport code if it is not already stored in the airport lists
- _flightPeriod.addAirport (lBoardPoint);
- }
-
- FlightPeriod_T& _flightPeriod;
- };
- /** Store the parsed off point. */
- struct store_off_point {
- store_off_point (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
+////////////////////////////////////////////////////////////////////////////
+// Parser
+////////////////////////////////////////////////////////////////////////////
+template <typename ITERATOR, typename FLIGHT_PERIOD>
+struct FlightPeriodParser :
+ boost::spirit::qi::grammar<ITERATOR, boost::spirit::ascii::space_type > {
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lOffPoint (iStr, iStrEnd);
- _flightPeriod._itLeg._offPoint = lOffPoint;
- // std::cout << "Off point: " << lOffPoint << std::endl;
-
- // Add the airport code if it is not already stored in the airport lists
- _flightPeriod.addAirport (lOffPoint);
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the board time. */
- struct store_board_time {
- store_board_time (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- _flightPeriod._itLeg._boardTime = _flightPeriod.getTime();
-
- // Reset the number of seconds
- _flightPeriod._itSeconds = 0;
-
- // Reset the date off-set
- _flightPeriod._dateOffSet = 0;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the off time. */
- struct store_off_time {
- store_off_time (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- _flightPeriod._itLeg._offTime = _flightPeriod.getTime();
-
- // Reset the number of seconds
- _flightPeriod._itSeconds = 0;
-
- // As the board date off set is optional, it can be set only afterwards,
- // based on the staging date off-set value (_flightPeriod._dateOffSet).
- const boost::gregorian::date_duration lDateOffSet (_flightPeriod._dateOffSet);
- _flightPeriod._itLeg._boardDateOffSet = lDateOffSet;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the elapsed time. */
- struct store_elapsed_time {
- store_elapsed_time (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- _flightPeriod._itLeg._elapsed = _flightPeriod.getTime();
-
- // Reset the number of seconds
- _flightPeriod._itSeconds = 0;
-
- // As the board date off set is optional, it can be set only afterwards,
- // based on the staging date off-set value (_flightPeriod._dateOffSet).
- const boost::gregorian::date_duration lDateOffSet (_flightPeriod._dateOffSet);
- _flightPeriod._itLeg._offDateOffSet = lDateOffSet;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the parsed cabin code. */
- struct store_cabin_code {
- store_cabin_code (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- void operator() (char iChar) const {
- _flightPeriod._itCabin._cabinCode = iChar;
- // std::cout << "Cabin code: " << iChar << std::endl;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
+ typedef store_airline_code<FLIGHT_PERIOD> store_airline_code_t;
+ typedef store_cabin_code<FLIGHT_PERIOD> store_cabin_code_t;
- /** Store the parsed capacity. */
- struct store_capacity {
- store_capacity (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
+ FLIGHT_PERIOD _t;
- void operator() (double iReal) const {
- _flightPeriod._itCabin._capacity = iReal;
- // std::cout << "Capacity: " << iReal << std::endl;
+ FlightPeriodParser () :
+ FlightPeriodParser::base_type(start) {
- // The capacity is the last (according to arrival order) detail
- // of the cabin. Hence, when a capacity is parsed, it means that
- // the full cabin details have already been parsed as well: the
- // cabin can thus be added to the leg.
- _flightPeriod._itLeg._cabinList.push_back (_flightPeriod._itCabin);
- }
+ using boost::spirit::ascii::string;
+ using boost::spirit::ascii::char_;
+ using boost::spirit::qi::lexeme;
+ using boost::spirit::qi::repeat;
+ using boost::spirit::qi::double_;
+ using boost::lambda::_1;
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store whether or not all the segments are the same. */
- struct store_segment_specificity {
- store_segment_specificity (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {
- }
- void operator() (char iChar) const {
- if (iChar == '0') {
- _flightPeriod._areSegmentDefinitionsSpecific = false;
- } else {
- _flightPeriod._areSegmentDefinitionsSpecific = true;
- }
+ start = (comment | flight_period) ;
- // Do a few sanity checks: the two lists should get exactly the same
- // content (in terms of airport codes). The only difference is that one
- // is a STL set, and the other a STL vector.
- assert (_flightPeriod._airportList.size()
- == _flightPeriod._airportOrderedList.size());
- assert (_flightPeriod._airportList.size() >= 2);
-
- // Since all the legs have now been parsed, we get all the airports
- // and the segments may be built.
- _flightPeriod.buildSegments();
- }
+ comment = lexeme[ (repeat(2)[char_("/")]) ] >> *(char_);
- FlightPeriod_T& _flightPeriod;
- };
+ flight_period = airline_code
+ >> ';' >> flight_number
+ >> ';' >> date
+ >> ';' >> date
+ >> ';' >> dow
+ >> ';'
+ >> leg_list
+ >> segment_list
+ ;
- /** Store the board point of the segment. */
- struct store_segment_board_point {
- store_segment_board_point (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {
- }
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lBoardPoint (iStr, iStrEnd);
- _flightPeriod._itSegment._boardPoint = lBoardPoint;
- // std::cout << "Board point: " << lBoardPoint << std::endl;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the off point of the segment. */
- struct store_segment_off_point {
- store_segment_off_point (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {
- }
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lOffPoint (iStr, iStrEnd);
- _flightPeriod._itSegment._offPoint = lOffPoint;
- // std::cout << "Off point: " << lOffPoint << std::endl;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the off point of the segment. */
- struct store_segment_cabin_code {
- store_segment_cabin_code (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {
- }
+ airline_code = lexeme[ (repeat(2)[char_("A-Z")]) ];
- void operator() (char iChar) const {
- _flightPeriod._itSegmentCabin._cabinCode = iChar;
- // std::cout << "Cabin code: " << iChar << std::endl;
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Store the classes of the segment-cabin. */
- struct store_classes {
- store_classes (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {
- }
-
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- std::string lClasses (iStr, iStrEnd);
- _flightPeriod._itSegmentCabin._classes = lClasses;
- // std::cout << "Classes: " << lClasses << std::endl;
-
- // The list of classes is the last (according to the arrival order
- // within the schedule input file) detail of the segment cabin. Hence,
- // when a list of classes is parsed, it means that the full segment
- // cabin details have already been parsed as well: the segment cabin
- // can thus be added to the segment.
- if (_flightPeriod._areSegmentDefinitionsSpecific == true) {
- _flightPeriod.addSegmentCabin (_flightPeriod._itSegment,
- _flightPeriod._itSegmentCabin);
- } else {
- _flightPeriod.addSegmentCabin (_flightPeriod._itSegmentCabin);
- }
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-
- /** Mark the end of the flight-period parsing. */
- struct do_end_flight {
- do_end_flight (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {}
-
- // void operator() (char iChar) const {
- void operator() (iterator_t iStr, iterator_t iStrEnd) const {
- // std::cout << "End of Flight-Period " << std::endl;
-
- assert (_flightPeriod._legAlreadyDefined == true);
- _flightPeriod._legList.push_back (_flightPeriod._itLeg);
- // The lists of legs and cabins must be reset
- _flightPeriod._legAlreadyDefined = false;
- _flightPeriod._itLeg._cabinList.clear();
-
- // Display the result
- _flightPeriod.display();
- }
-
- FlightPeriod_T& _flightPeriod;
- };
-}
-
-// /////////// Utilities /////////////
-/** 1-digit-integer parser */
-boost::spirit::classic::int_parser<unsigned int, 10, 1, 1> int1_p;
-/** 2-digit-integer parser */
-boost::spirit::classic::uint_parser<int, 10, 2, 2> uint2_p;
-/** 4-digit-integer parser */
-boost::spirit::classic::uint_parser<int, 10, 4, 4> uint4_p;
-/** Up-to-4-digit-integer parser */
-boost::spirit::classic::uint_parser<int, 10, 1, 4> uint1_4_p;
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// Our calculator grammar (using subrules)
-//
-///////////////////////////////////////////////////////////////////////////////
- /**
- AirlineCode; FlightNumber; DateRangeStart; DateRangeEnd; DOW;
- (list) BoardPoint; OffPoint; BoardTime; DateOffSet; OffTime;
- ElapsedTime;
- (list) CabinCode; Capacity;
- SegmentSpecificty (0 or 1);
- (list) (optional BoardPoint; OffPoint); CabinCode; Classes
-
- BA; 9; 2007-04-20; 2007-06-30; 0000011;
- LHR; BKK; 22:00; 15:15 / +1; 11:15; F; 5; J; 12; W; 20; Y; 300;
- BKK; SYD; 18:10 / +1; 06:05 / +2; 08:55; F; 5; J; 12; W; 20; Y; 300;
- 0; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
- BA; 9; 2007-04-20; 2007-06-30; 1111100;
- LHR; BKK; 22:00; 15:15 / +1; 11:15; F; 5; J; 12; W; 20; Y; 300;
- BKK; SYD; 18:10 / +1; 06:05 / +2; 08:55; F; 5; J; 12; W; 20; Y; 300;
- 1; LHR; BKK; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
- BKK; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
- LHR; SYD; F; FA; J; JCDI; W; WT; Y; YBHKMLSQ;
-
- Grammar:
- DOW ::= int
- FlightKey ::= AirlineCode ';' FlightNumber
- ';' DateRangeStart ';' DateRangeEnd ';' DOW
- LegKey ::= BoardPoint ';' OffPoint
- LegDetails ::= BoardTime ['/' BoardDateOffSet]
- ';' OffTime ['/' BoardDateOffSet]
- ';' Elapsed
- LegCabinDetails ::= CabinCode ';' Capacity
- Leg ::= LegKey ';' LegDetails (';' CabinDetails)+
- SegmentKey ::= BoardPoint ';' OffPoint
- SegmentCabinDetails ::= CabinCode ';' Classes
- FullSegmentCabinDetails::= (';' SegmentCabinDetails)+
- GeneralSegments ::= '0' (';' SegmentCabinDetails)+
- SpecificSegments ::= '1' (';' SegmentKey
- ';' FullSegmentCabinDetails)+
- Segment ::= GeneralSegment | SpecificSegment
- FlightPeriod ::= FlightKey (';' Leg)+
- (';' Segment)+ ';' EndOfFlight
- EndOfFlight ::= ';'
- */
-
-using namespace boost::spirit::classic;
-
-/** Grammar for the Flight-Period parser. */
-struct FlightPeriodParser :
- public boost::spirit::classic::grammar<FlightPeriodParser> {
-
- FlightPeriodParser (FlightPeriod_T& ioFlightPeriod)
- : _flightPeriod (ioFlightPeriod) {
- }
-
- template <typename ScannerT>
- struct definition {
- definition (FlightPeriodParser const& self) {
-
- flight_period_list = *( boost::spirit::classic::comment_p("//")
- | boost::spirit::classic::comment_p("/*", "*/")
- | flight_period )
- ;
+ flight_number = uint1_4_p;
- flight_period = flight_key
- >> +( ';' >> leg )
- >> +( ';' >> segment )
- >> flight_period_end[do_end_flight(self._flightPeriod)]
+ date = lexeme[ uint4_p
+ >> '-' >> uint2_p
+ >> '-' >> uint2_p ]
;
- flight_period_end =
- boost::spirit::classic::ch_p(';')
+ dow =
+ lexeme[ repeat(7)[char_("0-1")] ]
;
-
- flight_key = airline_code
- >> ';' >> flight_number
- >> ';' >> date[store_date_range_start(self._flightPeriod)]
- >> ';' >> date[store_date_range_end(self._flightPeriod)]
- >> ';' >> dow[store_dow(self._flightPeriod)]
- ;
- airline_code =
- lexeme_d[ (repeat_p(2,3)[chset_p("0-9A-Z")])[store_airline_code(self._flightPeriod)] ]
+ leg_list = +(leg);
+
+ leg = leg_key
+ >> leg_details
+ >> +(cabin_details)
;
-
- flight_number =
- lexeme_d[ limit_d(0u, 9999u)[uint1_4_p][store_flight_number(self._flightPeriod)] ]
- ;
-
- date =
- lexeme_d[ limit_d(2000u,2099u)[uint4_p][assign_a(self._flightPeriod._itYear)]
- >> '-' >> limit_d(1u,12u)[uint2_p][assign_a(self._flightPeriod._itMonth)]
- >> '-' >> limit_d(1u,31u)[uint2_p][assign_a(self._flightPeriod._itDay)] ]
- ;
-
- dow =
- lexeme_d[ repeat_p(7)[chset_p("0-1")] ]
- ;
-
- leg = leg_key >> ';' >> leg_details >> +( ';' >> cabin_details )
- ;
- leg_key =
- (repeat_p(3)[chset_p("0-9A-Z")])[store_board_point(self._flightPeriod)]
- >> ';'
- >> (repeat_p(3)[chset_p("0-9A-Z")])[store_off_point(self._flightPeriod)]
- ;
+ leg_key =
+ lexeme[ repeat(3)[char_("A-Z")] ]
+ >> ';'
+ >> lexeme[ repeat(3)[char_("A-Z")] ]
+ >> ';'
+ ;
- leg_details =
- time[store_board_time(self._flightPeriod)]
- >> !(date_offset)
- >> ';'
- >> time[store_off_time(self._flightPeriod)]
- >> !(date_offset)
- >> ';'
- >> time[store_elapsed_time(self._flightPeriod)]
- ;
+ leg_details =
+ time
+ >> ';' >> time
+ >> ';' >> time
+ >> ';'
+ ;
- time = lexeme_d[ limit_d(0u,23u)[uint2_p][assign_a(self._flightPeriod._itHours)]
- >> ':' >> limit_d(0u,59u)[uint2_p][assign_a(self._flightPeriod._itMinutes)]
- >> !(':' >> limit_d(0u,59u)[uint2_p][assign_a(self._flightPeriod._itSeconds)]) ]
- ;
+ time = lexeme[ uint2_p
+ >> ':' >> uint2_p
+ >> !(':' >> uint2_p) ]
+ ;
+
+ cabin_details = char_("A-Z") [store_cabin_code_t(_t)]
+ >> ';' >> double_
+ >> ';'
+ ;
- date_offset =
- boost::spirit::classic::ch_p('/')
- >> (int1_p)[boost::spirit::classic::assign_a(self._flightPeriod._dateOffSet)]
- ;
-
- cabin_details = (chset_p("A-Z"))[store_cabin_code(self._flightPeriod)]
- >> ';' >> (boost::spirit::classic::ureal_p)[store_capacity(self._flightPeriod)]
- ;
-
- segment_key =
- (repeat_p(3)[chset_p("0-9A-Z")])[store_segment_board_point(self._fl...
[truncated message content] |
|
From: <den...@us...> - 2010-11-02 17:48:03
|
Revision: 147
http://dsim.svn.sourceforge.net/dsim/?rev=147&view=rev
Author: denis_arnaud
Date: 2010-11-02 17:47:57 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
[Test] Fixed the DB issue (however, a local MySQL instance must run, and the sim_dsim database must have been created).
Modified Paths:
--------------
trunk/dsim/test/dsim/SimulationTestSuite.cpp
Modified: trunk/dsim/test/dsim/SimulationTestSuite.cpp
===================================================================
--- trunk/dsim/test/dsim/SimulationTestSuite.cpp 2010-11-02 17:45:52 UTC (rev 146)
+++ trunk/dsim/test/dsim/SimulationTestSuite.cpp 2010-11-02 17:47:57 UTC (rev 147)
@@ -45,28 +45,21 @@
// Initialise the simulation context
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
- const stdair::BasDBParams lDBParams ("dsim", "dsim",
- "localhost", "3306",
+ const stdair::BasDBParams lDBParams ("dsim", "dsim", "localhost", "3306",
"sim_dsim");
DSIM::DSIM_Service dsimService (lLogParams, lDBParams,
lScheduleInputFilename, lODInputFilename,
- lDemandInputFilename, lFareInputFilename);
+ lFareInputFilename, lDemandInputFilename);
// Perform a simulation
dsimService.simulate();
-
+
} catch (const DSIM::RootException& otexp) {
- std::cerr << "Standard exception: " << otexp.what() << std::endl;
- return;
+ std::cerr << "DSim exception: " << otexp.what() << std::endl;
} catch (const std::exception& stde) {
std::cerr << "Standard exception: " << stde.what() << std::endl;
- return;
-
- } catch (...) {
- return;
}
-
}
// //////////////////////////////////////////////////////////////////////
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-11-02 17:45:58
|
Revision: 146
http://dsim.svn.sourceforge.net/dsim/?rev=146&view=rev
Author: denis_arnaud
Date: 2010-11-02 17:45:52 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
[Dev] Removed the exception try-catch clause, as it was hindering to get the call stack in case of exception.
Modified Paths:
--------------
trunk/dsim/dsim/batches/simulate.cpp
Modified: trunk/dsim/dsim/batches/simulate.cpp
===================================================================
--- trunk/dsim/dsim/batches/simulate.cpp 2010-11-02 15:04:31 UTC (rev 145)
+++ trunk/dsim/dsim/batches/simulate.cpp 2010-11-02 17:45:52 UTC (rev 146)
@@ -273,72 +273,68 @@
// ///////// M A I N ////////////
int main (int argc, char* argv[]) {
- try {
+ // Query
+ std::string lQuery;
- // Query
- std::string lQuery;
+ // Demand input file name
+ stdair::Filename_T lDemandInputFilename;
- // Demand input file name
- stdair::Filename_T lDemandInputFilename;
+ // Schedule input file name
+ stdair::Filename_T lScheduleInputFilename;
- // Schedule input file name
- stdair::Filename_T lScheduleInputFilename;
-
- // O&D input filename
- std::string lOnDInputFilename;
+ // O&D input filename
+ std::string lOnDInputFilename;
- // Fare input filename
- std::string lFareInputFilename;
+ // Fare input filename
+ std::string lFareInputFilename;
- // Output log File
- std::string lLogFilename;
+ // Output log File
+ std::string lLogFilename;
- // SQL database parameters
- std::string lDBUser;
- std::string lDBPasswd;
- std::string lDBHost;
- std::string lDBPort;
- std::string lDBDBName;
+ // SQL database parameters
+ std::string lDBUser;
+ std::string lDBPasswd;
+ std::string lDBHost;
+ std::string lDBPort;
+ std::string lDBDBName;
- // Airline code
- stdair::AirlineCode_T lAirlineCode ("BA");
+ // Airline code
+ stdair::AirlineCode_T lAirlineCode ("BA");
- // Call the command-line option parser
- const int lOptionParserStatus =
- readConfiguration (argc, argv, lQuery, lDemandInputFilename,
- lScheduleInputFilename, lOnDInputFilename,
- lFareInputFilename, lLogFilename,
- lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
+ // Call the command-line option parser
+ const int lOptionParserStatus =
+ readConfiguration (argc, argv, lQuery, lDemandInputFilename,
+ lScheduleInputFilename, lOnDInputFilename,
+ lFareInputFilename, lLogFilename,
+ lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
- if (lOptionParserStatus == K_DSIM_EARLY_RETURN_STATUS) {
- return 0;
- }
+ if (lOptionParserStatus == K_DSIM_EARLY_RETURN_STATUS) {
+ return 0;
+ }
- // Set the database parameters
- stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort,
- lDBDBName);
+ // Set the database parameters
+ stdair::BasDBParams lDBParams (lDBUser, lDBPasswd, lDBHost, lDBPort,
+ lDBDBName);
- // Set the log parameters
- std::ofstream logOutputFile;
- // open and clean the log outputfile
- logOutputFile.open (lLogFilename.c_str());
- logOutputFile.clear();
+ // Set the log parameters
+ std::ofstream logOutputFile;
+ // open and clean the log outputfile
+ logOutputFile.open (lLogFilename.c_str());
+ logOutputFile.clear();
- // Initialise the simulation context
- const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
- DSIM::DSIM_Service dsimService (lLogParams, lDBParams,
- lScheduleInputFilename, lOnDInputFilename,
- lFareInputFilename, lDemandInputFilename);
+ // Initialise the simulation context
+ const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
+ DSIM::DSIM_Service dsimService (lLogParams, lDBParams,
+ lScheduleInputFilename, lOnDInputFilename,
+ lFareInputFilename, lDemandInputFilename);
- // Perform a simulation
- dsimService.simulate();
+ // Perform a simulation
+ dsimService.simulate();
- // DEBUG
- // Display the airlines stored in the database
- dsimService.displayAirlineListFromDB();
+ // DEBUG
+ // Display the airlines stored in the database
+ dsimService.displayAirlineListFromDB();
- } CATCH_ALL_EXCEPTIONS
-
return 0;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <gsa...@us...> - 2010-11-02 15:04:37
|
Revision: 145
http://dsim.svn.sourceforge.net/dsim/?rev=145&view=rev
Author: gsabatier
Date: 2010-11-02 15:04:31 +0000 (Tue, 02 Nov 2010)
Log Message:
-----------
Created parser of the simfqt module
Modified Paths:
--------------
trunk/dsim/dsim/command/Simulator.cpp
Modified: trunk/dsim/dsim/command/Simulator.cpp
===================================================================
--- trunk/dsim/dsim/command/Simulator.cpp 2010-10-20 15:55:11 UTC (rev 144)
+++ trunk/dsim/dsim/command/Simulator.cpp 2010-11-02 15:04:31 UTC (rev 145)
@@ -92,8 +92,10 @@
ioSIMCRS_Service.getTravelSolutions (iBookingRequest);
if (lTravelSolutionList.empty() == false) {
// Get the fare quote for each travel solution.
+ ioSIMCRS_Service.getFare(lTravelSolutionList);
+
// Get the availability for each travel solution.
- //ioSIMCRS_Service.getAvailability (lTravelSolutionList);
+ ioSIMCRS_Service.getAvailability (lTravelSolutionList);
// Hardcode a travel solution choice.
stdair::TravelSolutionList_T::iterator itTS = lTravelSolutionList.begin();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-10-20 15:55:17
|
Revision: 144
http://dsim.svn.sourceforge.net/dsim/?rev=144&view=rev
Author: denis_arnaud
Date: 2010-10-20 15:55:11 +0000 (Wed, 20 Oct 2010)
Log Message:
-----------
[Dev] Added missing input files as option of the batch.
Modified Paths:
--------------
trunk/dsim/dsim/batches/simulate.cpp
Modified: trunk/dsim/dsim/batches/simulate.cpp
===================================================================
--- trunk/dsim/dsim/batches/simulate.cpp 2010-10-15 09:59:36 UTC (rev 143)
+++ trunk/dsim/dsim/batches/simulate.cpp 2010-10-20 15:55:11 UTC (rev 144)
@@ -32,6 +32,12 @@
/** Default name and location for the (CSV) schedule input file. */
const std::string K_DSIM_DEFAULT_SCHEDULE_INPUT_FILENAME ("../../test/samples/schedule01.csv");
+/** Default name and location for the (CSV) O&D input file. */
+const std::string K_DSIM_DEFAULT_OND_INPUT_FILENAME ("../../test/samples/ond01.csv");
+
+/** Default name and location for the (CSV) fare input file. */
+const std::string K_DSIM_DEFAULT_FARE_INPUT_FILENAME ("../../test/samples/fare01.csv");
+
/** Default query string. */
const std::string K_DSIM_DEFAULT_QUERY_STRING ("my good old query");
@@ -97,8 +103,10 @@
/** Read and parse the command line options. */
int readConfiguration (int argc, char* argv[],
std::string& ioQueryString,
+ stdair::Filename_T& ioDemandInputFilename,
stdair::Filename_T& ioScheduleInputFilename,
- stdair::Filename_T& ioDemandInputFilename,
+ stdair::Filename_T& ioOnDInputFilename,
+ stdair::Filename_T& ioFareInputFilename,
std::string& ioLogFilename,
std::string& ioDBUser, std::string& ioDBPasswd,
std::string& ioDBHost, std::string& ioDBPort,
@@ -125,11 +133,17 @@
boost::program_options::options_description config ("Configuration");
config.add_options()
("demand,d",
- boost::program_options::value< std::string >(&ioScheduleInputFilename)->default_value(K_DSIM_DEFAULT_DEMAND_INPUT_FILENAME),
+ boost::program_options::value< std::string >(&ioDemandInputFilename)->default_value(K_DSIM_DEFAULT_DEMAND_INPUT_FILENAME),
"(CVS) input file for the demand distributions")
("schedule,s",
- boost::program_options::value< std::string >(&ioDemandInputFilename)->default_value(K_DSIM_DEFAULT_SCHEDULE_INPUT_FILENAME),
+ boost::program_options::value< std::string >(&ioScheduleInputFilename)->default_value(K_DSIM_DEFAULT_SCHEDULE_INPUT_FILENAME),
"(CVS) input file for the schedules")
+ ("ond,o",
+ boost::program_options::value< std::string >(&ioOnDInputFilename)->default_value(K_DSIM_DEFAULT_OND_INPUT_FILENAME),
+ "(CVS) input file for the O&D definitions")
+ ("fare,f",
+ boost::program_options::value< std::string >(&ioFareInputFilename)->default_value(K_DSIM_DEFAULT_FARE_INPUT_FILENAME),
+ "(CVS) input file for the fares")
("log,l",
boost::program_options::value< std::string >(&ioLogFilename)->default_value(K_DSIM_DEFAULT_LOG_FILENAME),
"Filepath for the logs")
@@ -198,18 +212,28 @@
return K_DSIM_EARLY_RETURN_STATUS;
}
+ if (vm.count ("demand")) {
+ ioDemandInputFilename = vm["demand"].as< std::string >();
+ std::cout << "Demand input filename is: " << ioDemandInputFilename
+ << std::endl;
+ }
+
+ if (vm.count ("ond")) {
+ ioOnDInputFilename = vm["ond"].as< std::string >();
+ std::cout << "O&D input filename is: " << ioOnDInputFilename << std::endl;
+ }
+
+ if (vm.count ("fare")) {
+ ioFareInputFilename = vm["fare"].as< std::string >();
+ std::cout << "Fare input filename is: " << ioFareInputFilename << std::endl;
+ }
+
if (vm.count ("schedule")) {
ioScheduleInputFilename = vm["schedule"].as< std::string >();
std::cout << "Schedule input filename is: " << ioScheduleInputFilename
<< std::endl;
}
- if (vm.count ("demand")) {
- ioDemandInputFilename = vm["demand"].as< std::string >();
- std::cout << "Demand input filename is: " << ioDemandInputFilename
- << std::endl;
- }
-
if (vm.count ("log")) {
ioLogFilename = vm["log"].as< std::string >();
std::cout << "Log filename is: " << ioLogFilename << std::endl;
@@ -254,12 +278,18 @@
// Query
std::string lQuery;
+ // Demand input file name
+ stdair::Filename_T lDemandInputFilename;
+
// Schedule input file name
stdair::Filename_T lScheduleInputFilename;
- // Demand input file name
- stdair::Filename_T lDemandInputFilename;
-
+ // O&D input filename
+ std::string lOnDInputFilename;
+
+ // Fare input filename
+ std::string lFareInputFilename;
+
// Output log File
std::string lLogFilename;
@@ -275,8 +305,9 @@
// Call the command-line option parser
const int lOptionParserStatus =
- readConfiguration (argc, argv, lQuery, lScheduleInputFilename,
- lDemandInputFilename, lLogFilename,
+ readConfiguration (argc, argv, lQuery, lDemandInputFilename,
+ lScheduleInputFilename, lOnDInputFilename,
+ lFareInputFilename, lLogFilename,
lDBUser, lDBPasswd, lDBHost, lDBPort, lDBDBName);
if (lOptionParserStatus == K_DSIM_EARLY_RETURN_STATUS) {
@@ -296,8 +327,8 @@
// Initialise the simulation context
const stdair::BasLogParams lLogParams (stdair::LOG::DEBUG, logOutputFile);
DSIM::DSIM_Service dsimService (lLogParams, lDBParams,
- lScheduleInputFilename,
- lDemandInputFilename);
+ lScheduleInputFilename, lOnDInputFilename,
+ lFareInputFilename, lDemandInputFilename);
// Perform a simulation
dsimService.simulate();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <den...@us...> - 2010-10-15 09:59:42
|
Revision: 143
http://dsim.svn.sourceforge.net/dsim/?rev=143&view=rev
Author: denis_arnaud
Date: 2010-10-15 09:59:36 +0000 (Fri, 15 Oct 2010)
Log Message:
-----------
[Test] Fixed the SimFQT linking issue with the DSim test.
Modified Paths:
--------------
trunk/dsim/test/dsim/Makefile.am
Modified: trunk/dsim/test/dsim/Makefile.am
===================================================================
--- trunk/dsim/test/dsim/Makefile.am 2010-10-15 09:28:16 UTC (rev 142)
+++ trunk/dsim/test/dsim/Makefile.am 2010-10-15 09:59:36 UTC (rev 143)
@@ -19,4 +19,6 @@
SimulationTestSuite_LDADD =
SimulationTestSuite_LDFLAGS = \
$(BOOST_LIBS) $(CPPUNIT_LIBS) $(EXTRACC_LIBS) $(STDAIR_LIBS) \
+ $(top_builddir)/simfqt/core/libsimfqt.la \
$(top_builddir)/dsim/core/libdsim.la
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <qua...@us...> - 2010-10-15 09:28:23
|
Revision: 142
http://dsim.svn.sourceforge.net/dsim/?rev=142&view=rev
Author: quannaus
Date: 2010-10-15 09:28:16 +0000 (Fri, 15 Oct 2010)
Log Message:
-----------
[test] Adapted the test suite to the new interface.
Modified Paths:
--------------
trunk/dsim/test/dsim/SimulationTestSuite.cpp
Modified: trunk/dsim/test/dsim/SimulationTestSuite.cpp
===================================================================
--- trunk/dsim/test/dsim/SimulationTestSuite.cpp 2010-10-15 09:27:53 UTC (rev 141)
+++ trunk/dsim/test/dsim/SimulationTestSuite.cpp 2010-10-15 09:28:16 UTC (rev 142)
@@ -24,9 +24,15 @@
// Schedule input file name
const std::string lScheduleInputFilename ("../samples/schedule01.csv");
+
+ // O&D input file name
+ const std::string lODInputFilename ("../samples/ond01.csv");
// Demand input file name
const stdair::Filename_T lDemandInputFilename ("../samples/demand01.csv");
+
+ // Fare input file name
+ const stdair::Filename_T lFareInputFilename ("../samples/fare01.csv");
// Output log File
const std::string lLogFilename ("SimulationTestSuite.log");
@@ -43,8 +49,8 @@
"localhost", "3306",
"sim_dsim");
DSIM::DSIM_Service dsimService (lLogParams, lDBParams,
- lScheduleInputFilename,
- lDemandInputFilename);
+ lScheduleInputFilename, lODInputFilename,
+ lDemandInputFilename, lFareInputFilename);
// Perform a simulation
dsimService.simulate();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|