OPALX (Object Oriented Parallel Accelerator Library for Exascal) master (dc2a29eed580)
OPALX
Loading...
Searching...
No Matches
column.hpp
Go to the documentation of this file.
1//
2// Struct column
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 COLUMN_HPP_
18#define COLUMN_HPP_
19
20#include <optional>
21#include "ast.hpp"
22#include "value_parser.hpp"
23
24#include <vector>
25
26#define BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
27#define BOOST_SPIRIT_QI_DEBUG
28
29namespace SDDS {
30 struct column {
32
33 unsigned int order_m;
34 std::optional<std::string> name_m;
35 std::optional<std::string> units_m;
36 std::optional<std::string> description_m;
37 std::optional<ast::datatype> type_m;
39 static unsigned int count_m;
40
41 bool checkMandatories() const { return name_m && type_m; }
42
43 template <attributes A>
45 static bool apply() {
46 std::string attributeString;
47 switch (A) {
48 case SYMBOL:
49 attributeString = "symbol";
50 break;
51 case FORMAT_STRING:
52 attributeString = "format_string";
53 break;
54 case FIELD_LENGTH:
55 attributeString = "field_length";
56 break;
57 default:
58 return true;
59 }
60 std::cerr << attributeString << " not supported yet" << std::endl;
61 return false;
62 }
63 };
64
65 bool parse(const std::string& input, size_t& pos) {
66 parser::ValueParser parser(input, pos);
67 switch (*this->type_m) {
68 case ast::FLOAT: {
69 float f = 0.0f;
70 if (parser.parseFloat(f)) {
71 this->values_m.push_back(f);
72 pos = parser.getPosition();
73 return true;
74 }
75 break;
76 }
77 case ast::DOUBLE: {
78 double d = 0.0;
79 if (parser.parseDouble(d)) {
80 this->values_m.push_back(d);
81 pos = parser.getPosition();
82 return true;
83 }
84 break;
85 }
86 case ast::SHORT: {
87 short s = 0;
88 if (parser.parseShort(s)) {
89 this->values_m.push_back(s);
90 pos = parser.getPosition();
91 return true;
92 }
93 break;
94 }
95 case ast::LONG: {
96 long l = 0;
97 if (parser.parseLong(l)) {
98 this->values_m.push_back(l);
99 pos = parser.getPosition();
100 return true;
101 }
102 break;
103 }
104 case ast::CHARACTER: {
105 char c = '\0';
106 if (parser.parseChar(c)) {
107 this->values_m.push_back(c);
108 pos = parser.getPosition();
109 return true;
110 }
111 break;
112 }
113 case ast::STRING: {
114 std::string s;
115 if (parser.parseQuotedString(s)) {
116 this->values_m.push_back(s);
117 pos = parser.getPosition();
118 return true;
119 }
120 break;
121 }
122 }
123 return false;
124 }
125 };
126
127 struct columnList : std::vector<column> {};
128
129 template <typename Iterator>
130 struct columnOrder {
131 template <typename, typename>
132 struct result {
133 typedef void type;
134 };
135
136 void operator()(column& col, Iterator) const { col.order_m = column::count_m++; }
137 };
138
139 inline std::ostream& operator<<(std::ostream& out, const column& col) {
140 if (col.name_m) out << "name = " << *col.name_m << ", ";
141 if (col.type_m) out << "type = " << *col.type_m << ", ";
142 if (col.units_m) out << "units = " << *col.units_m << ", ";
143 if (col.description_m) out << "description = " << *col.description_m << ", ";
144 out << "order = " << col.order_m;
145
146 return out;
147 }
148} // namespace SDDS
149
150#endif /* COLUMN_HPP_ */
bool parseQuotedString(std::string &value)
bool parseLong(long &value)
bool parseChar(char &value)
bool parseFloat(float &value)
bool parseDouble(double &value)
bool parseShort(short &value)
std::vector< variant_t > columnData_t
Definition ast.hpp:36
@ STRING
Definition ast.hpp:26
@ DOUBLE
Definition ast.hpp:26
@ LONG
Definition ast.hpp:26
@ FLOAT
Definition ast.hpp:26
@ CHARACTER
Definition ast.hpp:26
@ SHORT
Definition ast.hpp:26
std::ostream & operator<<(std::ostream &out, const array &)
Definition array.hpp:87
void operator()(column &col, Iterator) const
Definition column.hpp:136
std::optional< std::string > name_m
Definition column.hpp:34
std::optional< ast::datatype > type_m
Definition column.hpp:37
bool parse(const std::string &input, size_t &pos)
Definition column.hpp:65
unsigned int order_m
Definition column.hpp:33
ast::columnData_t values_m
Definition column.hpp:38
bool checkMandatories() const
Definition column.hpp:41
std::optional< std::string > units_m
Definition column.hpp:35
std::optional< std::string > description_m
Definition column.hpp:36
static unsigned int count_m
Definition column.hpp:39