OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
data_def.hpp
Go to the documentation of this file.
1//
2// Struct data
3//
4// Copyright (c) 2015, Christof Metzger-Kraus, Helmholtz-Zentrum Berlin
5// All rights reserved
6//
7// This file is part of OPAL.
8//
9// OPAL is free software: you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 3 of the License, or
12// (at your option) any later version.
13//
14// You should have received a copy of the GNU General Public License
15// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
16//
17#ifndef DATA_DEF_HPP_
18#define DATA_DEF_HPP_
19
20#include "data.hpp"
21
22#include <boost/spirit/include/phoenix_core.hpp>
23#include <boost/spirit/include/phoenix_operator.hpp>
24#include <boost/spirit/include/phoenix_fusion.hpp>
25#include <boost/spirit/include/phoenix_bind.hpp>
26
27namespace SDDS { namespace parser
28{
29 template <typename Iterator>
30 data_parser<Iterator>::data_parser(error_handler<Iterator> & _error_handler):
31 data_parser::base_type(start)
32 {
33 using qi::on_error;
34 using qi::fail;
35 using phx::function;
36 typedef function<error_handler<Iterator> > error_handler_function;
37
38 qi::_1_type _1;
39 qi::_3_type _3;
40 qi::_4_type _4;
41 qi::lit_type lit;
42 qi::long_type long_;
43 qi::short_type short_;
44 qi::_val_type _val;
45 qi::_pass_type _pass;
46 qi::eps_type eps;
47
48 datamode.add
49 ("ascii", ast::ASCII)
50 ("binary", ast::BINARY)
51 ;
52 dataendian.add
53 ("big", ast::BIGENDIAN)
54 ("little", ast::LITTLEENDIAN)
55 ;
56
57 data_mode = lit("mode") > '=' > datamode;
58 data_lines = lit("lines_per_row") > '=' > long_;
59 data_row = lit("no_row_counts") > '=' > long_;
60 data_fixed = lit("fixed_row_count") > '=' > long_;
61 data_additional = lit("additional_header_lines") > '=' > long_;
62 data_column = lit("column_major_order") > '=' > short_;
63 data_endian = lit("endian") > '=' > dataendian;
64
65 auto complainLines = phx::bind(&data::complainUnsupported<data::LINES_PER_ROW>::apply);
66 auto complainFixed = phx::bind(&data::complainUnsupported<data::FIXED_ROW_COUNT>::apply);
67 auto complainAdditional = phx::bind(&data::complainUnsupported<data::ADDITIONAL_HEADER_LINES>::apply);
68 auto complainColumn = phx::bind(&data::complainUnsupported<data::COLUMN_MAJOR_ORDER>::apply);
69 auto complainEndian = phx::bind(&data::complainUnsupported<data::ENDIAN>::apply);
70
71 data_unsupported_pre =
72 ((',' > data_lines[_pass = complainLines])
73 ^ (',' > data_fixed[_pass = complainFixed])
74 ^ (',' > data_additional[_pass = complainAdditional])
75 ^ (',' > data_column[_pass = complainColumn])
76 ^ (',' > data_endian[_pass = complainEndian]));
77 data_unsupported_post =
78 ((data_lines[_pass = complainLines] > ',')
79 ^ (data_fixed[_pass = complainFixed] > ',')
80 ^ (data_additional[_pass = complainAdditional] > ',')
81 ^ (data_column[_pass = complainColumn] > ',')
82 ^ (data_endian[_pass = complainEndian] > ','));
83
84 start =
85 lit("&data")
86 > -data_unsupported_post
87 > ((data_mode[phx::at_c<0>(_val) = _1] >> ',' >> data_row[phx::at_c<1>(_val) = _1])
88 | (data_row[phx::at_c<1>(_val) = _1] >> ',' >> data_mode[phx::at_c<0>(_val) = _1]))
89 > -data_unsupported_pre
90 > lit("&end")
91 >> eps[_pass = phx::bind(&data::isASCII, _val)];
92
93 BOOST_SPIRIT_DEBUG_NODES(
94 (start)
95 )
96
97 on_error<fail>(start,
98 error_handler_function(_error_handler)(
99 std::string("Error! Expecting "), _4, _3));
100 }
101}}
102#endif /* DATA_DEF_HPP_ */
py::list function(PolynomialPatch *patch, py::list point)
@ BIGENDIAN
Definition: ast.hpp:38
@ LITTLEENDIAN
Definition: ast.hpp:39
datamode
Definition: ast.hpp:35
@ ASCII
Definition: ast.hpp:35
@ BINARY
Definition: ast.hpp:36