DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
attribute.hpp
Go to the documentation of this file.
1
10#ifndef OKS_ATTRIBUTE_H
11#define OKS_ATTRIBUTE_H
12
13#include "oks/defs.hpp"
14#include "oks/object.hpp"
15
16#include <string>
17#include <vector>
18
19#include <boost/regex.hpp>
20
21namespace dunedaq {
22namespace oks {
23
24
25class OksXmlOutputStream;
26class OksXmlInputStream;
27
28
30
42{
43public:
44
45 OksRange(const std::string& range, OksAttribute * a)
46 {
47 reset(range, a);
48 }
49
50 void
51 reset(const std::string& range, OksAttribute * a);
52
53 bool
54 validate(const OksData&) const;
55
56 inline bool
58 {
59 return (m_less.empty() && m_equal.empty() && m_interval.empty() && m_great.empty() && m_like.empty());
60 }
61
62private:
63
64 std::string m_range;
65
66 std::list<OksData> m_less;
67 std::list<OksData> m_equal;
68 std::list<std::pair<OksData,OksData>> m_interval;
69 std::list<OksData> m_great;
70 std::list<boost::regex> m_like;
71
72private:
73
74 inline void
76 {
77 m_range.clear();
78
79 m_less.clear();
80 m_equal.clear();
81 m_interval.clear();
82 m_great.clear();
83 m_like.clear();
84 }
85};
86
87
89
102{
103 friend class OksKernel;
104 friend class OksClass;
105 friend class OksIndex;
106 friend class OksObject;
107 friend struct OksData;
108
109public:
110
113 enum Format {
114 Oct = 8,
115 Dec = 10,
116 Hex = 16
117 };
118
119
132 OksAttribute(const std::string& name, OksClass * p = nullptr);
133
134
154 OksAttribute(const std::string& name, const std::string& type, bool is_mv, const std::string& range, const std::string& init_v, const std::string& description, bool no_null, Format format = Dec, OksClass * p = nullptr);
155
156
158 {
159 if (p_enumerators)
160 delete p_enumerators;
161
162 clean_range();
163 }
164
165
166 bool operator==(const class OksAttribute&) const;
167 friend std::ostream& operator<<(std::ostream&, const OksAttribute&);
168
169 const std::string&
170 get_name() const noexcept
171 {
172 return p_name;
173 }
174
175
186 void
187 set_name(const std::string& name);
188
189
196 const std::string&
197 get_type() const noexcept;
198
199
227 void
228 set_type(const std::string& type, bool skip_init = false);
229
230
237 const std::string&
238 get_range() const noexcept
239 {
240 return p_range;
241 }
242
243
268 void
269 set_range(const std::string& range);
270
271
282 static OksData::Type
283 get_data_type(const std::string& type) noexcept;
284
285
297 static OksData::Type
298 get_data_type(const char * type, size_t len) noexcept;
299
300
304 get_data_type() const noexcept
305 {
306 return p_data_type;
307 }
308
309
316 Format
317 get_format() const noexcept
318 {
319 return p_format;
320 }
321
322
342 void
343 set_format(Format format);
344
345
348 bool
349 is_integer() const noexcept;
350
351
354 bool
355 is_number() const noexcept;
356
357
360 bool
361 get_is_multi_values() const noexcept
362 {
363 return p_multi_values;
364 }
365
366
377 void
378 set_is_multi_values(bool multi_values);
379
380
383 const std::string&
384 get_init_value() const noexcept
385 {
386 return p_init_value;
387 }
388
389
400 void
401 set_init_value(const std::string& init_value);
402
403
410 std::list<std::string>
412
413
416 const std::string&
417 get_description() const noexcept
418 {
419 return p_description;
420 }
421
422
431 void
432 set_description(const std::string& description);
433
434
437 bool
438 get_is_no_null() const noexcept
439 {
440 return p_no_null;
441 }
442
443
455 void
456 set_is_no_null(bool no_null);
457
467 static bool
468 find_token(const char * token, const char * range) noexcept;
469
482 int
483 get_enum_index(const char * s, size_t length) const noexcept;
484
489 int
490 get_enum_index(const std::string& s) const noexcept
491 {
492 return get_enum_index(s.data(), s.length());
493 }
494
495
510 const std::string *
511 get_enum_value(const char * s, size_t length) const;
512
513
518 const std::string *
519 get_enum_value(const std::string& s) const
520 {
521 return get_enum_value(s.data(), s.length());
522 }
523
524
536 uint16_t
537 get_enum_value(const OksData& d) const noexcept;
538
550 const std::string *
551 get_enum_string(uint16_t idx) const noexcept
552 {
553 return &(*p_enumerators)[idx];
554 }
555
556
561 static const char * bool_type;
562 static const char * s8_int_type;
563 static const char * u8_int_type;
564 static const char * s16_int_type;
565 static const char * u16_int_type;
566 static const char * s32_int_type;
567 static const char * u32_int_type;
568 static const char * s64_int_type;
569 static const char * u64_int_type;
570 static const char * float_type;
571 static const char * double_type;
572 static const char * date_type;
573 static const char * time_type;
574 static const char * string_type;
575 static const char * uid_type;
576 static const char * enum_type;
577 static const char * class_type;
578
579 static Format
580 str2format(const char *) noexcept;
581 static const char *
582 format2str(Format) noexcept;
583
584private:
585
586 std::string p_name;
587 std::string p_range;
591 std::string p_init_value;
593 std::string p_description;
595 std::vector<std::string> * p_enumerators;
600
601 inline void
602 __set_data_type(const char * t, size_t len) noexcept;
603
606 OksAttribute(OksData::Type t, const OksClass * c) noexcept :
607 p_data_type(t), p_class(const_cast<OksClass*>(c)), p_enumerators(nullptr), p_range_obj(nullptr), p_ordered(false)
608 {
609 ;
610 }
611
612
616
617
620 void
621 save(OksXmlOutputStream&) const;
622
623 void
624 init_enum();
625
626 void
627 init_range();
628
629 inline void
631 {
632 if (p_range_obj)
633 {
634 delete p_range_obj;
635 p_range_obj = nullptr;
636 }
637 }
638
639 void
641 {
642 p_init_data.set_init_value(this, false);
644 }
645
650 static const char attribute_xml_tag[];
651 static const char name_xml_attr[];
652 static const char description_xml_attr[];
653 static const char type_xml_attr[];
654 static const char format_xml_attr[];
655 static const char range_xml_attr[];
656 static const char is_multi_value_xml_attr[];
657 static const char mv_implement_xml_attr[];
658 static const char init_value_xml_attr[];
659 static const char is_not_null_xml_attr[];
660 static const char ordered_xml_attr[];
661
662};
663
664inline void
665OksAttribute::__set_data_type(const char * t, size_t len) noexcept
666{
667 p_data_type = get_data_type(t, len);
668}
669
670inline void
671OksData::SetE(const char *s, size_t len, const OksAttribute *a)
672{
673 Clear();
674 type = enum_type;
675 data.ENUMERATION = a->get_enum_value(s, len);
676}
677
678inline void
679OksData::SetE(const std::string &s, const OksAttribute *a)
680{
681 Clear();
682 type = enum_type;
684}
685
686inline void
688{
689 Clear();
690 type = enum_type;
691 data.ENUMERATION = &((*(a->p_enumerators))[0]);
692}
693
694inline void
696{
697 Clear();
698 type = enum_type;
700}
701
702// profit from C++ string object vs. "char *" to create new string (string_type) or known string length (enum_type)
703
704inline void
705OksData::ReadFrom(const std::string& s, const OksAttribute * a)
706{
707 if (type == OksData::string_type)
708 data.STRING = new OksString(s);
709 else if (type == OksData::enum_type)
711 else
712 SetValue(s.c_str(), a);
713}
714
715} // namespace oks
716} // namespace dunedaq
717
718#endif
OKS attribute class.
static const char * uid_type
static const char * s8_int_type
void set_range(const std::string &range)
Set attribute range.
static const char * u32_int_type
static const char * u8_int_type
static const char * time_type
static const char * s64_int_type
bool get_is_multi_values() const noexcept
static const char format_xml_attr[]
void set_type(const std::string &type, bool skip_init=false)
Set attribute type.
static const char description_xml_attr[]
static const char * bool_type
friend std::ostream & operator<<(std::ostream &, const OksAttribute &)
equality operator
static const char name_xml_attr[]
void __set_data_type(const char *t, size_t len) noexcept
const std::string & get_type() const noexcept
Get attribute string type.
static const char ordered_xml_attr[]
const std::string & get_range() const noexcept
Get attribute range.
void set_is_multi_values(bool multi_values)
Set attribute is a single-value or multi-value.
void set_format(Format format)
Set attribute format.
int get_enum_index(const std::string &s) const noexcept
See get_enum_index(const char *, size_t);.
const std::string & get_name() const noexcept
out stream operator
static const char * class_type
static const char * string_type
void save(OksXmlOutputStream &) const
static const char * enum_type
static const char * s32_int_type
static const char mv_implement_xml_attr[]
static const char init_value_xml_attr[]
static bool find_token(const char *token, const char *range) noexcept
Finds token in given range.
static const char * format2str(Format) noexcept
Definition attribute.cpp:62
OksAttribute(const std::string &name, OksClass *p=nullptr)
OKS attribute simple constructor.
static const char attribute_xml_tag[]
static const char * s16_int_type
OksData::Type get_data_type() const noexcept
static const char * u64_int_type
OksAttribute(OksData::Type t, const OksClass *c) noexcept
static const char * double_type
std::vector< std::string > * p_enumerators
bool operator==(const class OksAttribute &) const
const std::string * get_enum_string(uint16_t idx) const noexcept
Returns enumeration string by value.
const std::string & get_init_value() const noexcept
const std::string * get_enum_value(const std::string &s) const
See get_enum_value(const char *, size_t).
const std::string * get_enum_value(const char *s, size_t length) const
Returns pointer on internal enumerator data equal to given string, if such string is defined in attri...
void set_is_no_null(bool no_null)
Set attribute is-no-null property.
static const char is_multi_value_xml_attr[]
bool is_number() const noexcept
Definition attribute.cpp:78
static const char * u16_int_type
std::list< std::string > get_init_values() const
Return list of initial values for mv-attribute.
int get_enum_index(const char *s, size_t length) const noexcept
Finds index of given string in attribute's range.
const std::string & get_description() const noexcept
static const char * date_type
static const char is_not_null_xml_attr[]
static const char * float_type
static Format str2format(const char *) noexcept
Definition attribute.cpp:52
void set_description(const std::string &description)
Set attribute description.
void set_init_value(const std::string &init_value)
Set attribute initialisation value.
static const char type_xml_attr[]
static const char range_xml_attr[]
bool is_integer() const noexcept
Definition attribute.cpp:72
bool get_is_no_null() const noexcept
void set_name(const std::string &name)
Set attribute name.
Format get_format() const noexcept
Get attribute format.
The OKS class.
Definition class.hpp:200
Provides interface to the OKS kernel.
Definition kernel.hpp:577
OksObject describes instance of OksClass.
Definition object.hpp:836
OKS range class.
Definition attribute.hpp:42
std::list< std::pair< OksData, OksData > > m_interval
Definition attribute.hpp:68
OksRange(const std::string &range, OksAttribute *a)
Definition attribute.hpp:45
std::list< OksData > m_less
Definition attribute.hpp:66
std::list< OksData > m_great
Definition attribute.hpp:69
std::list< boost::regex > m_like
Definition attribute.hpp:70
std::list< OksData > m_equal
Definition attribute.hpp:67
void reset(const std::string &range, OksAttribute *a)
Class OKS string.
Definition object.hpp:369
Including Qt Headers.
DAC value out of range
Message.
Definition DACNode.hpp:32
Definition __init__.py:1
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:449
union dunedaq::oks::OksData::Data data
void SetE(OksString *s, const OksAttribute *a)
void SetValue(const char *s, const OksAttribute *a)
void set_init_value(const OksAttribute *attr, bool skip_init)
Set value defined by initial value of attribute.
Definition object.cpp:242
void ReadFrom(const char *, Type, const OksAttribute *)
Definition object.hpp:747
const std::string * ENUMERATION
Definition object.hpp:507