OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
file.hpp
Go to the documentation of this file.
1 //
2 // Struct file
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 FILE_HPP_
18 #define FILE_HPP_
19 
20 #include "ast.hpp"
21 #include "skipper.hpp"
22 #include "error_handler.hpp"
23 #include "version.hpp"
24 #include "description.hpp"
25 #include "parameter.hpp"
26 #include "column.hpp"
27 #include "data.hpp"
28 #include "associate.hpp"
29 #include "array.hpp"
30 #include "include.hpp"
31 
32 #include <boost/config/warning_disable.hpp>
33 #include <boost/spirit/include/qi.hpp>
34 #include <boost/fusion/include/adapt_struct.hpp>
35 #include <boost/optional.hpp>
36 
37 #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
38 #define BOOST_SPIRIT_QI_DEBUG
39 
40 namespace SDDS {
41  struct file
42  {
44  boost::optional<description> sddsDescription_m; // 1
51 
52  void clear() {
53  sddsParameters_m.clear();
54  sddsColumns_m.clear();
55  sddsAssociates_m.clear();
56  sddsArrays_m.clear();
57  sddsIncludes_m.clear();
58  }
59  };
60 
61  inline std::ostream& operator<<(std::ostream& out, const file& fh) {
62  out << fh.sddsVersion_m << "\n";
63  if (fh.sddsDescription_m) out << *fh.sddsDescription_m << "\n";
64  for (const parameter& param: fh.sddsParameters_m) {
65  out << param << "\n";
66  }
67  for (const column& col: fh.sddsColumns_m) {
68  out << col << "\n";
69  }
70  out << fh.sddsData_m << "\n";
71 
72 // if (fh.sddsAssociates_m) out << *fh.sddsAssociates_m << "\n";
73 // if (fh.sddsArrays_m) out << *fh.sddsArrays_m << "\n";
74 // if (fh.sddsIncludes_m) out << *fh.sddsIncludes_m << "\n";
75 
76  out << std::endl;
77 
78  return out;
79  }
80 }
81 
83  SDDS::file,
84  (SDDS::version, sddsVersion_m)
85  (boost::optional<SDDS::description>, sddsDescription_m)
86  (SDDS::parameterList, sddsParameters_m)
87  (SDDS::columnList, sddsColumns_m)
88  (SDDS::data, sddsData_m)
89  (SDDS::associateList, sddsAssociates_m)
90  (SDDS::arrayList, sddsArrays_m)
91  (SDDS::includeList, sddsIncludes_m)
92 )
93 
94 namespace SDDS { namespace parser
95 {
96  namespace qi = boost::spirit::qi;
97  namespace ascii = boost::spirit::ascii;
98  namespace phx = boost::phoenix;
99 
100  template <typename Iterator>
101  struct file_parser: qi::grammar<Iterator, file(), skipper<Iterator> >
102  {
103  file_parser(error_handler<Iterator> & _error_handler);
104 
105  version_parser<Iterator> version_m;
106  description_parser<Iterator> description_m;
107  parameter_parser<Iterator> parameter_m;
108  column_parser<Iterator> column_m;
109  data_parser<Iterator> data_m;
110  associate_parser<Iterator> associate_m;
111  array_parser<Iterator> array_m;
112  include_parser<Iterator> include_m;
113  qi::rule<Iterator, file(), skipper<Iterator> > start;
114  };
115 }}
116 #endif /* FILE_HPP_ */
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
BOOST_FUSION_ADAPT_STRUCT(SDDS::file,(SDDS::version, sddsVersion_m)(boost::optional< SDDS::description >, sddsDescription_m)(SDDS::parameterList, sddsParameters_m)(SDDS::columnList, sddsColumns_m)(SDDS::data, sddsData_m)(SDDS::associateList, sddsAssociates_m)(SDDS::arrayList, sddsArrays_m)(SDDS::includeList, sddsIncludes_m)) namespace SDDS
Definition: file.hpp:82
Definition: array.hpp:33
std::ostream & operator<<(std::ostream &out, const array &)
Definition: array.hpp:97
version sddsVersion_m
Definition: file.hpp:43
columnList sddsColumns_m
Definition: file.hpp:46
boost::optional< description > sddsDescription_m
Definition: file.hpp:44
arrayList sddsArrays_m
Definition: file.hpp:49
data sddsData_m
Definition: file.hpp:47
includeList sddsIncludes_m
Definition: file.hpp:50
void clear()
Definition: file.hpp:52
parameterList sddsParameters_m
Definition: file.hpp:45
associateList sddsAssociates_m
Definition: file.hpp:48