DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
attribute.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/attribute.h to include/oks/attribute.hpp).
5
14
15#ifndef OKS_ATTRIBUTE_H
16#define OKS_ATTRIBUTE_H
17
18#include "oks/defs.hpp"
19#include "oks/object.hpp"
20
21#include <string>
22#include <vector>
23
24#include <boost/regex.hpp>
25
26namespace dunedaq {
27namespace oks {
28
29
32
33
35
45
47{
48public:
49
50 OksRange(const std::string& range, OksAttribute * a)
51 {
52 reset(range, a);
53 }
54
55 void
56 reset(const std::string& range, OksAttribute * a);
57
58 bool
59 validate(const OksData&) const;
60
61 inline bool
63 {
64 return (m_less.empty() && m_equal.empty() && m_interval.empty() && m_great.empty() && m_like.empty());
65 }
66
67private:
68
69 std::string m_range;
70
71 std::list<OksData> m_less;
72 std::list<OksData> m_equal;
73 std::list<std::pair<OksData,OksData>> m_interval;
74 std::list<OksData> m_great;
75 std::list<boost::regex> m_like;
76
77private:
78
79 inline void
81 {
82 m_range.clear();
83
84 m_less.clear();
85 m_equal.clear();
86 m_interval.clear();
87 m_great.clear();
88 m_like.clear();
89 }
90};
91
92
94
105
107{
108 friend class OksKernel;
109 friend class OksClass;
110 friend class OksIndex;
111 friend class OksObject;
112 friend struct OksData;
113
114public:
115
117
118 enum Format {
119 Oct = 8,
120 Dec = 10,
121 Hex = 16
122 };
123
124
136
137 OksAttribute(const std::string& name, OksClass * p = nullptr);
138
139
158
159 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);
160
161
163 {
164 if (p_enumerators)
165 delete p_enumerators;
166
167 clean_range();
168 }
169
170
171 bool operator==(const class OksAttribute&) const;
172 friend std::ostream& operator<<(std::ostream&, const OksAttribute&);
173
174 const std::string&
175 get_name() const noexcept
176 {
177 return p_name;
178 }
179
180
190
191 void
192 set_name(const std::string& name);
193
194
200
201 const std::string&
202 get_type() const noexcept;
203
204
231
232 void
233 set_type(const std::string& type, bool skip_init = false);
234
235
241
242 const std::string&
243 get_range() const noexcept
244 {
245 return p_range;
246 }
247
248
272
273 void
274 set_range(const std::string& range);
275
276
286
287 static OksData::Type
288 get_data_type(const std::string& type) noexcept;
289
290
301
302 static OksData::Type
303 get_data_type(const char * type, size_t len) noexcept;
304
305
307
309 get_data_type() const noexcept
310 {
311 return p_data_type;
312 }
313
314
320
321 Format
322 get_format() const noexcept
323 {
324 return p_format;
325 }
326
327
346
347 void
348 set_format(Format format);
349
350
352
353 bool
354 is_integer() const noexcept;
355
356
358
359 bool
360 is_number() const noexcept;
361
362
364
365 bool
366 get_is_multi_values() const noexcept
367 {
368 return p_multi_values;
369 }
370
371
381
382 void
383 set_is_multi_values(bool multi_values);
384
385
387
388 const std::string&
389 get_init_value() const noexcept
390 {
391 return p_init_value;
392 }
393
394
404
405 void
406 set_init_value(const std::string& init_value);
407
408
414
415 std::list<std::string>
417
418
420
421 const std::string&
422 get_description() const noexcept
423 {
424 return p_description;
425 }
426
427
435
436 void
437 set_description(const std::string& description);
438
439
441
442 bool
443 get_is_no_null() const noexcept
444 {
445 return p_no_null;
446 }
447
448
458
459
460 void
461 set_is_no_null(bool no_null);
462
470
471
472 static bool
473 find_token(const char * token, const char * range) noexcept;
474
485
486
487 int
488 get_enum_index(const char * s, size_t length) const noexcept;
489
493
494 int
495 get_enum_index(const std::string& s) const noexcept
496 {
497 return get_enum_index(s.data(), s.length());
498 }
499
500
514
515 const std::string *
516 get_enum_value(const char * s, size_t length) const;
517
518
522
523 const std::string *
524 get_enum_value(const std::string& s) const
525 {
526 return get_enum_value(s.data(), s.length());
527 }
528
529
539
540
541 uint16_t
542 get_enum_value(const OksData& d) const noexcept;
543
553
554
555 const std::string *
556 get_enum_string(uint16_t idx) const noexcept
557 {
558 return &(*p_enumerators)[idx];
559 }
560
561
565
566 static const char * bool_type;
567 static const char * s8_int_type;
568 static const char * u8_int_type;
569 static const char * s16_int_type;
570 static const char * u16_int_type;
571 static const char * s32_int_type;
572 static const char * u32_int_type;
573 static const char * s64_int_type;
574 static const char * u64_int_type;
575 static const char * float_type;
576 static const char * double_type;
577 static const char * date_type;
578 static const char * time_type;
579 static const char * string_type;
580 static const char * uid_type;
581 static const char * enum_type;
582 static const char * class_type;
583
584 static Format
585 str2format(const char *) noexcept;
586 static const char *
587 format2str(Format) noexcept;
588
589private:
590
591 std::string p_name;
592 std::string p_range;
596 std::string p_init_value;
598 std::string p_description;
600 std::vector<std::string> * p_enumerators;
605
606 inline void
607 __set_data_type(const char * t, size_t len) noexcept;
608
610
611 OksAttribute(OksData::Type t, const OksClass * c) noexcept :
612 p_data_type(t), p_class(const_cast<OksClass*>(c)), p_enumerators(nullptr), p_range_obj(nullptr), p_ordered(false)
613 {
614 ;
615 }
616
617
619
621
622
624
625 void
626 save(OksXmlOutputStream&) const;
627
628 void
629 init_enum();
630
631 void
632 init_range();
633
634 inline void
636 {
637 if (p_range_obj)
638 {
639 delete p_range_obj;
640 p_range_obj = nullptr;
641 }
642 }
643
644 void
646 {
647 p_init_data.set_init_value(this, false);
648 p_empty_init_data.set_init_value(this, true);
649 }
650
654
655 static const char attribute_xml_tag[];
656 static const char name_xml_attr[];
657 static const char description_xml_attr[];
658 static const char type_xml_attr[];
659 static const char format_xml_attr[];
660 static const char range_xml_attr[];
661 static const char is_multi_value_xml_attr[];
662 static const char mv_implement_xml_attr[];
663 static const char init_value_xml_attr[];
664 static const char is_not_null_xml_attr[];
665 static const char ordered_xml_attr[];
666
667};
668
669inline void
670OksAttribute::__set_data_type(const char * t, size_t len) noexcept
671{
672 p_data_type = get_data_type(t, len);
673}
674
675inline void
676OksData::SetE(const char *s, size_t len, const OksAttribute *a)
677{
678 Clear();
679 type = enum_type;
680 data.ENUMERATION = a->get_enum_value(s, len);
681}
682
683inline void
684OksData::SetE(const std::string &s, const OksAttribute *a)
685{
686 Clear();
687 type = enum_type;
688 data.ENUMERATION = a->get_enum_value(s);
689}
690
691inline void
693{
694 Clear();
695 type = enum_type;
696 data.ENUMERATION = &((*(a->p_enumerators))[0]);
697}
698
699inline void
701{
702 Clear();
703 type = enum_type;
704 data.ENUMERATION = a->get_enum_value(s);
705}
706
707// profit from C++ string object vs. "char *" to create new string (string_type) or known string length (enum_type)
708
709inline void
710OksData::ReadFrom(const std::string& s, const OksAttribute * a)
711{
713 data.STRING = new OksString(s);
714 else if (type == OksData::enum_type)
715 data.ENUMERATION = a->get_enum_value(s);
716 else
717 SetValue(s.c_str(), a);
718}
719
720} // namespace oks
721} // namespace dunedaq
722
723#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:67
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:83
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:57
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:77
bool get_is_no_null() const noexcept
static OksData::Type get_data_type(const std::string &type) noexcept
Converts string to attribute OKS data type.
void set_name(const std::string &name)
Set attribute name.
Format get_format() const noexcept
Get attribute format.
The OKS class.
Definition class.hpp:205
OKS range class.
Definition attribute.hpp:47
std::list< std::pair< OksData, OksData > > m_interval
Definition attribute.hpp:73
OksRange(const std::string &range, OksAttribute *a)
Definition attribute.hpp:50
std::list< OksData > m_less
Definition attribute.hpp:71
std::list< OksData > m_great
Definition attribute.hpp:74
std::list< boost::regex > m_like
Definition attribute.hpp:75
std::list< OksData > m_equal
Definition attribute.hpp:72
void reset(const std::string &range, OksAttribute *a)
Class OKS string.
Definition object.hpp:374
Including Qt Headers.
Definition module.cpp:16
DAC value out of range
Message.
Definition DACNode.hpp:32
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:454
union dunedaq::oks::OksData::Data data
void SetE(OksString *s, const OksAttribute *a)
void SetValue(const char *s, const OksAttribute *a)
enum dunedaq::oks::OksData::Type type
void ReadFrom(const char *, Type, const OksAttribute *)
Definition object.hpp:752