DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigObject.hpp
Go to the documentation of this file.
1
7
8#ifndef CONFFWK_CONFIGOBJECT_H_
9#define CONFFWK_CONFIGOBJECT_H_
10
11#include <string>
12#include <vector>
13#include <iostream>
14
15#include <mutex>
16
18#include "conffwk/Errors.hpp"
19
20namespace dunedaq {
21namespace conffwk {
22
23class Configuration;
24
45
47
48 friend class Configuration;
49 friend class ConfigurationImpl;
50 friend class DalObject;
51 friend class DalRegistry;
52
53 public:
54
63
64 ConfigObject() noexcept;
65
66
73
74 ConfigObject(const ConfigObject& other) noexcept;
75
76
80
81 ConfigObject(ConfigObjectImpl *impl) noexcept;
82
83
87
88 ~ConfigObject() noexcept;
89
90
97
98 ConfigObject& operator=(const ConfigObject& other) noexcept;
99
100
104
105 ConfigObject& operator=(ConfigObjectImpl *impl) noexcept;
106
107
111
112 bool operator==(const ConfigObject& other) const noexcept;
113
114 ConfigObject* get_obj_pybind(const std::string& attrname);
115
116 template <typename T>
117 T get_value_pybind(const std::string& attrname) {
118 T attrval;
119 this->get(attrname, attrval);
120 return attrval;
121 }
122
123 template <typename T>
124 std::vector<T> get_list_pybind(const std::string& attrname) {
125 std::vector<T> attrvals;
126 this->get(attrname, attrvals);
127 return attrvals;
128 }
129
130 template <typename T>
131 void set_list_pybind(const std::string& attrname, std::vector<T> l) {
132 this->set_by_ref(attrname, l);
133 }
134
135
136
137// private:
138// void set_string_list_generic(ConfigObject& co, const std::string& attrname, std::vector<std::string> data,
139// void (ConfigObject::*f)(const std::string&, const std::vector<std::string>&)) {
140// (co.*f)(attrname, data);
141// }
142
143// public:
144
145// void set_string_list
146// (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
147// set_string_list_generic(co, attrname, l,
148// &ConfigObject::set_by_ref<const std::vector<std::string> >);
149// }
150
151// void set_enum_list
152// (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
153// set_string_list_generic(co, attrname, l, &ConfigObject::set_enum);
154// }
155
156// void set_class_list
157// (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
158// set_string_list_generic(co, attrname, l, &ConfigObject::set_class);
159// }
160
161// void set_date_list
162// (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
163// set_string_list_generic(co, attrname, l, &ConfigObject::set_date);
164// }
165
166// void set_time_list
167// (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
168// set_string_list_generic(co, attrname, l, &ConfigObject::set_time);
169// }
170
179
180 bool
181 is_null() const noexcept
182 {
183 return (m_impl == nullptr);
184 }
185
186
190
191 bool
193 {
194 return (m_impl->is_deleted());
195 }
196
197
198 private:
199
200 void action_on_object_update(Configuration * db, const std::string& name);
201
202
203
204 public:
205
206
217
218 const std::string& UID() const noexcept { return m_impl->m_id; }
219
220
230
231 const std::string& class_name() const noexcept { return *m_impl->m_class_name; }
232
233
240
241 const std::string full_name() const noexcept { return UID() + '@' + class_name(); }
242
243
248
249 const std::string contained_in() const
250 {
251 return m_impl->contained_in();
252 }
253
254
277
278 template<class T> void get(const std::string& name, T& value) {
279 m_impl->get(name, value);
280 m_impl->convert(value, *this, name);
281 }
282
283
295
296 bool
297 rel(const std::string& name, std::vector<ConfigObject>& value)
298 {
299 if (m_impl->rel(name, value))
300 {
301 m_impl->convert(value, *this, name);
302 return true;
303 }
304
305 return false;
306 }
307
308
326
327 void referenced_by(std::vector<ConfigObject>& value,
328 const std::string& relationship_name = "*",
329 bool check_composite_only = true,
330 unsigned long rlevel = 0,
331 const std::vector<std::string> * rclasses = nullptr ) const {
332 m_impl->referenced_by(value, relationship_name, check_composite_only, rlevel, rclasses);
333 }
334
337
338
348
349 void set_obj(const std::string& name, const ConfigObject * o, bool skip_non_null_check = false) {
350 m_impl->set(name, o, skip_non_null_check);
352 }
353
354
364
365 void set_objs(const std::string& name, const std::vector<const ConfigObject*> & o, bool skip_non_null_check = false) {
366 m_impl->set(name, o, skip_non_null_check);
368 }
369
370
390
391 template<class T> void set_by_val(const std::string& name, T value) {
392 m_impl->set(name, value);
394 }
395
396
411
412 template<class T> void set_by_ref(const std::string& name, T& value) {
413 m_impl->set(name, value);
415 }
416
417
428
429 void set_enum(const std::string& name, const std::string& value) {
430 m_impl->set_enum(name, value);
432 }
433
434
445
446 void set_class(const std::string& name, const std::string& value) {
447 m_impl->set_class(name, value);
449 }
450
451
462
463 void set_date(const std::string& name, const std::string& value) {
464 m_impl->set_date(name, value);
466 }
467
468
479
480 void set_time(const std::string& name, const std::string& value) {
481 m_impl->set_time(name, value);
483 }
484
485
496
497 void set_enum(const std::string& name, const std::vector<std::string>& value) {
498 m_impl->set_enum(name, value);
500 }
501
502
513
514 void set_class(const std::string& name, const std::vector<std::string>& value) {
515 m_impl->set_class(name, value);
517 }
518
519
530
531 void set_date(const std::string& name, const std::vector<std::string>& value) {
532 m_impl->set_date(name, value);
534 }
535
536
547
548 void set_time(const std::string& name, const std::vector<std::string>& value) {
549 m_impl->set_time(name, value);
551 }
552
553
563
564 void move(const std::string& at) {
565 m_impl->move(at);
566 }
567
568
578
579 void
580 rename(const std::string& new_id);
581
582
586
587 void print_ptr(std::ostream& s) const noexcept;
588
589
593
594 void print_ref(
595 std::ostream& s,
596 Configuration & conf,
597 const std::string& prefix = "",
598 bool show_contained_in = false
599 ) const noexcept;
600
601
607
608 const ConfigObjectImpl * implementation() const noexcept {return m_impl;}
609
610
611 private:
612
613 void
614 _clear() noexcept
615 {
616 if (m_impl)
617 {
618 m_impl->clear();
619 }
620 }
621
622
623 private:
624
626
627};
628
629
631
632std::ostream& operator<<(std::ostream&, const ConfigObject *);
633
634
636
637std::ostream& operator<<(std::ostream&, const ConfigObject &);
638
639} // namespace conffwk
640} // namespace dunedaq
641
642#endif // CONFFWK_CONFIGOBJECT_H_
Implements database objects.
Represents database objects.
void set_time(const std::string &name, const std::string &value)
Set attribute time value.
void set_by_val(const std::string &name, T value)
Set attribute value.
ConfigObject * get_obj_pybind(const std::string &attrname)
void set_time(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-times value.
T get_value_pybind(const std::string &attrname)
ConfigObject() noexcept
Default constructor.
void set_class(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-class value.
void set_date(const std::string &name, const std::string &value)
Set attribute date value.
void print_ptr(std::ostream &s) const noexcept
Print object's pointer in format 'obj-id@class-name'.
void set_objs(const std::string &name, const std::vector< const ConfigObject * > &o, bool skip_non_null_check=false)
Set relationship multi-value.
void move(const std::string &at)
Move object to a different database.
const std::string & UID() const noexcept
Return object identity.
void set_enum(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-enumerations value.
Configuration * get_configuration() const
Get pointer to configuration object.
void set_class(const std::string &name, const std::string &value)
Set attribute class value.
void set_by_ref(const std::string &name, T &value)
Set attribute value.
bool is_deleted() const
Check if object was deleted.
void action_on_object_update(Configuration *db, const std::string &name)
void set_list_pybind(const std::string &attrname, std::vector< T > l)
void set_date(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-dates value.
void print_ref(std::ostream &s, Configuration &conf, const std::string &prefix="", bool show_contained_in=false) const noexcept
Print details of object's attributes and relationships.
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
void set_enum(const std::string &name, const std::string &value)
Set attribute enumeration value.
void referenced_by(std::vector< ConfigObject > &value, const std::string &relationship_name="*", bool check_composite_only=true, unsigned long rlevel=0, const std::vector< std::string > *rclasses=nullptr) const
Get objects which have references to given object.
const std::string full_name() const noexcept
Return full object name.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
bool is_null() const noexcept
Check if object's implementation points to null.
const ConfigObjectImpl * implementation() const noexcept
Returns pointer on implementation.
void rename(const std::string &new_id)
Rename object.
std::vector< T > get_list_pybind(const std::string &attrname)
const std::string & class_name() const noexcept
Return object's class name.
bool rel(const std::string &name, std::vector< ConfigObject > &value)
Get value of object's relationship.
const std::string contained_in() const
Return the name of the database file this object belongs to.
Defines base class for cache of template objects.
std::ostream & operator<<(std::ostream &, const ConfigurationChange &)
Including Qt Headers.