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 <exception>
22#include <list>
23
24#include <boost/regex.hpp>
25
26namespace dunedaq {
27namespace oks {
28
30
32
38
40{
41public:
43 : p_sub_classes(b)
44 , p_expression(q)
45 , p_status(0) {};
46 OksQuery(const OksClass*, const std::string&);
47 virtual ~OksQuery();
48
49 friend std::ostream& operator<<(std::ostream&, const OksQuery&);
50
51 bool search_in_subclasses() const { return p_sub_classes; }
52 void search_in_subclasses(bool b) { p_sub_classes = b; }
53
54 OksQueryExpression* get() const { return p_expression; }
56
57 bool good() const { return (p_status == 0); }
58
68
69 static const char* OR;
70 static const char* AND;
71 static const char* NOT;
72 static const char* SOME;
73 static const char* THIS_CLASS;
74 static const char* ALL_SUBCLASSES;
75 static const char* OID;
76 static const char* EQ;
77 static const char* NE;
78 static const char* RE;
79 static const char* LE;
80 static const char* GE;
81 static const char* LS;
82 static const char* GT;
83 static const char* PATH_TO;
84 static const char* DIRECT;
85 static const char* NESTED;
86
87 static bool equal_cmp(const OksData*, const OksData*);
88 static bool not_equal_cmp(const OksData*, const OksData*);
89 static bool less_or_equal_cmp(const OksData*, const OksData*);
90 static bool greater_or_equal_cmp(const OksData*, const OksData*);
91 static bool less_cmp(const OksData*, const OksData*);
92 static bool greater_cmp(const OksData*, const OksData*);
93 static bool reg_exp_cmp(const OksData*, const OksData* regexp);
94
95 typedef bool (*Comparator)(const OksData*, const OksData*);
96
97private:
101
102 static OksQueryExpression* create_expression(const OksClass*, const std::string&);
103};
104
106
110
112{
113 friend std::ostream& operator<<(std::ostream&, const OksQueryExpression&);
114
115public:
116 virtual ~OksQueryExpression() { ; }
117
118 OksQuery::QueryType type() const { return p_type; }
119 bool CheckSyntax() const;
120 bool operator==(const class OksQueryExpression& e) const { return (this == &e); }
121
122protected:
125
126private:
128};
129
131
137
139{
140 friend class OksObject;
141 friend class OksQueryExpression;
142
143public:
145 : OksQueryExpression(OksQuery::comparator_type)
146 , attribute(a)
147 , value(v)
148 , m_comp_f(f)
149 , m_reg_exp(0) {};
150
152 {
153 delete value;
154 if (m_reg_exp)
155 delete m_reg_exp;
156 }
157
158 const OksAttribute* GetAttribute() const { return attribute; }
159 void SetAttribute(const OksAttribute* a) { attribute = a; }
160
161 OksData* GetValue() { return value; }
162 void SetValue(OksData* v);
163
164 void clean_reg_exp();
165
168
169private:
173 boost::regex* m_reg_exp;
174};
175
177
182
184{
185 friend class OksObject;
186 friend class OksQueryExpression;
187
188public:
190 : OksQueryExpression(OksQuery::relationship_type)
191 , relationship(r)
192 , checkAllObjects(b)
193 , p_expression(q) {};
194
196
199
202
203 bool IsCheckAllObjects() const { return checkAllObjects; }
204 void SetIsCheckAllObjects(const bool b) { checkAllObjects = b; }
205
206private:
210};
211
213
217
219{
220
221 friend class OksObject;
222 friend class OksQueryExpression;
223
224public:
228
229 virtual ~OksNotExpression() { delete p_expression; }
230
233
234private:
236};
237
239
241{
242
243 friend class OksObject;
244 friend class OksClass;
245 friend class OksQueryExpression;
246
247public:
249 {
250 while (!p_expressions.empty()) {
251 OksQueryExpression* qe = p_expressions.front();
252 p_expressions.pop_front();
253 delete qe;
254 }
255 }
256
257 const std::list<OksQueryExpression*>& expressions() const { return p_expressions; }
258 void add(OksQueryExpression* q) { p_expressions.push_back(q); }
259
260protected:
262
263private:
264 std::list<OksQueryExpression*> p_expressions;
265};
266
268
270 : public OksQueryExpression
272{
273public:
276
277 virtual ~OksAndExpression() { ; }
278};
279
281
283 : public OksQueryExpression
285{
286public:
289
290 virtual ~OksOrExpression() { ; }
291};
292
294{
295 delete p_expression;
296}
297
302
303class bad_query_syntax : public std::exception
304{
305
306 std::string p_what;
307
308public:
309 bad_query_syntax(const std::string& what_arg) noexcept
310 : p_what(what_arg)
311 {
312 }
313 virtual ~bad_query_syntax() noexcept {}
314
315 virtual const char* what() const noexcept { return p_what.c_str(); }
316};
317
322
324{
325
326 friend class QueryPath;
327 friend class OksObject;
328
329public:
331 const std::list<std::string>& get_rel_names() const { return p_rel_names; }
332 const QueryPathExpression* get_next() const { return p_next; }
333
334protected:
337 {
338 }
339 QueryPathExpression(const std::string& expression);
340
342
344 std::list<std::string> p_rel_names;
346};
347
368
370{
371
372public:
374 : p_goal(o)
375 , p_start(qpe)
376 {
377 }
378 QueryPath(const std::string& query, const OksKernel&);
379 ~QueryPath() { delete p_start; }
380
382 const OksObject* get_goal_object() const { return p_goal; }
383
384private:
387};
388
389std::ostream&
390operator<<(std::ostream&, const oks::QueryPathExpression&);
391std::ostream&
392operator<<(std::ostream&, const oks::QueryPath&);
393
394} // namespace oks
395} // namespace dunedaq
396#endif
OKS attribute class.
Definition attribute.hpp:94
The OKS class.
Definition class.hpp:223
OksQuery::Comparator GetFunction() const
Definition query.hpp:166
friend class OksQueryExpression
Definition query.hpp:141
boost::regex * m_reg_exp
Definition query.hpp:173
const OksAttribute * attribute
Definition query.hpp:170
void SetValue(OksData *v)
Definition query.cpp:92
const OksAttribute * GetAttribute() const
Definition query.hpp:158
void SetFunction(OksQuery::Comparator f)
Definition query.hpp:167
OksComparator(const OksAttribute *a, OksData *v, OksQuery::Comparator f)
Definition query.hpp:144
OksQuery::Comparator m_comp_f
Definition query.hpp:172
void SetAttribute(const OksAttribute *a)
Definition query.hpp:159
Provides interface to the OKS kernel.
Definition kernel.hpp:615
std::list< OksQueryExpression * > p_expressions
Definition query.hpp:264
const std::list< OksQueryExpression * > & expressions() const
Definition query.hpp:257
void add(OksQueryExpression *q)
Definition query.hpp:258
OksNotExpression(OksQueryExpression *q=0)
Definition query.hpp:225
friend class OksQueryExpression
Definition query.hpp:222
void set(OksQueryExpression *q)
Definition query.hpp:232
OksQueryExpression * p_expression
Definition query.hpp:235
OksQueryExpression * get() const
Definition query.hpp:231
OksObject describes instance of OksClass.
Definition object.hpp:1144
OKS query expression class.
Definition query.hpp:112
const OksQuery::QueryType p_type
Definition query.hpp:127
bool operator==(const class OksQueryExpression &e) const
Definition query.hpp:120
OksQuery::QueryType type() const
Definition query.hpp:118
friend std::ostream & operator<<(std::ostream &, const OksQueryExpression &)
Definition query.cpp:761
OksQueryExpression(OksQuery::QueryType qet=OksQuery::unknown_type)
Definition query.hpp:123
OKS query class.
Definition query.hpp:40
static const char * ALL_SUBCLASSES
Definition query.hpp:74
bool good() const
Definition query.hpp:57
static bool equal_cmp(const OksData *, const OksData *)
Definition query.cpp:56
void search_in_subclasses(bool b)
Definition query.hpp:52
static bool reg_exp_cmp(const OksData *, const OksData *regexp)
Definition query.cpp:86
bool(*) Comparator(const OksData *, const OksData *)
Definition query.hpp:95
static bool greater_cmp(const OksData *, const OksData *)
Definition query.cpp:81
static const char * OR
Definition query.hpp:69
bool search_in_subclasses() const
Definition query.hpp:51
static const char * RE
Definition query.hpp:78
static const char * THIS_CLASS
Definition query.hpp:73
void set(OksQueryExpression *q)
Definition query.hpp:55
static const char * OID
Definition query.hpp:75
static bool less_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:66
static bool not_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:61
static const char * GT
Definition query.hpp:82
static const char * NOT
Definition query.hpp:71
static const char * SOME
Definition query.hpp:72
static const char * PATH_TO
Definition query.hpp:83
OksQueryExpression * p_expression
Definition query.hpp:99
static const char * GE
Definition query.hpp:80
static const char * AND
Definition query.hpp:70
static const char * NESTED
Definition query.hpp:85
static bool greater_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:71
static const char * EQ
Definition query.hpp:76
static bool less_cmp(const OksData *, const OksData *)
Definition query.cpp:76
static const char * DIRECT
Definition query.hpp:84
static const char * LE
Definition query.hpp:79
OksQuery(bool b, OksQueryExpression *q=0)
Definition query.hpp:42
static const char * NE
Definition query.hpp:77
static OksQueryExpression * create_expression(const OksClass *, const std::string &)
Definition query.cpp:212
static const char * LS
Definition query.hpp:81
OksQueryExpression * get() const
Definition query.hpp:54
OksQueryExpression * get() const
Definition query.hpp:200
void set(OksQueryExpression *q)
Definition query.hpp:201
void SetRelationship(const OksRelationship *r)
Definition query.hpp:198
const OksRelationship * GetRelationship() const
Definition query.hpp:197
void SetIsCheckAllObjects(const bool b)
Definition query.hpp:204
const OksRelationship * relationship
Definition query.hpp:207
OksRelationshipExpression(const OksRelationship *r, OksQueryExpression *q, bool b=false)
Definition query.hpp:189
OksQueryExpression * p_expression
Definition query.hpp:209
QueryPathExpression * p_next
Definition query.hpp:345
QueryPathExpression(const std::string &expression)
const QueryPathExpression * get_next() const
Definition query.hpp:332
std::list< std::string > p_rel_names
Definition query.hpp:344
const std::list< std::string > & get_rel_names() const
Definition query.hpp:331
const OksObject * get_goal_object() const
Definition query.hpp:382
const QueryPathExpression * get_start_expression() const
Definition query.hpp:381
QueryPath(const OksObject *o, QueryPathExpression *qpe)
Definition query.hpp:373
const OksObject * p_goal
Definition query.hpp:385
QueryPathExpression * p_start
Definition query.hpp:386
QueryPath(const std::string &query, const OksKernel &)
bad_query_syntax(const std::string &what_arg) noexcept
Definition query.hpp:309
virtual ~bad_query_syntax() noexcept
Definition query.hpp:313
virtual const char * what() const noexcept
Definition query.hpp:315
std::ostream & operator<<(std::ostream &s, const oks::exception &ex)
The DUNE-DAQ namespace.
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]
Struct OKS data.
Definition object.hpp:510