7 #include <stdair/basic/BasFileMgr.hpp>
8 #include <stdair/bom/BomRoot.hpp>
9 #include <stdair/service/Logger.hpp>
16 namespace OnDParserHelper {
26 : _onDPeriod (ioOnDPeriod) {
37 std::string lOrigin (iStr, iStrEnd);
57 std::string lDestination (iStr, iStrEnd);
93 const stdair::DateOffset_T oneDay (1);
146 const std::string lAirlineCodeStr (iStr, iStrEnd);
147 const stdair::AirlineCode_T lAirlineCode(lAirlineCodeStr);
151 std::ostringstream ostr;
155 const stdair::AirlineCode_T lPreviousAirlineCode =
157 if (lPreviousAirlineCode != lAirlineCode) {
178 std::ostringstream ostr;
180 std::string classCodeStr = ostr.str();
181 const stdair::ClassCode_T lClassCode (classCodeStr);
186 std::ostringstream ostrr;
195 _bomRoot (ioBomRoot) {
262 : _bomRoot (ioBomRoot), _onDPeriod (ioOnDPeriod) {
266 template<
typename ScannerT>
269 ond_list = *( boost::spirit::classic::comment_p(
"//")
270 | boost::spirit::classic::comment_p(
"/*",
"*/")
275 >> +(
';' >> segment )
276 >> ond_end[
doEndOnD(
self._bomRoot,
self._onDPeriod)]
279 ond_end = boost::spirit::classic::ch_p(
';')
290 date = boost::spirit::classic::
292 assign_a(
self._onDPeriod._itYear)]
295 assign_a(
self._onDPeriod._itMonth)]
298 assign_a(
self._onDPeriod._itDay)]]
301 time = boost::spirit::classic::
303 assign_a(
self._onDPeriod._itHours)]
306 assign_a(
self._onDPeriod._itMinutes)]
308 assign_a(
self._onDPeriod._itSeconds)])]
311 segment = boost::spirit::classic::
317 BOOST_SPIRIT_DEBUG_NODE (ond_list);
318 BOOST_SPIRIT_DEBUG_NODE (ond);
319 BOOST_SPIRIT_DEBUG_NODE (segment);
320 BOOST_SPIRIT_DEBUG_NODE (ond_key);
321 BOOST_SPIRIT_DEBUG_NODE (ond_end);
322 BOOST_SPIRIT_DEBUG_NODE (date);
323 BOOST_SPIRIT_DEBUG_NODE (time);
328 template<
typename ScannerT>
329 boost::spirit::classic::rule<ScannerT>
const&
343 stdair::BomRoot& ioBomRoot)
344 : _filename (iFilename), _bomRoot (ioBomRoot) {
349 void OnDPeriodFileParser::init() {
351 const bool doesExistAndIsReadable =
352 stdair::BasFileMgr::doesExistAndIsReadable (_filename);
354 if (doesExistAndIsReadable ==
false) {
355 STDAIR_LOG_ERROR (
"The O&D file " << _filename
356 <<
" does not exist or can not be read.");
359 +
" does not exist or can not be read");
366 if (!_startIterator) {
367 STDAIR_LOG_DEBUG (
"The O&D file " << _filename <<
" can not be open."
369 throw OnDInputFileNotFoundException (
"The file " + _filename
370 +
" does not exist or can not be read");
374 _endIterator = _startIterator.make_end();
379 bool oResult =
false;
381 STDAIR_LOG_DEBUG (
"Parsing O&D input file: " << _filename);
388 boost::spirit::classic::parse_info<iterator_t> info =
389 boost::spirit::classic::parse (_startIterator, _endIterator, lODParser,
390 boost::spirit::classic::space_p);
395 const std::string hasBeenFullyReadStr = (info.full ==
true)?
"":
"not ";
396 if (oResult ==
true) {
397 STDAIR_LOG_DEBUG (
"Parsing of O&D input file: " << _filename
398 <<
" succeeded: read " << info.length
399 <<
" characters. The input file has "
400 << hasBeenFullyReadStr
401 <<
"been fully read. Stop point: " << info.stop);
405 STDAIR_LOG_ERROR (
"Parsing of O&D input file: " << _filename
406 <<
" failed: read " << info.length
407 <<
" characters. The input file has "
408 << hasBeenFullyReadStr
409 <<
"been fully read. Stop point: " << info.stop);
void operator()(iterator_t iStr, iterator_t iStrEnd) const
bounded4_p_t year_p(uint4_p.derived(), 2000u, 2099u)
doEndOnD(stdair::BomRoot &, OnDPeriodStruct &)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
boost::spirit::classic::uint_parser< unsigned int, 10, 1, 4 > uint1_4_p_t
storeDestination(OnDPeriodStruct &)
boost::spirit::classic::chset< char_t > chset_t
boost::spirit::classic::rule< ScannerT > const & start() const
bounded2_p_t day_p(uint2_p.derived(), 1u, 31u)
bounded2_p_t seconds_p(uint2_p.derived(), 0u, 59u)
boost::spirit::classic::uint_parser< unsigned int, 10, 2, 2 > uint2_p_t
bounded2_p_t minutes_p(uint2_p.derived(), 0u, 59u)
stdair::Date_T getDate() const
OnDParser(stdair::BomRoot &, OnDPeriodStruct &)
stdair::Duration_T _timeRangeStart
stdair::ClassCodeList_T _classCodeList
stdair::NbOfAirlines_T _nbOfAirlines
void operator()(iterator_t iStr, iterator_t iStrEnd) const
void operator()(iterator_t iStr, iterator_t iStrEnd) const
chset_t alpha_cap_set_p("A-Z")
stdair::ClassCode_T _classCode
bool generateOnDPeriods()
storeAirlineCode(OnDPeriodStruct &)
boost::spirit::classic::file_iterator< char_t > iterator_t
definition(OnDParser const &self)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
bounded2_p_t hours_p(uint2_p.derived(), 0u, 23u)
stdair::DatePeriod_T _datePeriod
ParserSemanticAction(OnDPeriodStruct &)
chset_t class_code_p("A-Z")
stdair::Duration_T _timeRangeEnd
storeOrigin(OnDPeriodStruct &)
storeStartRangeTime(OnDPeriodStruct &)
stdair::AirportCode_T _destination
void operator()(iterator_t iStr, iterator_t iStrEnd) const
bounded2_p_t month_p(uint2_p.derived(), 1u, 12u)
void operator()(iterator_t iStr, iterator_t iStrEnd) const
stdair::AirportCode_T _origin
boost::spirit::classic::impl::loop_traits< chset_t, unsigned int, unsigned int >::type repeat_p_t
boost::spirit::classic::bounded< uint2_p_t, unsigned int > bounded2_p_t
OnDPeriodFileParser(const stdair::Filename_T &iFilename, stdair::BomRoot &ioBomRoot)
void operator()(char iChar) const
storeDateRangeEnd(OnDPeriodStruct &)
repeat_p_t airport_p(chset_t("0-9A-Z").derived(), 3, 3)
storeClassCode(OnDPeriodStruct &)
stdair::AirlineCode_T _airlineCode
stdair::Duration_T getTime() const
stdair::Date_T _dateRangeEnd
boost::spirit::classic::uint_parser< unsigned int, 10, 4, 4 > uint4_p_t
void operator()(iterator_t iStr, iterator_t iStrEnd) const
OnDPeriodStruct & _onDPeriod
repeat_p_t airline_code_p(alpha_cap_set_p.derived(), 2, 3)
storeEndRangeTime(OnDPeriodStruct &)
stdair::BomRoot & _bomRoot
stdair::Date_T _dateRangeStart
storeDateRangeStart(OnDPeriodStruct &)
stdair::AirlineCodeList_T _airlineCodeList
boost::spirit::classic::bounded< uint4_p_t, unsigned int > bounded4_p_t