DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
query.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3// Fork baseline commit: oks-08-03-04 (2022-04-14).
4// Renamed since fork: yes (from oks/query.h to include/oks/query.hpp).
5
14
15#ifndef __OKS_QUERY
16#define __OKS_QUERY
17
18#include "oks/defs.hpp"
19#include "oks/object.hpp"
20
21#include <list>
22#include <exception>
23
24#include <boost/regex.hpp>
25
26namespace dunedaq {
27namespace oks {
28
30
31
33
39
41{
42 public:
43
45 OksQuery(const OksClass *, const std::string &);
46 virtual ~OksQuery();
47
48 friend std::ostream& operator<<(std::ostream&, const OksQuery&);
49
50 bool search_in_subclasses() const {return p_sub_classes;}
52
55
56 bool good() const {return (p_status == 0);}
57
66
67 static const char * OR;
68 static const char * AND;
69 static const char * NOT;
70 static const char * SOME;
71 static const char * THIS_CLASS;
72 static const char * ALL_SUBCLASSES;
73 static const char * OID;
74 static const char * EQ;
75 static const char * NE;
76 static const char * RE;
77 static const char * LE;
78 static const char * GE;
79 static const char * LS;
80 static const char * GT;
81 static const char * PATH_TO;
82 static const char * DIRECT;
83 static const char * NESTED;
84
85 static bool equal_cmp(const OksData *, const OksData *);
86 static bool not_equal_cmp(const OksData *, const OksData *);
87 static bool less_or_equal_cmp(const OksData *, const OksData *);
88 static bool greater_or_equal_cmp(const OksData *, const OksData *);
89 static bool less_cmp(const OksData *, const OksData *);
90 static bool greater_cmp(const OksData *, const OksData *);
91 static bool reg_exp_cmp(const OksData *, const OksData * regexp);
92
93 typedef bool (*Comparator)(const OksData *, const OksData *);
94
95
96 private:
97
101
102 static OksQueryExpression * create_expression(const OksClass *, const std::string &);
103};
104
105
107
111
113 friend std::ostream& operator<<(std::ostream&, const OksQueryExpression&);
114
115 public:
116
118
120 bool CheckSyntax() const;
121 bool operator==(const class OksQueryExpression& e) const {return (this == &e);}
122
123
124 protected:
125
127
128
129 private:
130
132};
133
134
136
142
144{
145 friend class OksObject;
146 friend class OksQueryExpression;
147
148 public:
149
151 OksQueryExpression (OksQuery::comparator_type),
152 attribute (a),
153 value (v),
154 m_comp_f (f),
155 m_reg_exp (0)
156 {};
157
158 virtual ~OksComparator() {
159 delete value;
160 if(m_reg_exp) delete m_reg_exp;
161 }
162
163 const OksAttribute * GetAttribute() const {return attribute;}
164 void SetAttribute(const OksAttribute* a) {attribute = a;}
165
166 OksData * GetValue() {return value;}
167 void SetValue(OksData *v);
168
169 void clean_reg_exp();
170
173
174 private:
175
179 boost::regex * m_reg_exp;
180
181};
182
183
185
190
192{
193 friend class OksObject;
194 friend class OksQueryExpression;
195
196 public:
197
199 OksQueryExpression (OksQuery::relationship_type),
200 relationship (r),
201 checkAllObjects (b),
202 p_expression (q)
203 {};
204
206
209
212
213 bool IsCheckAllObjects() const {return checkAllObjects;}
214 void SetIsCheckAllObjects(const bool b) {checkAllObjects = b;}
215
216
217 private:
218
222
223};
224
225
227
231
233{
234
235 friend class OksObject;
236 friend class OksQueryExpression;
237
238 public:
239
241
242 virtual ~OksNotExpression() {delete p_expression;}
243
246
247
248 private:
249
251
252};
253
254
256
258{
259
260 friend class OksObject;
261 friend class OksClass;
262 friend class OksQueryExpression;
263
264 public:
265
266 virtual ~OksListBaseQueryExpression() {while(!p_expressions.empty()) {OksQueryExpression * qe = p_expressions.front(); p_expressions.pop_front(); delete qe;}}
267
268 const std::list<OksQueryExpression *> & expressions() const {return p_expressions;}
269 void add(OksQueryExpression *q) {p_expressions.push_back(q);}
270
271
272 protected:
273
275
276
277 private:
278
279 std::list<OksQueryExpression *> p_expressions;
280
281};
282
283
285
287{
288 public:
289
291
292 virtual ~OksAndExpression() {;}
293};
294
295
297
299{
300 public:
301
303
304 virtual ~OksOrExpression() {;}
305
306};
307
309
310
315
316 class bad_query_syntax : public std::exception
317 {
318
319 std::string p_what;
320
321 public:
322
323 bad_query_syntax(const std::string& what_arg) noexcept : p_what (what_arg)
324 {}
325 virtual ~bad_query_syntax() noexcept
326 {}
327
328 virtual const char * what () const noexcept
329 { return p_what.c_str ();}
330 };
331
332
337
339 {
340
341 friend class QueryPath;
342 friend class OksObject;
343
344 public:
345
347 const std::list<std::string>& get_rel_names() const { return p_rel_names; }
348 const QueryPathExpression * get_next() const { return p_next; }
349
350 protected:
351
353 QueryPathExpression(const std::string& expression);
354
356
358 std::list<std::string> p_rel_names;
360
361 };
362
363
364
385
386
388 {
389
390 public:
391
392 QueryPath(const OksObject * o, QueryPathExpression * qpe) : p_goal(o), p_start(qpe) { }
393 QueryPath(const std::string& query, const OksKernel&);
394 ~QueryPath() {delete p_start;}
395
397 const OksObject * get_goal_object() const { return p_goal; }
398
399 private:
400
403
404 };
405
406
407std::ostream& operator<<(std::ostream&, const oks::QueryPathExpression&);
408std::ostream& operator<<(std::ostream&, const oks::QueryPath&);
409
410} // namespace oks
411} // namespace dunedaq
412#endif
OKS attribute class.
The OKS class.
Definition class.hpp:205
OksQuery::Comparator GetFunction() const
Definition query.hpp:171
friend class OksQueryExpression
Definition query.hpp:146
boost::regex * m_reg_exp
Definition query.hpp:179
const OksAttribute * attribute
Definition query.hpp:176
void SetValue(OksData *v)
Definition query.cpp:67
const OksAttribute * GetAttribute() const
Definition query.hpp:163
void SetFunction(OksQuery::Comparator f)
Definition query.hpp:172
OksComparator(const OksAttribute *a, OksData *v, OksQuery::Comparator f)
Definition query.hpp:150
OksQuery::Comparator m_comp_f
Definition query.hpp:178
void SetAttribute(const OksAttribute *a)
Definition query.hpp:164
Provides interface to the OKS kernel.
Definition kernel.hpp:582
std::list< OksQueryExpression * > p_expressions
Definition query.hpp:279
const std::list< OksQueryExpression * > & expressions() const
Definition query.hpp:268
void add(OksQueryExpression *q)
Definition query.hpp:269
OksNotExpression(OksQueryExpression *q=0)
Definition query.hpp:240
friend class OksQueryExpression
Definition query.hpp:236
void set(OksQueryExpression *q)
Definition query.hpp:245
OksQueryExpression * p_expression
Definition query.hpp:250
OksQueryExpression * get() const
Definition query.hpp:244
OksObject describes instance of OksClass.
Definition object.hpp:841
OKS query expression class.
Definition query.hpp:112
const OksQuery::QueryType p_type
Definition query.hpp:131
bool operator==(const class OksQueryExpression &e) const
Definition query.hpp:121
OksQuery::QueryType type() const
Definition query.hpp:119
friend std::ostream & operator<<(std::ostream &, const OksQueryExpression &)
Definition query.cpp:784
OksQueryExpression(OksQuery::QueryType qet=OksQuery::unknown_type)
Definition query.hpp:126
OKS query class.
Definition query.hpp:41
static const char * ALL_SUBCLASSES
Definition query.hpp:72
bool good() const
Definition query.hpp:56
static bool equal_cmp(const OksData *, const OksData *)
Definition query.cpp:56
void search_in_subclasses(bool b)
Definition query.hpp:51
static bool reg_exp_cmp(const OksData *, const OksData *regexp)
Definition query.cpp:62
static bool greater_cmp(const OksData *, const OksData *)
Definition query.cpp:61
static const char * OR
Definition query.hpp:67
bool search_in_subclasses() const
Definition query.hpp:50
static const char * RE
Definition query.hpp:76
static const char * THIS_CLASS
Definition query.hpp:71
void set(OksQueryExpression *q)
Definition query.hpp:54
static const char * OID
Definition query.hpp:73
static bool less_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:58
friend std::ostream & operator<<(std::ostream &, const OksQuery &)
Definition query.cpp:897
static bool not_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:57
static const char * GT
Definition query.hpp:80
static const char * NOT
Definition query.hpp:69
static const char * SOME
Definition query.hpp:70
static const char * PATH_TO
Definition query.hpp:81
OksQueryExpression * p_expression
Definition query.hpp:99
static const char * GE
Definition query.hpp:78
static const char * AND
Definition query.hpp:68
static const char * NESTED
Definition query.hpp:83
static bool greater_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:59
static const char * EQ
Definition query.hpp:74
static bool less_cmp(const OksData *, const OksData *)
Definition query.cpp:60
static const char * DIRECT
Definition query.hpp:82
static const char * LE
Definition query.hpp:77
OksQuery(bool b, OksQueryExpression *q=0)
Definition query.hpp:44
static const char * NE
Definition query.hpp:75
static OksQueryExpression * create_expression(const OksClass *, const std::string &)
Definition query.cpp:187
bool(* Comparator)(const OksData *, const OksData *)
Definition query.hpp:93
static const char * LS
Definition query.hpp:79
OksQueryExpression * get() const
Definition query.hpp:53
OksQueryExpression * get() const
Definition query.hpp:210
void set(OksQueryExpression *q)
Definition query.hpp:211
void SetRelationship(const OksRelationship *r)
Definition query.hpp:208
const OksRelationship * GetRelationship() const
Definition query.hpp:207
void SetIsCheckAllObjects(const bool b)
Definition query.hpp:214
const OksRelationship * relationship
Definition query.hpp:219
OksRelationshipExpression(const OksRelationship *r, OksQueryExpression *q, bool b=false)
Definition query.hpp:198
OksQueryExpression * p_expression
Definition query.hpp:221
QueryPathExpression * p_next
Definition query.hpp:359
QueryPathExpression(const std::string &expression)
const QueryPathExpression * get_next() const
Definition query.hpp:348
std::list< std::string > p_rel_names
Definition query.hpp:358
const std::list< std::string > & get_rel_names() const
Definition query.hpp:347
const OksObject * get_goal_object() const
Definition query.hpp:397
const QueryPathExpression * get_start_expression() const
Definition query.hpp:396
QueryPath(const OksObject *o, QueryPathExpression *qpe)
Definition query.hpp:392
const OksObject * p_goal
Definition query.hpp:401
QueryPathExpression * p_start
Definition query.hpp:402
QueryPath(const std::string &query, const OksKernel &)
bad_query_syntax(const std::string &what_arg) noexcept
Definition query.hpp:323
virtual ~bad_query_syntax() noexcept
Definition query.hpp:325
virtual const char * what() const noexcept
Definition query.hpp:328
std::ostream & operator<<(std::ostream &s, const oks::exception &ex)
Including Qt Headers.
Definition module.cpp:16
Unknown serialization type<< t,((char) t)) template< typename T > inline std::string datatype_to_string() { return "Unknown";} namespace serialization { template< typename T > struct is_serializable :std::false_type {};enum SerializationType { kMsgPack };inline SerializationType from_string(const std::string s) { if(s=="msgpack") return kMsgPack;throw UnknownSerializationTypeString(ERS_HERE, s);} constexpr uint8_t serialization_type_byte(SerializationType stype) { switch(stype) { case kMsgPack:return 'M';default:throw UnknownSerializationTypeEnum(ERS_HERE);} } constexpr SerializationType DEFAULT_SERIALIZATION_TYPE=kMsgPack;template< class T > std::vector< uint8_t > serialize(const T &obj, SerializationType stype=DEFAULT_SERIALIZATION_TYPE) { switch(stype) { case kMsgPack:{ msgpack::sbuffer buf;msgpack::pack(buf, obj);std::vector< uint8_t > ret(buf.size()+1);ret[0]=serialization_type_byte(stype);std::copy(buf.data(), buf.data()+buf.size(), ret.begin()+1);return ret;} default:throw UnknownSerializationTypeEnum(ERS_HERE);} } template< class T, typename CharType=unsigned char > T deserialize(const std::vector< CharType > &v) { switch(v[0]) { case serialization_type_byte(kMsgPack):{ try { msgpack::object_handle oh=msgpack::unpack(const_cast< char * >(reinterpret_cast< const char * >(v.data()+1)), v.size() - 1,[](msgpack::type::object_type, std::size_t, void *) -> bool
default char v[0]
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:454