OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
data.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_HPP_
18#define DATA_HPP_
19
20#include "ast.hpp"
21#include "skipper.hpp"
22#include "error_handler.hpp"
23
24#include <boost/config/warning_disable.hpp>
25#include <boost/spirit/include/qi.hpp>
26#include <boost/fusion/include/adapt_struct.hpp>
27
28#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
29#define BOOST_SPIRIT_QI_DEBUG
30
31namespace SDDS {
32 struct data
33 {
41 };
42
45
46 bool isASCII() const
47 {
48 if (mode_m == ast::BINARY) {
49 std::cerr << "can't handle binary data yet" << std::endl;
50 return false;
51 }
52 return true;
53 }
54
55 template <attributes A>
57 {
58 static bool apply()
59 {
60 std::string attributeString;
61 switch(A)
62 {
63 case LINES_PER_ROW:
64 attributeString = "lines_per_row";
65 break;
66 case NO_ROW_COUNT:
67 attributeString = "no_row_count";
68 break;
69 case FIXED_ROW_COUNT:
70 attributeString = "fixed_row_count";
71 break;
73 attributeString = "additional_header_lines";
74 break;
76 attributeString = "column_major_order";
77 break;
78 case ENDIAN:
79 attributeString = "endian";
80 break;
81 default:
82 return true;
83 }
84 std::cerr << attributeString << " not supported yet" << std::endl;
85 return false;
86 }
87 };
88 };
89
90 inline std::ostream& operator<<(std::ostream& out, const data& data_) {
91 out << "mode = " << data_.mode_m;
92 return out;
93 }
94}
95
98 (SDDS::ast::datamode, mode_m)
99 (long, numberRows_m)
100)
101
102namespace SDDS { namespace parser
103{
104 namespace qi = boost::spirit::qi;
105 namespace ascii = boost::spirit::ascii;
106 namespace phx = boost::phoenix;
107
108 template <typename Iterator>
109 struct data_parser: qi::grammar<Iterator, data(), skipper<Iterator> >
110 {
111 data_parser(error_handler<Iterator> & _error_handler);
112
113 qi::rule<Iterator, data(), skipper<Iterator> > start;
114 qi::rule<Iterator, ast::datamode(), skipper<Iterator> > data_mode;
115 qi::rule<Iterator, long(), skipper<Iterator> > data_lines,
116 data_row, data_fixed, data_additional;
117 qi::rule<Iterator, short(), skipper<Iterator> > data_column;
118 qi::rule<Iterator, ast::endianess(), skipper<Iterator> > data_endian;
119 qi::rule<Iterator, ast::nil(), skipper<Iterator> > data_unsupported_pre,
120 data_unsupported_post;
121 qi::symbols<char, ast::endianess> dataendian;
122 qi::symbols<char, ast::datamode> datamode;
123 };
124}}
125#endif /* DATA_HPP_ */
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
BOOST_FUSION_ADAPT_STRUCT(SDDS::data,(SDDS::ast::datamode, mode_m)(long, numberRows_m)) namespace SDDS
Definition: data.hpp:96
std::ostream & operator<<(std::ostream &out, const array &)
Definition: array.hpp:97
endianess
Definition: ast.hpp:38
datamode
Definition: ast.hpp:35
@ BINARY
Definition: ast.hpp:36
bool isASCII() const
Definition: data.hpp:46
attributes
Definition: data.hpp:34
@ ENDIAN
Definition: data.hpp:40
@ LINES_PER_ROW
Definition: data.hpp:35
@ FIXED_ROW_COUNT
Definition: data.hpp:37
@ COLUMN_MAJOR_ORDER
Definition: data.hpp:39
@ ADDITIONAL_HEADER_LINES
Definition: data.hpp:38
@ NO_ROW_COUNT
Definition: data.hpp:36
@ MODE
Definition: data.hpp:34
long numberRows_m
Definition: data.hpp:44
ast::datamode mode_m
Definition: data.hpp:43