OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
parameter.hpp
Go to the documentation of this file.
1 //
2 // Copyright & License: See Copyright.readme in src directory
3 //
4 
9 #ifndef PARAMETER_HPP_
10 #define PARAMETER_HPP_
11 
12 #include "ast.hpp"
13 #include "skipper.hpp"
14 #include "error_handler.hpp"
15 
16 #include <boost/config/warning_disable.hpp>
17 #include <boost/spirit/include/qi.hpp>
18 #include <boost/fusion/include/adapt_struct.hpp>
19 #include <boost/optional.hpp>
20 
21 #include <list>
22 
23 #define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
24 #define BOOST_SPIRIT_QI_DEBUG
25 
26 namespace SDDS {
27  struct parameter
28  {
34  , TYPE
36  };
37 
38  unsigned int order_m;
39  boost::optional<std::string> name_m;
40  boost::optional<std::string> units_m;
41  boost::optional<std::string> description_m;
42  boost::optional<ast::datatype> type_m;
44  static unsigned int count_m;
45 
46  bool checkMandatories() const
47  {
48  return name_m && type_m;
49  }
50 
51  template <attributes A>
53  {
54  static bool apply()
55  {
56  std::string attributeString;
57  switch(A)
58  {
59  case SYMBOL:
60  attributeString = "symbol";
61  break;
62  case FORMAT_STRING:
63  attributeString = "format_string";
64  break;
65  case FIXED_VALUE:
66  attributeString = "fixed_value";
67  break;
68  default:
69  return true;
70  }
71  std::cerr << attributeString << " not supported yet" << std::endl;
72  return false;
73  }
74  };
75 
76  template <typename Iterator, typename Skipper>
77  bool parse(
78  Iterator& first
79  , Iterator last
80  , Skipper const& skipper)
81  {
82  switch(*this->type_m) {
83  case ast::FLOAT:
84  {
85  boost::spirit::qi::float_type float_;
86  return phrase_parse(first, last, float_, skipper, this->value_m);
87  }
88  case ast::DOUBLE:
89  {
90  boost::spirit::qi::double_type double_;
91  return phrase_parse(first, last, double_, skipper, this->value_m);
92  }
93  case ast::SHORT:
94  {
95  boost::spirit::qi::short_type short_;
96  return phrase_parse(first, last, short_, skipper, this->value_m);
97  }
98  case ast::LONG:
99  {
100  boost::spirit::qi::long_type long_;
101  return phrase_parse(first, last, long_, skipper, this->value_m);
102  }
103  case ast::CHARACTER:
104  {
105  boost::spirit::qi::char_type char_;
106  return phrase_parse(first, last, char_, skipper, this->value_m);
107  }
108  case ast::STRING:
109  {
111  return phrase_parse(first, last, string, skipper, this->value_m);
112  }
113  }
114  return false;
115  }
116  };
117 
118  struct parameterList : std::vector<parameter> {};
119 
120  template <typename Iterator>
122  {
123  template <typename, typename>
124  struct result { typedef void type; };
125 
126  void operator()(parameter& param, Iterator) const
127  {
128  param.order_m = parameter::count_m ++;
129  }
130  };
131 
132  inline std::ostream& operator<<(std::ostream& out, const parameter& param) {
133  if (param.name_m) out << "name = " << *param.name_m << ", ";
134  if (param.type_m) out << "type = " << *param.type_m << ", ";
135  if (param.units_m) out << "units = " << *param.units_m << ", ";
136  if (param.description_m) out << "description = " << *param.description_m << ", ";
137  out << "order = " << param.order_m;
138 
139  return out;
140  }
141 }
142 
145  (boost::optional<std::string>, name_m)
146  (boost::optional<SDDS::ast::datatype>, type_m)
147  (boost::optional<std::string>, units_m)
148  (boost::optional<std::string>, description_m)
149  (SDDS::ast::variant_t, value_m)
150 )
151 
152 namespace SDDS { namespace parser
153 {
154  namespace qi = boost::spirit::qi;
155  namespace ascii = boost::spirit::ascii;
156  namespace phx = boost::phoenix;
157 
158  template <typename Iterator>
159  struct parameter_parser: qi::grammar<Iterator, parameter(), skipper<Iterator> >
160  {
161  parameter_parser(error_handler<Iterator> & _error_handler);
162 
163  qi::rule<Iterator, std::string(), skipper<Iterator> > string, quoted_string, units;
164  qi::rule<Iterator, std::string(), skipper<Iterator> > parameter_name, parameter_units,
165  parameter_description, parameter_symbol, parameter_format;
166  qi::rule<Iterator, ast::datatype(), skipper<Iterator> > parameter_type;
167  qi::rule<Iterator, long(), skipper<Iterator> > parameter_fixed;
168  qi::rule<Iterator, parameter(), skipper<Iterator> > start;
169  qi::rule<Iterator, ast::nil(), skipper<Iterator> > parameter_unsupported_pre,
170  parameter_unsupported_post;
171  qi::symbols<char, ast::datatype> datatype;
172  };
173 }}
174 #endif /* PARAMETER_HPP_ */
boost::optional< ast::datatype > type_m
Definition: parameter.hpp:42
unsigned int order_m
Definition: parameter.hpp:38
bool checkMandatories() const
Definition: parameter.hpp:46
boost::variant< float, double, short, long, char, std::string > variant_t
Definition: ast.hpp:40
BOOST_FUSION_ADAPT_STRUCT(SDDS::column,(boost::optional< std::string >, name_m)(boost::optional< SDDS::ast::datatype >, type_m)(boost::optional< std::string >, units_m)(boost::optional< std::string >, description_m)(SDDS::ast::variant_t, value_m)) namespace SDDS
Definition: column.hpp:173
void operator()(parameter &param, Iterator) const
Definition: parameter.hpp:126
static unsigned int count_m
Definition: parameter.hpp:44
boost::optional< std::string > description_m
Definition: parameter.hpp:41
boost::optional< std::string > units_m
Definition: parameter.hpp:40
boost::optional< std::string > name_m
Definition: parameter.hpp:39
std::ostream & operator<<(std::ostream &out, const array &)
Definition: array.hpp:89
ast::variant_t value_m
Definition: parameter.hpp:43
Inform & endl(Inform &inf)
Definition: Inform.cpp:42
datatype
Definition: ast.hpp:20
bool parse(Iterator &first, Iterator last, Skipper const &skipper)
Definition: parameter.hpp:77