OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
data_def.hpp
Go to the documentation of this file.
1 //
2 // Copyright & License: See Copyright.readme in src directory
3 //
4 
9 #ifndef DATA_DEF_HPP_
10 #define DATA_DEF_HPP_
11 
12 #include "data.hpp"
13 
14 #include <boost/spirit/include/phoenix_core.hpp>
15 #include <boost/spirit/include/phoenix_operator.hpp>
16 #include <boost/spirit/include/phoenix_fusion.hpp>
17 #include <boost/spirit/include/phoenix_bind.hpp>
18 
19 namespace SDDS { namespace parser
20 {
21  template <typename Iterator>
22  data_parser<Iterator>::data_parser(error_handler<Iterator> & _error_handler):
23  data_parser::base_type(start)
24  {
25  using qi::on_error;
26  using qi::fail;
27  using phx::function;
28  typedef function<error_handler<Iterator> > error_handler_function;
29 
30  qi::_1_type _1;
31  qi::_3_type _3;
32  qi::_4_type _4;
33  qi::lit_type lit;
34  qi::long_type long_;
35  qi::short_type short_;
36  qi::_val_type _val;
37  qi::_pass_type _pass;
38  qi::eps_type eps;
39 
40  datamode.add
41  ("ascii", ast::ASCII)
42  ("binary", ast::BINARY)
43  ;
44  dataendian.add
45  ("big", ast::BIGENDIAN)
46  ("little", ast::LITTLEENDIAN)
47  ;
48 
49  data_mode = lit("mode") > '=' > datamode;
50  data_lines = lit("lines_per_row") > '=' > long_;
51  data_row = lit("no_row_counts") > '=' > long_;
52  data_fixed = lit("fixed_row_count") > '=' > long_;
53  data_additional = lit("additional_header_lines") > '=' > long_;
54  data_column = lit("column_major_order") > '=' > short_;
55  data_endian = lit("endian") > '=' > dataendian;
56 
57  auto complainLines = phx::bind(&data::complainUnsupported<data::LINES_PER_ROW>::apply);
58  auto complainFixed = phx::bind(&data::complainUnsupported<data::FIXED_ROW_COUNT>::apply);
59  auto complainAdditional = phx::bind(&data::complainUnsupported<data::ADDITIONAL_HEADER_LINES>::apply);
60  auto complainColumn = phx::bind(&data::complainUnsupported<data::COLUMN_MAJOR_ORDER>::apply);
61  auto complainEndian = phx::bind(&data::complainUnsupported<data::ENDIAN>::apply);
62 
63  data_unsupported_pre =
64  ((',' > data_lines[_pass = complainLines])
65  ^ (',' > data_fixed[_pass = complainFixed])
66  ^ (',' > data_additional[_pass = complainAdditional])
67  ^ (',' > data_column[_pass = complainColumn])
68  ^ (',' > data_endian[_pass = complainEndian]));
69  data_unsupported_post =
70  ((data_lines[_pass = complainLines] > ',')
71  ^ (data_fixed[_pass = complainFixed] > ',')
72  ^ (data_additional[_pass = complainAdditional] > ',')
73  ^ (data_column[_pass = complainColumn] > ',')
74  ^ (data_endian[_pass = complainEndian] > ','));
75 
76  start =
77  lit("&data")
78  > -data_unsupported_post
79  > ((data_mode[phx::at_c<0>(_val) = _1] >> ',' >> data_row[phx::at_c<1>(_val) = _1])
80  | (data_row[phx::at_c<1>(_val) = _1] >> ',' >> data_mode[phx::at_c<0>(_val) = _1]))
81  > -data_unsupported_pre
82  > lit("&end")
83  >> eps[_pass = phx::bind(&data::isASCII, _val)];
84 
85  BOOST_SPIRIT_DEBUG_NODES(
86  (start)
87  )
88 
89  on_error<fail>(start,
90  error_handler_function(_error_handler)(
91  std::string("Error! Expecting "), _4, _3));
92  }
93 }}
94 #endif /* DATA_DEF_HPP_ */
datamode
Definition: ast.hpp:27