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
31
33
43
45{
46public:
47 OksRange(const std::string& range, OksAttribute* a) { reset(range, a); }
48
49 void reset(const std::string& range, OksAttribute* a);
50
51 bool validate(const OksData&) const;
52
53 inline bool is_empty()
54 {
55 return (m_less.empty() && m_equal.empty() && m_interval.empty() && m_great.empty() && m_like.empty());
56 }
57
58private:
59 std::string m_range;
60
61 std::list<OksData> m_less;
62 std::list<OksData> m_equal;
63 std::list<std::pair<OksData, OksData>> m_interval;
64 std::list<OksData> m_great;
65 std::list<boost::regex> m_like;
66
67private:
68 inline void clear()
69 {
70 m_range.clear();
71
72 m_less.clear();
73 m_equal.clear();
74 m_interval.clear();
75 m_great.clear();
76 m_like.clear();
77 }
78};
79
81
92
94{
95 friend class OksKernel;
96 friend class OksClass;
97 friend class OksIndex;
98 friend class OksObject;
99 friend struct OksData;
100
101public:
103
105 {
106 Oct = 8,
107 Dec = 10,
108 Hex = 16
109 };
110
122
123 OksAttribute(const std::string& name, OksClass* p = nullptr);
124
143
144 OksAttribute(const std::string& name,
145 const std::string& type,
146 bool is_mv,
147 const std::string& range,
148 const std::string& init_v,
149 const std::string& description,
150 bool no_null,
151 Format format = Dec,
152 OksClass* p = nullptr);
153
155 {
156 if (p_enumerators)
157 delete p_enumerators;
158
159 clean_range();
160 }
161
162 bool operator==(const class OksAttribute&) const;
163 friend std::ostream& operator<<(std::ostream&, const OksAttribute&);
164
165 const std::string& get_name() const noexcept { return p_name; }
166
176
177 void set_name(const std::string& name);
178
184
185 const std::string& get_type() const noexcept;
186
213
214 void set_type(const std::string& type, bool skip_init = false);
215
221
222 const std::string& get_range() const noexcept { return p_range; }
223
247
248 void set_range(const std::string& range);
249
259
260 static OksData::Type get_data_type(const std::string& type) noexcept;
261
272
273 static OksData::Type get_data_type(const char* type, size_t len) noexcept;
274
276
277 OksData::Type get_data_type() const noexcept { return p_data_type; }
278
284
285 Format get_format() const noexcept { return p_format; }
286
305
306 void set_format(Format format);
307
309
310 bool is_integer() const noexcept;
311
313
314 bool is_number() const noexcept;
315
317
318 bool get_is_multi_values() const noexcept { return p_multi_values; }
319
329
330 void set_is_multi_values(bool multi_values);
331
333
334 const std::string& get_init_value() const noexcept { return p_init_value; }
335
345
346 void set_init_value(const std::string& init_value);
347
353
354 std::list<std::string> get_init_values() const;
355
357
358 const std::string& get_description() const noexcept { return p_description; }
359
367
368 void set_description(const std::string& description);
369
371
372 bool get_is_no_null() const noexcept { return p_no_null; }
373
383
384 void set_is_no_null(bool no_null);
385
393
394 static bool find_token(const char* token, const char* range) noexcept;
395
406
407 int get_enum_index(const char* s, size_t length) const noexcept;
408
412
413 int get_enum_index(const std::string& s) const noexcept { return get_enum_index(s.data(), s.length()); }
414
429
430 const std::string* get_enum_value(const char* s, size_t length) const;
431
435
436 const std::string* get_enum_value(const std::string& s) const { return get_enum_value(s.data(), s.length()); }
437
447
448 uint16_t get_enum_value(const OksData& d) const noexcept;
449
460
461 const std::string* get_enum_string(uint16_t idx) const noexcept { return &(*p_enumerators)[idx]; }
462
466
467 static const char* bool_type;
468 static const char* s8_int_type;
469 static const char* u8_int_type;
470 static const char* s16_int_type;
471 static const char* u16_int_type;
472 static const char* s32_int_type;
473 static const char* u32_int_type;
474 static const char* s64_int_type;
475 static const char* u64_int_type;
476 static const char* float_type;
477 static const char* double_type;
478 static const char* date_type;
479 static const char* time_type;
480 static const char* string_type;
481 static const char* uid_type;
482 static const char* enum_type;
483 static const char* class_type;
484
485 static Format str2format(const char*) noexcept;
486 static const char* format2str(Format) noexcept;
487
488private:
489 std::string p_name;
490 std::string p_range;
494 std::string p_init_value;
496 std::string p_description;
498 std::vector<std::string>* p_enumerators;
503
504 inline void __set_data_type(const char* t, size_t len) noexcept;
505
507
508 OksAttribute(OksData::Type t, const OksClass* c) noexcept
509 : p_data_type(t)
510 , p_class(const_cast<OksClass*>(c))
511 , p_enumerators(nullptr)
512 , p_range_obj(nullptr)
513 , p_ordered(false)
514 {
515 ;
516 }
517
519
521
523
524 void save(OksXmlOutputStream&) const;
525
526 void init_enum();
527
528 void init_range();
529
530 inline void clean_range()
531 {
532 if (p_range_obj) {
533 delete p_range_obj;
534 p_range_obj = nullptr;
535 }
536 }
537
539 {
540 p_init_data.set_init_value(this, false);
542 }
543
547
548 static const char attribute_xml_tag[];
549 static const char name_xml_attr[];
550 static const char description_xml_attr[];
551 static const char type_xml_attr[];
552 static const char format_xml_attr[];
553 static const char range_xml_attr[];
554 static const char is_multi_value_xml_attr[];
555 static const char mv_implement_xml_attr[];
556 static const char init_value_xml_attr[];
557 static const char is_not_null_xml_attr[];
558 static const char ordered_xml_attr[];
559};
560
561inline void
562OksAttribute::__set_data_type(const char* t, size_t len) noexcept
563{
564 p_data_type = get_data_type(t, len);
565}
566
567inline void
568OksData::SetE(const char* s, size_t len, const OksAttribute* a)
569{
570 Clear();
571 type = enum_type;
572 data.ENUMERATION = a->get_enum_value(s, len);
573}
574
575inline void
576OksData::SetE(const std::string& s, const OksAttribute* a)
577{
578 Clear();
579 type = enum_type;
581}
582
583inline void
585{
586 Clear();
587 type = enum_type;
588 data.ENUMERATION = &((*(a->p_enumerators))[0]);
589}
590
591inline void
593{
594 Clear();
595 type = enum_type;
597}
598
599// profit from C++ string object vs. "char *" to create new string (string_type) or known string length (enum_type)
600
601inline void
602OksData::ReadFrom(const std::string& s, const OksAttribute* a)
603{
605 data.STRING = new OksString(s);
606 else if (type == OksData::enum_type)
608 else
609 SetValue(s.c_str(), a);
610}
611
612} // namespace oks
613} // namespace dunedaq
614
615#endif
OKS attribute class.
Definition attribute.hpp:94
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
static const char name_xml_attr[]
void __set_data_type(const char *t, size_t len) noexcept
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:61
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
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:73
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:55
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:67
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:223
OKS range class.
Definition attribute.hpp:45
OksRange(const std::string &range, OksAttribute *a)
Definition attribute.hpp:47
std::list< std::pair< OksData, OksData > > m_interval
Definition attribute.hpp:63
std::list< OksData > m_less
Definition attribute.hpp:61
std::list< OksData > m_great
Definition attribute.hpp:64
std::list< boost::regex > m_like
Definition attribute.hpp:65
std::list< OksData > m_equal
Definition attribute.hpp:62
void reset(const std::string &range, OksAttribute *a)
Class OKS string.
Definition object.hpp:417
OksString()
to deallocate memory when destroyed
Definition object.hpp:421
bool operator==(const OksString &s1, const OksString &s2)
Implementation of OksString logical equality operator.
Definition object.hpp:453
std::ostream & operator<<(std::ostream &s, const oks::exception &ex)
The DUNE-DAQ namespace.
DAC value out of range
Message.
Definition DACNode.hpp:32
std::string get_type(oks::OksData::Type oks_type, bool is_cpp)
Definition utils.cpp:95
Struct OKS data.
Definition object.hpp:510
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 set_init_value(const OksAttribute *attr, bool skip_init)
Set value defined by initial value of attribute.
Definition object.cpp:248
void ReadFrom(const char *, Type, const OksAttribute *)
Definition object.hpp:1063
const std::string * ENUMERATION
Definition object.hpp:571