OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BasParserTypes.hpp
Go to the documentation of this file.
1 #ifndef __OPENTREP_BAS_BASPARSERTYPES_HPP
2 #define __OPENTREP_BAS_BASPARSERTYPES_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <string>
9 // Boost Spirit (Parsing)
10 #include <boost/spirit/include/qi.hpp>
11 #include <boost/spirit/include/phoenix_core.hpp>
12 #include <boost/spirit/include/phoenix_operator.hpp>
13 #include <boost/spirit/include/support_multi_pass.hpp>
14 #include <boost/spirit/include/classic_position_iterator.hpp>
15 // OpenTREP
17 
18 namespace OPENTREP {
19 
20  // ////////////////////////////////////////////////////////////////////
21  //
22  // Definition of Basic Types
23  //
24  // ////////////////////////////////////////////////////////////////////
25  // The types of iterator, scanner and rule are then derived from
26  // the parsing unit.
27  typedef std::istreambuf_iterator<char> base_iterator_t;
28  typedef boost::spirit::multi_pass<base_iterator_t> iterator_t;
29 
30  // Wrap the forward iterator with position iterator, to record the position
31  typedef boost::spirit::classic::position_iterator2<iterator_t> pos_iterator_t;
32 
33 
34  // ////////////////////////////////////////////////////////////////////
35  //
36  // Parser related types
37  //
38  // ////////////////////////////////////////////////////////////////////
40  typedef boost::spirit::qi::uint_parser<int, 10, 1, 1> uint1_p_t;
41 
43  typedef boost::spirit::qi::uint_parser<int, 10, 2, 2> uint2_p_t;
44 
46  typedef boost::spirit::qi::uint_parser<int, 10, 1, 2> int1_2_p_t;
47 
49  typedef boost::spirit::qi::uint_parser<int, 10, 4, 4> uint4_p_t;
50 
52  typedef boost::spirit::qi::int_parser<int, 10, 1, 5> int1_5_p_t;
53  typedef boost::spirit::qi::int_parser<int, 10, 0, 5> int0_5_p_t;
54 
56  typedef boost::spirit::qi::uint_parser<int, 10, 1, 4> uint1_4_p_t;
57 
59  typedef boost::spirit::qi::uint_parser<int, 10, 1, 9> uint1_9_p_t;
60  typedef boost::spirit::qi::uint_parser<int, 10, 0, 9> uint0_9_p_t;
61 
63  typedef boost::spirit::qi::uint_parser<hour_t, 10, 2, 2> hour_p_t;
64  typedef boost::spirit::qi::uint_parser<minute_t, 10, 2, 2> minute_p_t;
65  typedef boost::spirit::qi::uint_parser<second_t, 10, 2, 2> second_p_t;
66  typedef boost::spirit::qi::uint_parser<year_t, 10, 4, 4> year_p_t;
67  typedef boost::spirit::qi::uint_parser<month_t, 10, 2, 2> month_p_t;
68  typedef boost::spirit::qi::uint_parser<day_t, 10, 2, 2> day_p_t;
69 
71  struct short_bool_policies : boost::spirit::qi::bool_policies<> {
72  template <typename Iterator, typename Attribute>
73  static bool parse_true (Iterator& first, Iterator const& last,
74  Attribute& attr) {
75  if (boost::spirit::qi::detail::string_parse ("Y", first, last,
76  boost::spirit::qi::unused)) {
77  // Result is true
78  boost::spirit::traits::assign_to (true, attr);
79  return true;
80  }
81  return false;
82  }
83 
84  // 'Y' will return true and 'N' false
85  template <typename Iterator, typename Attribute>
86  static bool parse_false (Iterator& first, Iterator const& last,
87  Attribute& attr) {
88  if (boost::spirit::qi::detail::string_parse ("N", first, last,
89  boost::spirit::qi::unused)
90  ||
91  boost::spirit::qi::detail::string_parse ("Z", first, last,
92  boost::spirit::qi::unused)) {
93  // Result is false
94  boost::spirit::traits::assign_to (false, attr);
95  return true;
96  }
97  return false;
98  }
99  };
100 
101  typedef boost::spirit::qi::bool_parser<bool, short_bool_policies> boolean_p_t;
102 
103 }
104 #endif // __OPENTREP_BAS_BASPARSERTYPES_HPP
static bool parse_false(Iterator &first, Iterator const &last, Attribute &attr)
boost::spirit::qi::uint_parser< month_t, 10, 2, 2 > month_p_t
std::istreambuf_iterator< char > base_iterator_t
boost::spirit::qi::int_parser< int, 10, 0, 5 > int0_5_p_t
boost::spirit::qi::uint_parser< second_t, 10, 2, 2 > second_p_t
boost::spirit::qi::uint_parser< hour_t, 10, 2, 2 > hour_p_t
boost::spirit::qi::uint_parser< int, 10, 2, 2 > uint2_p_t
boost::spirit::qi::uint_parser< int, 10, 1, 9 > uint1_9_p_t
boost::spirit::qi::int_parser< int, 10, 1, 5 > int1_5_p_t
static bool parse_true(Iterator &first, Iterator const &last, Attribute &attr)
boost::spirit::qi::uint_parser< year_t, 10, 4, 4 > year_p_t
boost::spirit::qi::uint_parser< int, 10, 1, 1 > uint1_p_t
boost::spirit::qi::bool_parser< bool, short_bool_policies > boolean_p_t
boost::spirit::qi::uint_parser< int, 10, 1, 2 > int1_2_p_t
boost::spirit::qi::uint_parser< int, 10, 4, 4 > uint4_p_t
boost::spirit::qi::uint_parser< day_t, 10, 2, 2 > day_p_t
boost::spirit::qi::uint_parser< int, 10, 1, 4 > uint1_4_p_t
boost::spirit::qi::uint_parser< minute_t, 10, 2, 2 > minute_p_t
boost::spirit::multi_pass< base_iterator_t > iterator_t
boost::spirit::qi::uint_parser< int, 10, 0, 9 > uint0_9_p_t
boost::spirit::classic::position_iterator2< iterator_t > pos_iterator_t