DUNE-DAQ
DUNE Trigger and Data Acquisition software
|
OKS attribute class. More...
#include <attribute.hpp>
Public Types | |
enum | Format { Oct = 8 , Dec = 10 , Hex = 16 } |
Public Member Functions | |
OksAttribute (const std::string &name, OksClass *p=nullptr) | |
OKS attribute simple constructor. | |
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) | |
OKS attribute complete constructor. | |
~OksAttribute () | |
bool | operator== (const class OksAttribute &) const |
const std::string & | get_name () const noexcept |
out stream operator | |
void | set_name (const std::string &name) |
Set attribute name. | |
const std::string & | get_type () const noexcept |
Get attribute string type. | |
void | set_type (const std::string &type, bool skip_init=false) |
Set attribute type. | |
const std::string & | get_range () const noexcept |
Get attribute range. | |
void | set_range (const std::string &range) |
Set attribute range. | |
OksData::Type | get_data_type () const noexcept |
Format | get_format () const noexcept |
Get attribute format. | |
void | set_format (Format format) |
Set attribute format. | |
bool | is_integer () const noexcept |
bool | is_number () const noexcept |
bool | get_is_multi_values () const noexcept |
void | set_is_multi_values (bool multi_values) |
Set attribute is a single-value or multi-value. | |
const std::string & | get_init_value () const noexcept |
void | set_init_value (const std::string &init_value) |
Set attribute initialisation value. | |
std::list< std::string > | get_init_values () const |
Return list of initial values for mv-attribute. | |
const std::string & | get_description () const noexcept |
void | set_description (const std::string &description) |
Set attribute description. | |
bool | get_is_no_null () const noexcept |
void | set_is_no_null (bool no_null) |
Set attribute is-no-null property. | |
int | get_enum_index (const char *s, size_t length) const noexcept |
Finds index of given string in attribute's range. | |
int | get_enum_index (const std::string &s) const noexcept |
See get_enum_index(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 attribute's range. | |
const std::string * | get_enum_value (const std::string &s) const |
See get_enum_value(const char *, size_t). | |
uint16_t | get_enum_value (const OksData &d) const noexcept |
Returns index of given enumeration in attribute's range (0 or positive integer value). | |
const std::string * | get_enum_string (uint16_t idx) const noexcept |
Returns enumeration string by value. | |
Static Public Member Functions | |
static OksData::Type | get_data_type (const std::string &type) noexcept |
Converts string to attribute OKS data type. | |
static OksData::Type | get_data_type (const char *type, size_t len) noexcept |
Converts string to attribute OKS data type (fast version). | |
static bool | find_token (const char *token, const char *range) noexcept |
Finds token in given range. | |
static Format | str2format (const char *) noexcept |
static const char * | format2str (Format) noexcept |
Static Public Attributes | |
static const char * | bool_type = "bool" |
static const char * | s8_int_type = "s8" |
static const char * | u8_int_type = "u8" |
static const char * | s16_int_type = "s16" |
static const char * | u16_int_type = "u16" |
static const char * | s32_int_type = "s32" |
static const char * | u32_int_type = "u32" |
static const char * | s64_int_type = "s64" |
static const char * | u64_int_type = "u64" |
static const char * | float_type = "float" |
static const char * | double_type = "double" |
static const char * | date_type = "date" |
static const char * | time_type = "time" |
static const char * | string_type = "string" |
static const char * | uid_type = "uid" |
static const char * | enum_type = "enum" |
static const char * | class_type = "class" |
Private Member Functions | |
void | __set_data_type (const char *t, size_t len) noexcept |
OksAttribute (OksData::Type t, const OksClass *c) noexcept | |
OksAttribute (OksXmlInputStream &, OksClass *) | |
void | save (OksXmlOutputStream &) const |
void | init_enum () |
void | init_range () |
void | clean_range () |
void | set_init_data () |
Private Attributes | |
std::string | p_name |
std::string | p_range |
OksData::Type | p_data_type |
bool | p_multi_values |
bool | p_no_null |
std::string | p_init_value |
Format | p_format |
std::string | p_description |
OksClass * | p_class |
std::vector< std::string > * | p_enumerators |
OksRange * | p_range_obj |
OksData | p_init_data |
OksData | p_empty_init_data |
bool | p_ordered |
Static Private Attributes | |
static const char | attribute_xml_tag [] = "attribute" |
static const char | name_xml_attr [] = "name" |
static const char | description_xml_attr [] = "description" |
static const char | type_xml_attr [] = "type" |
static const char | format_xml_attr [] = "format" |
static const char | range_xml_attr [] = "range" |
static const char | is_multi_value_xml_attr [] = "is-multi-value" |
static const char | mv_implement_xml_attr [] |
static const char | init_value_xml_attr [] = "init-value" |
static const char | is_not_null_xml_attr [] = "is-not-null" |
static const char | ordered_xml_attr [] = "ordered" |
Friends | |
class | OksKernel |
class | OksClass |
class | OksIndex |
class | OksObject |
struct | OksData |
std::ostream & | operator<< (std::ostream &s, const OksAttribute &a) |
equality operator | |
OKS attribute class.
This class implements OKS attribute that is a part of an OKS class. An attribute has name, type, range, initial value and description. An attribute can be single-value or multi-value. An attribute can be non-null.
Definition at line 101 of file attribute.hpp.
Format for integer representation (OKS data file, print output)
Enumerator | |
---|---|
Oct | |
Dec | |
Hex |
Definition at line 113 of file attribute.hpp.
dunedaq::oks::OksAttribute::OksAttribute | ( | const std::string & | name, |
OksClass * | p = nullptr ) |
OKS attribute simple constructor.
Create new OKS attribute providing name.
The parameter is:
name | name of the attribute |
p | containing parent class |
oks::exception | is thrown in case of problems. |
Definition at line 206 of file attribute.cpp.
dunedaq::oks::OksAttribute::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 ) |
OKS attribute complete constructor.
Create new OKS attribute providing all properties.
The parameters are:
name | name of the attribute (max 128 bytes, see #s_max_name_length variable) |
type | type of attribute; see set_type() for details |
is_mv | if true, the attribute is multi-values, see set_is_multi_values() for details |
range | range of attribute, see set_range() for details |
init_v | initial value of attribute |
description | description of the method (max 2000 bytes, see #s_max_description_length variable) |
no_null | if true, the value of attribute cannot be null, see set_is_no_null() for details |
format | format of attribute for integers, see set_format() for details |
p | containing parent class |
oks::exception | is thrown in case of problems. |
Definition at line 222 of file attribute.cpp.
|
inline |
Definition at line 157 of file attribute.hpp.
|
inlineprivatenoexcept |
Private constructor used by OksData
Definition at line 606 of file attribute.hpp.
|
private |
Private constructor from XML stream
Definition at line 335 of file attribute.cpp.
|
inlineprivatenoexcept |
Definition at line 665 of file attribute.hpp.
|
inlineprivate |
Definition at line 630 of file attribute.hpp.
|
staticnoexcept |
Finds token in given range.
token | string to find |
range | pass true to declare the value cannot be null |
Definition at line 805 of file attribute.cpp.
|
staticnoexcept |
Definition at line 62 of file attribute.cpp.
|
inlinenoexcept |
Get attribute OKS data type.
Definition at line 304 of file attribute.hpp.
|
staticnoexcept |
Converts string to attribute OKS data type (fast version).
See set_type() for more information about allowed values.
type | the string value to be converted to data type |
len | lenght of type value |
Definition at line 477 of file attribute.cpp.
|
staticnoexcept |
Converts string to attribute OKS data type.
See set_type() for more information about allowed values.
type | the string value to be converted to data type |
Definition at line 470 of file attribute.cpp.
|
inlinenoexcept |
Return description of attribute
Definition at line 417 of file attribute.hpp.
|
noexcept |
Finds index of given string in attribute's range.
The method can only be applied, if attribute is enumeration.
s | string to find |
length | length of string |
Definition at line 131 of file attribute.cpp.
|
inlinenoexcept |
See get_enum_index(const char *, size_t);.
Definition at line 490 of file attribute.hpp.
|
inlinenoexcept |
Returns enumeration string by value.
The method can only be applied, if attribute is enumeration and the index is within number of items in enumeration range.
idx | enumeration index |
Definition at line 551 of file attribute.hpp.
const std::string * dunedaq::oks::OksAttribute::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 attribute's range.
The method can only be applied, if attribute is enumeration. The returned pointer is valid unless the attribute is not destroyed or modified.
s | string to find |
length | length of string |
std::exception | is thrown, if no such string found. |
Definition at line 154 of file attribute.cpp.
|
noexcept |
Returns index of given enumeration in attribute's range (0 or positive integer value).
The method can only be applied, if attribute is enumeration and the data were created for given attribute.
d | OKS data created for given attribute |
Definition at line 179 of file attribute.cpp.
|
inline |
See get_enum_value(const char *, size_t).
Definition at line 519 of file attribute.hpp.
|
inlinenoexcept |
Get attribute format.
The format meaning is described by the set_format() method.
Definition at line 317 of file attribute.hpp.
|
inlinenoexcept |
The attribute initialisation value.
Definition at line 384 of file attribute.hpp.
std::list< std::string > dunedaq::oks::OksAttribute::get_init_values | ( | ) | const |
Return list of initial values for mv-attribute.
oks::AttributeReadError | is thrown if initial values became invalid (may happen for class_type attributes), |
|
inlinenoexcept |
The method returns true, if the attribute is multi-values.
Definition at line 361 of file attribute.hpp.
|
inlinenoexcept |
Return true, if the attribute's value cannot be equal to null.
Definition at line 438 of file attribute.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
Get attribute range.
The range meaning is described by the set_range() method.
Definition at line 238 of file attribute.hpp.
|
noexcept |
Get attribute string type.
The type meaning is described by the set_type() method.
Definition at line 518 of file attribute.cpp.
|
private |
Definition at line 84 of file attribute.cpp.
|
private |
Definition at line 115 of file attribute.cpp.
|
noexcept |
The method returns true, if the attribute is an integer number.
Definition at line 72 of file attribute.cpp.
|
noexcept |
The method returns true, if the attribute is a number.
Definition at line 78 of file attribute.cpp.
bool dunedaq::oks::OksAttribute::operator== | ( | const class OksAttribute & | a | ) | const |
Definition at line 247 of file attribute.cpp.
|
private |
Private method to save in XML stream
Definition at line 292 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_description | ( | const std::string & | description | ) |
Set attribute description.
description | new description of attribute (max 2000 bytes, see #s_max_description_length variable) |
oks::exception | is thrown in case of problems. |
Definition at line 689 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_format | ( | Format | format | ) |
Set attribute format.
There are 3 OKS formats for integer attributes:
The value of an integer attribute will be printed out and stored by OKS in the format defined by the schema for that attribute accordingly to C/C++ style. E.g. decimal value 255 can also be presented as 0377 (oct) or 0xFF (hex).
The method parameter is:
format | new format |
oks::exception | is thrown in case of problems. |
Definition at line 720 of file attribute.cpp.
|
inlineprivate |
Definition at line 640 of file attribute.hpp.
void dunedaq::oks::OksAttribute::set_init_value | ( | const std::string & | init_value | ) |
Set attribute initialisation value.
When new object is created, this is default value of attribute.
multi_values | new init value |
oks::exception | is thrown in case of problems. |
Definition at line 662 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_is_multi_values | ( | bool | multi_values | ) |
Set attribute is a single-value or multi-value.
If true, the attribute value contains multiple single values, e.g. list of numbers, strings, etc.
multi_values | pass true to declare the value is multi-value |
oks::exception | is thrown in case of problems. |
Definition at line 644 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_is_no_null | ( | bool | no_null | ) |
Set attribute is-no-null property.
If true, a number cannot be 0 or string cannot be empty.
no_null | pass true to declare the value cannot be null |
oks::exception | is thrown in case of problems. |
Definition at line 705 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_name | ( | const std::string & | name | ) |
Set attribute name.
Attributes linked with the same class shall have different names.
name | new name of attribute (max 128 bytes, see #s_max_name_length variable) |
oks::exception | is thrown in case of problems. |
Definition at line 589 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_range | ( | const std::string & | range | ) |
Set attribute range.
To define a range the UML syntax is used. It can be defined as list of tokens e.g. "A,B,C..D,*..F,G..*", which means that the attribute may have one of the following value:
Note, that spaces are not allowed.
The empty range means that the attribute may have any value allowed by its type. The are two exceptions:
range | new range (max 1024 bytes, see #s_max_range_length variable) |
oks::exception | is thrown in case of problems. |
Definition at line 735 of file attribute.cpp.
void dunedaq::oks::OksAttribute::set_type | ( | const std::string & | type, |
bool | skip_init = false ) |
Set attribute type.
The valid attribute types are:
type | new type |
skip_init | if true, do not initialise enum and range |
oks::exception | is thrown in case of problems. |
Definition at line 549 of file attribute.cpp.
|
staticnoexcept |
Definition at line 52 of file attribute.cpp.
|
friend |
Definition at line 104 of file attribute.hpp.
|
friend |
Definition at line 107 of file attribute.hpp.
|
friend |
Definition at line 105 of file attribute.hpp.
|
friend |
Definition at line 103 of file attribute.hpp.
|
friend |
Definition at line 106 of file attribute.hpp.
|
friend |
equality operator
Definition at line 264 of file attribute.cpp.
|
staticprivate |
Valid xml tags and attributes
Definition at line 650 of file attribute.hpp.
|
static |
Valid attribute types
Definition at line 561 of file attribute.hpp.
|
static |
Definition at line 577 of file attribute.hpp.
|
static |
Definition at line 572 of file attribute.hpp.
|
staticprivate |
Definition at line 652 of file attribute.hpp.
|
static |
Definition at line 571 of file attribute.hpp.
|
static |
Definition at line 576 of file attribute.hpp.
|
static |
Definition at line 570 of file attribute.hpp.
|
staticprivate |
Definition at line 654 of file attribute.hpp.
|
staticprivate |
Definition at line 658 of file attribute.hpp.
|
staticprivate |
Definition at line 656 of file attribute.hpp.
|
staticprivate |
Definition at line 659 of file attribute.hpp.
|
staticprivate |
Definition at line 657 of file attribute.hpp.
|
staticprivate |
Definition at line 651 of file attribute.hpp.
|
staticprivate |
Definition at line 660 of file attribute.hpp.
|
private |
Definition at line 594 of file attribute.hpp.
|
private |
Definition at line 588 of file attribute.hpp.
|
private |
Definition at line 593 of file attribute.hpp.
|
private |
Definition at line 598 of file attribute.hpp.
|
private |
Definition at line 595 of file attribute.hpp.
|
private |
Definition at line 592 of file attribute.hpp.
|
private |
Definition at line 597 of file attribute.hpp.
|
private |
Definition at line 591 of file attribute.hpp.
|
private |
Definition at line 589 of file attribute.hpp.
|
private |
Definition at line 586 of file attribute.hpp.
|
private |
Definition at line 590 of file attribute.hpp.
|
private |
Definition at line 599 of file attribute.hpp.
|
private |
Definition at line 587 of file attribute.hpp.
|
private |
Definition at line 596 of file attribute.hpp.
|
staticprivate |
Definition at line 655 of file attribute.hpp.
|
static |
Definition at line 564 of file attribute.hpp.
|
static |
Definition at line 566 of file attribute.hpp.
|
static |
Definition at line 568 of file attribute.hpp.
|
static |
Definition at line 562 of file attribute.hpp.
|
static |
Definition at line 574 of file attribute.hpp.
|
static |
Definition at line 573 of file attribute.hpp.
|
staticprivate |
Definition at line 653 of file attribute.hpp.
|
static |
Definition at line 565 of file attribute.hpp.
|
static |
Definition at line 567 of file attribute.hpp.
|
static |
Definition at line 569 of file attribute.hpp.
|
static |
Definition at line 563 of file attribute.hpp.
|
static |
Definition at line 575 of file attribute.hpp.