DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::OksAttribute Class Reference

OKS attribute class. More...

#include <attribute.hpp>

Collaboration diagram for dunedaq::oks::OksAttribute:
[legend]

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

Detailed Description

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 93 of file attribute.hpp.

Member Enumeration Documentation

◆ Format

Format for integer representation (OKS data file, print output)

Enumerator
Oct 
Dec 
Hex 

Definition at line 104 of file attribute.hpp.

Constructor & Destructor Documentation

◆ OksAttribute() [1/4]

dunedaq::oks::OksAttribute::OksAttribute ( const std::string & name,
OksClass * p = nullptr )

OKS attribute simple constructor.

Create new OKS attribute providing name.

The parameter is:

Parameters
namename of the attribute
pcontaining parent class
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 181 of file attribute.cpp.

182 : p_name(nm)
184 , p_multi_values(false)
185 , p_no_null(false)
187 , p_class(p)
188 , p_enumerators(nullptr)
189 , p_range_obj(nullptr)
190 , p_ordered(false)
191
192{
193 validate_not_empty(p_name, "attribute name");
194}
std::vector< std::string > * p_enumerators
void validate_not_empty(const std::string &value, const char *name)

◆ OksAttribute() [2/4]

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:

Parameters
namename of the attribute (max 128 bytes, see #s_max_name_length variable)
typetype of attribute; see set_type() for details
is_mvif true, the attribute is multi-values, see set_is_multi_values() for details
rangerange of attribute, see set_range() for details
init_vinitial value of attribute
descriptiondescription of the method (max 2000 bytes, see #s_max_description_length variable)
no_nullif true, the value of attribute cannot be null, see set_is_no_null() for details
formatformat of attribute for integers, see set_format() for details
pcontaining parent class
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 196 of file attribute.cpp.

205 : p_name(nm)
206 , p_range(r)
208 , p_multi_values(is_mv)
209 , p_no_null(no_null)
210 , p_init_value(init_v)
211 , p_format(f)
212 , p_description(ds)
213 , p_class(p)
214 , p_enumerators(nullptr)
215 , p_range_obj(nullptr)
216 , p_ordered(false)
217{
218 set_type(t, true);
219 validate_not_empty(p_name, "attribute name");
220 init_enum();
221 init_range();
222 // cannot call set_init_data() because of the CLASS data type, since other class may not be known yet;
223 // initialize the init_data in the register_all_classes() call
224}
void set_type(const std::string &type, bool skip_init=false)
Set attribute type.
static OksData::Type get_data_type(const std::string &type) noexcept
Converts string to attribute OKS data type.

◆ ~OksAttribute()

dunedaq::oks::OksAttribute::~OksAttribute ( )
inline

Definition at line 154 of file attribute.hpp.

155 {
156 if (p_enumerators)
157 delete p_enumerators;
158
159 clean_range();
160 }

◆ OksAttribute() [3/4]

dunedaq::oks::OksAttribute::OksAttribute ( OksData::Type t,
const OksClass * c )
inlineprivatenoexcept

Private constructor used by OksData

Definition at line 508 of file attribute.hpp.

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 }

◆ OksAttribute() [4/4]

dunedaq::oks::OksAttribute::OksAttribute ( OksXmlInputStream & s,
OksClass * parent )
private

Private constructor from XML stream

Definition at line 308 of file attribute.cpp.

310 , p_multi_values(false)
311 , p_no_null(false)
313 , p_class(parent)
314 , p_enumerators(nullptr)
315 , p_range_obj(nullptr)
316 , p_ordered(false)
317{
318 // read attributes of OksAttribute from xml
319
320 try {
321 while (true) {
322 OksXmlAttribute attr(s);
323
324 // check for close of tag
325
326 if (cmp_str1(attr.name(), "/")) {
327 break;
328 }
329
330 // check for known oks-attribute' attributes
331
332 else if (cmp_str4(attr.name(), name_xml_attr))
333 p_name.assign(attr.value(), attr.value_len());
334 else if (cmp_str11(attr.name(), description_xml_attr))
335 p_description.assign(attr.value(), attr.value_len());
336 else if (cmp_str4(attr.name(), type_xml_attr)) {
337 __set_data_type(attr.value(), attr.value_len());
339 throw BadFileData(std::string("Value \'") + attr.value() + "\' is not a valid attribute type",
340 s.get_line_no(),
341 s.get_line_pos());
342 }
343 } else if (cmp_str5(attr.name(), range_xml_attr))
344 p_range.assign(attr.value(), attr.value_len());
345 else if (cmp_str6(attr.name(), format_xml_attr))
346 p_format = str2format(attr.value());
347 else if (cmp_str14(attr.name(), is_multi_value_xml_attr))
348 p_multi_values = xml::str2bool(attr.value());
349 else if (cmp_str10(attr.name(), init_value_xml_attr))
350 p_init_value.assign(attr.value(), attr.value_len());
351 else if (cmp_str11(attr.name(), is_not_null_xml_attr))
352 p_no_null = xml::str2bool(attr.value());
353 else if (cmp_str7(attr.name(), ordered_xml_attr))
354 p_ordered = xml::str2bool(attr.value());
355 else if (!strcmp(attr.name(), "multi-value-implementation"))
356 s.error_msg("OksAttribute::OksAttribute(OksXmlInputStream&)")
357 << "Obsolete oks-attribute\'s attribute \'" << attr.name() << "\'\n";
358 else
359 s.throw_unexpected_attribute(attr.name());
360 }
361 } catch (exception& e) {
362 throw FailedRead("xml attribute", e);
363 } catch (std::exception& e) {
364 throw FailedRead("xml attribute", e.what());
365 }
366
367 // check validity of read values
368
370 throw FailedRead("oks attribute", BadFileData("attribute type is not set", s.get_line_no(), s.get_line_pos()));
371 }
372
373 try {
374 validate_not_empty(p_name, "attribute name");
375 init_enum();
376 init_range();
377 } catch (std::exception& ex) {
378 throw FailedRead("oks attribute", BadFileData(ex.what(), s.get_line_no(), s.get_line_pos()));
379 }
380
381 if (p_init_value.empty()) {
383 std::ostringstream text;
384 text << "single-value attribute \"" << p_name << "\" is of \"class_type\" and has empty init value";
385 throw FailedRead("oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
386 }
387 } else {
389 try {
390 OksData _d;
391 if (p_multi_values) {
392 _d.SetValues(p_init_value.c_str(), this);
393 } else {
394 _d.type = p_data_type;
395 _d.SetValue(p_init_value.c_str(), 0);
396 }
397 } catch (exception& ex) {
398 std::ostringstream text;
399 text << "attribute \"" << p_name << "\" has bad init value:\n" << ex.what();
400 throw FailedRead("oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
401 }
402 }
403 }
404
405 try {
407 } catch (std::exception& ex) {
408 std::ostringstream text;
409 text << "attribute \"" << p_name << "\" has mismatch between init value and range:\n" << ex.what();
410 throw FailedRead("oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
411 }
412
413 // set_init_data();
414}
BadFileData(const std::string &what, unsigned long line_no, unsigned long line_pos, int level_arg=0) noexcept
Definition xml.hpp:49
FailedRead(const std::string &what, const exception &reason) noexcept
Definition xml.hpp:67
static const char format_xml_attr[]
static const char description_xml_attr[]
static const char name_xml_attr[]
void __set_data_type(const char *t, size_t len) noexcept
static const char ordered_xml_attr[]
static const char init_value_xml_attr[]
static const char is_multi_value_xml_attr[]
static const char is_not_null_xml_attr[]
static Format str2format(const char *) noexcept
Definition attribute.cpp:55
static const char type_xml_attr[]
static const char range_xml_attr[]
bool str2bool(const char *s) noexcept
Definition xml.hpp:36
bool cmp_str1(const char *s1, const char s2[2])
Definition cstring.hpp:15
bool cmp_str4(const char *s1, const char s2[5])
Definition cstring.hpp:45
bool cmp_str6(const char *s1, const char s2[7])
Definition cstring.hpp:69
bool cmp_str10(const char *s1, const char s2[11])
Definition cstring.hpp:111
void validate_init2range(const OksAttribute *a)
bool cmp_str5(const char *s1, const char s2[6])
Definition cstring.hpp:57
bool cmp_str11(const char *s1, const char s2[12])
Definition cstring.hpp:117
bool cmp_str14(const char *s1, const char s2[14])
Definition cstring.hpp:135
bool cmp_str7(const char *s1, const char s2[8])
Definition cstring.hpp:81

Member Function Documentation

◆ __set_data_type()

void dunedaq::oks::OksAttribute::__set_data_type ( const char * t,
size_t len )
inlineprivatenoexcept

Definition at line 562 of file attribute.hpp.

563{
564 p_data_type = get_data_type(t, len);
565}

◆ clean_range()

void dunedaq::oks::OksAttribute::clean_range ( )
inlineprivate

Definition at line 530 of file attribute.hpp.

531 {
532 if (p_range_obj) {
533 delete p_range_obj;
534 p_range_obj = nullptr;
535 }
536 }

◆ find_token()

bool dunedaq::oks::OksAttribute::find_token ( const char * token,
const char * range )
staticnoexcept

Finds token in given range.

Parameters
tokenstring to find
rangepass true to declare the value cannot be null
Returns
The method returns true, if the token is found in the range

Definition at line 729 of file attribute.cpp.

730{
731 const char* p;
732
733 if (token && (p = strstr(range, token)) != 0) {
734 int len = strlen(token);
735
736 do {
737 if (((p != range) && (p[-1] != ',')) || ((p[len] != ',') && (p[len] != '\0'))) {
738 p = strstr(p + 1, token);
739 } else {
740 return true;
741 }
742
743 } while (p != 0);
744 }
745
746 return false;
747}
DAC value out of range
Message.
Definition DACNode.hpp:32

◆ format2str()

const char * dunedaq::oks::OksAttribute::format2str ( Format f)
staticnoexcept

Definition at line 61 of file attribute.cpp.

62{
63 return (f == Dec ? "dec" : f == Hex ? "hex" : "oct");
64}

◆ get_data_type() [1/3]

OksData::Type dunedaq::oks::OksAttribute::get_data_type ( ) const
inlinenoexcept

Get attribute OKS data type.

Definition at line 277 of file attribute.hpp.

277{ return p_data_type; }

◆ get_data_type() [2/3]

OksData::Type dunedaq::oks::OksAttribute::get_data_type ( const char * type,
size_t len )
staticnoexcept

Converts string to attribute OKS data type (fast version).

See set_type() for more information about allowed values.

Parameters
typethe string value to be converted to data type
lenlenght of type value
Returns
the OKS data type; return OksData::unknown_type if the type cannot be detected

Definition at line 423 of file attribute.cpp.

424{
425 switch (len) {
426 case 3:
427 if (cmp_str3n(t, uid_type))
428 return OksData::uid2_type; // "uid"
429 else if (cmp_str3n(t, u32_int_type))
430 return OksData::u32_int_type; // "u32"
431 else if (cmp_str3n(t, s32_int_type))
432 return OksData::s32_int_type; // "s32"
433 else if (cmp_str3n(t, u16_int_type))
434 return OksData::u16_int_type; // "u16"
435 else if (cmp_str3n(t, s16_int_type))
436 return OksData::s16_int_type; // "s16"
437 else if (cmp_str3n(t, s64_int_type))
438 return OksData::s64_int_type; // "s64"
439 else if (cmp_str3n(t, u64_int_type))
440 return OksData::u64_int_type; // "u64"
441 break;
442
443 case 6:
444 if (cmp_str6n(t, string_type))
445 return OksData::string_type; // "string"
446 else if (cmp_str6n(t, double_type))
447 return OksData::double_type; // "double"
448 break;
449
450 case 4:
451 if (cmp_str4n(t, bool_type))
452 return OksData::bool_type; // "bool"
453 else if (cmp_str4n(t, enum_type))
454 return OksData::enum_type; // "enum"
455 else if (cmp_str4n(t, date_type))
456 return OksData::date_type; // "date"
457 else if (cmp_str4n(t, time_type))
458 return OksData::time_type; // "time"
459 break;
460
461 case 5:
462 if (cmp_str5n(t, float_type))
463 return OksData::float_type; // "float"
464 else if (cmp_str5n(t, class_type))
465 return OksData::class_type; // "class"
466 break;
467
468 case 2:
469 if (cmp_str2n(t, s8_int_type))
470 return OksData::s8_int_type; // "s8"
471 else if (cmp_str2n(t, u8_int_type))
472 return OksData::u8_int_type; // "u8"
473 break;
474 }
475
477}
static const char * uid_type
static const char * s8_int_type
static const char * u32_int_type
static const char * u8_int_type
static const char * time_type
static const char * s64_int_type
static const char * bool_type
static const char * class_type
static const char * string_type
static const char * enum_type
static const char * s32_int_type
static const char * s16_int_type
static const char * u64_int_type
static const char * double_type
static const char * u16_int_type
static const char * date_type
static const char * float_type
bool cmp_str2n(const char *s1, const char s2[2])
Definition cstring.hpp:27
bool cmp_str5n(const char *s1, const char s2[5])
Definition cstring.hpp:63
bool cmp_str3n(const char *s1, const char s2[3])
Definition cstring.hpp:39
bool cmp_str6n(const char *s1, const char s2[6])
Definition cstring.hpp:75
bool cmp_str4n(const char *s1, const char s2[4])
Definition cstring.hpp:51

◆ get_data_type() [3/3]

OksData::Type dunedaq::oks::OksAttribute::get_data_type ( const std::string & type)
staticnoexcept

Converts string to attribute OKS data type.

See set_type() for more information about allowed values.

Parameters
typethe string value to be converted to data type
Returns
the OKS data type; return OksData::unknown_type if the type cannot be detected

Definition at line 417 of file attribute.cpp.

418{
419 return get_data_type(t.c_str(), t.size());
420}

◆ get_description()

const std::string & dunedaq::oks::OksAttribute::get_description ( ) const
inlinenoexcept

Return description of attribute

Definition at line 358 of file attribute.hpp.

358{ return p_description; }

◆ get_enum_index() [1/2]

int dunedaq::oks::OksAttribute::get_enum_index ( const char * s,
size_t length ) const
noexcept

Finds index of given string in attribute's range.

The method can only be applied, if attribute is enumeration.

Parameters
sstring to find
lengthlength of string
Returns
The method returns 0 or positive integer index, if the string was found, and negative integer, if not.

Definition at line 117 of file attribute.cpp.

118{
120 for (int i = 0; i < (int)p_enumerators->size(); ++i) {
121 const std::string* x = &((*p_enumerators)[i]);
122 if (x->length() == length) {
123 if (memcmp(s, x->data(), length) == 0) {
124 return i;
125 }
126 }
127 }
128
129 return (-1);
130 }
131
132 return (-2);
133}

◆ get_enum_index() [2/2]

int dunedaq::oks::OksAttribute::get_enum_index ( const std::string & s) const
inlinenoexcept

See get_enum_index(const char *, size_t);.

Definition at line 413 of file attribute.hpp.

413{ return get_enum_index(s.data(), s.length()); }
int get_enum_index(const char *s, size_t length) const noexcept
Finds index of given string in attribute's range.

◆ get_enum_string()

const std::string * dunedaq::oks::OksAttribute::get_enum_string ( uint16_t idx) const
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.

Parameters
idxenumeration index
Returns
The method returns pointer on string corresponding to enumeration integer value.

Definition at line 461 of file attribute.hpp.

461{ return &(*p_enumerators)[idx]; }

◆ get_enum_value() [1/3]

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.

Parameters
sstring to find
lengthlength of string
Returns
The method returns pointer on internal enumerator data, if given string is defined in attribute's range.
Exceptions
std::exceptionis thrown, if no such string found.

Definition at line 136 of file attribute.cpp.

137{
139 for (unsigned int i = 0; i < p_enumerators->size(); ++i) {
140 const std::string* x = &((*p_enumerators)[i]);
141 if (x->length() == length) {
142 if (memcmp(s, x->data(), length) == 0) {
143 return x;
144 }
145 }
146 }
147
148 std::ostringstream text;
149 text << "value \'" << s << "\' is out of range \'" << get_range() << '\'';
150 throw std::runtime_error(text.str().c_str());
151 }
152
153 throw std::runtime_error("attribute is not enumeration");
154}
const std::string & get_range() const noexcept
Get attribute range.

◆ get_enum_value() [2/3]

uint16_t dunedaq::oks::OksAttribute::get_enum_value ( const OksData & d) const
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.

Parameters
dOKS data created for given attribute
Returns
The method returns integer value of given enumeration.

Definition at line 157 of file attribute.cpp.

158{
159 const std::string* p_enumerators_first(&((*p_enumerators)[0]));
160 return (d.data.ENUMERATION - p_enumerators_first);
161}

◆ get_enum_value() [3/3]

const std::string * dunedaq::oks::OksAttribute::get_enum_value ( const std::string & s) const
inline

See get_enum_value(const char *, size_t).

Definition at line 436 of file attribute.hpp.

436{ return get_enum_value(s.data(), s.length()); }
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...

◆ get_format()

Format dunedaq::oks::OksAttribute::get_format ( ) const
inlinenoexcept

Get attribute format.

The format meaning is described by the set_format() method.

Definition at line 285 of file attribute.hpp.

285{ return p_format; }

◆ get_init_value()

const std::string & dunedaq::oks::OksAttribute::get_init_value ( ) const
inlinenoexcept

The attribute initialisation value.

Definition at line 334 of file attribute.hpp.

334{ return p_init_value; }

◆ get_init_values()

std::list< std::string > dunedaq::oks::OksAttribute::get_init_values ( ) const

Return list of initial values for mv-attribute.

Exceptions
oks::AttributeReadErroris thrown if initial values became invalid (may happen for class_type attributes),

◆ get_is_multi_values()

bool dunedaq::oks::OksAttribute::get_is_multi_values ( ) const
inlinenoexcept

The method returns true, if the attribute is multi-values.

Definition at line 318 of file attribute.hpp.

318{ return p_multi_values; }

◆ get_is_no_null()

bool dunedaq::oks::OksAttribute::get_is_no_null ( ) const
inlinenoexcept

Return true, if the attribute's value cannot be equal to null.

Definition at line 372 of file attribute.hpp.

372{ return p_no_null; }

◆ get_name()

const std::string & dunedaq::oks::OksAttribute::get_name ( ) const
inlinenoexcept

out stream operator

Definition at line 165 of file attribute.hpp.

165{ return p_name; }

◆ get_range()

const std::string & dunedaq::oks::OksAttribute::get_range ( ) const
inlinenoexcept

Get attribute range.

The range meaning is described by the set_range() method.

Definition at line 222 of file attribute.hpp.

222{ return p_range; }

◆ get_type()

const std::string & dunedaq::oks::OksAttribute::get_type ( ) const
noexcept

Get attribute string type.

The type meaning is described by the set_type() method.

Definition at line 480 of file attribute.cpp.

481{
482 static std::string __types[] = {
483 "unknown", // unknown_type = 0
484 "s8", // s8_int_type = 1
485 "u8", // u8_int_type = 2
486 "s16", // s16_int_type = 3,
487 "u16", // u16_int_type = 4,
488 "s32", // s32_int_type = 5,
489 "u32", // u32_int_type = 6,
490 "s64", // s64_int_type = 7,
491 "u64", // u64_int_type = 8,
492 "float", // float_type = 9,
493 "double", // double_type = 10,
494 "bool", // bool_type = 11,
495 "class", // class_type = 12,
496 "object", // object_type = 13,
497 "date", // date_type = 14,
498 "time", // time_type = 15,
499 "string", // string_type = 16,
500 "list", // list_type = 17,
501 "uid", // uid_type = 18,
502 "uid2", // uid2_type = 19,
503 "enum" // enum_type = 20
504 };
505
506 return __types[(int)p_data_type];
507}

◆ init_enum()

void dunedaq::oks::OksAttribute::init_enum ( )
private

Definition at line 79 of file attribute.cpp.

80{
82 if (p_enumerators) {
83 p_enumerators->clear();
84 } else {
85 p_enumerators = new std::vector<std::string>();
86 }
87
88 Oks::Tokenizer t(p_range, ",");
89 std::string token;
90
91 while (t.next(token)) {
92 p_enumerators->push_back(token);
93 }
94
95 if (p_enumerators->empty()) {
96 std::ostringstream text;
97 text << "range of enumeration attribute \"" << p_name << "\" is empty";
98 throw std::runtime_error(text.str().c_str());
99 }
100 }
101}

◆ init_range()

void dunedaq::oks::OksAttribute::init_range ( )
private

Definition at line 104 of file attribute.cpp.

105{
106 clean_range();
107
108 if (p_range.empty() == false) {
109 p_range_obj = new OksRange(p_range, this);
110 if (p_range_obj->is_empty()) {
111 clean_range();
112 }
113 }
114}
OksRange(const std::string &range, OksAttribute *a)
Definition attribute.hpp:47

◆ is_integer()

bool dunedaq::oks::OksAttribute::is_integer ( ) const
noexcept

The method returns true, if the attribute is an integer number.

Definition at line 67 of file attribute.cpp.

◆ is_number()

bool dunedaq::oks::OksAttribute::is_number ( ) const
noexcept

The method returns true, if the attribute is a number.

Definition at line 73 of file attribute.cpp.

◆ operator==()

bool dunedaq::oks::OksAttribute::operator== ( const class OksAttribute & a) const

Definition at line 227 of file attribute.cpp.

228{
229 return ((this == &a) ||
230 ((p_name == a.p_name) && (p_range == a.p_range) && (p_data_type == a.p_data_type) &&
231 (p_multi_values == a.p_multi_values) && (p_init_value == a.p_init_value) &&
232 (p_description == a.p_description) && (p_no_null == a.p_no_null) && (p_ordered == a.p_ordered)));
233}

◆ save()

void dunedaq::oks::OksAttribute::save ( OksXmlOutputStream & s) const
private

Private method to save in XML stream

Definition at line 267 of file attribute.cpp.

268{
269 if (p_data_type == OksData::class_type && p_init_value.empty() && p_multi_values == false) {
270 std::ostringstream text;
271 text << "single-value attribute \"" << p_name << "\" is of \"class_type\" and has empty init value";
272 throw std::runtime_error(text.str().c_str());
273 }
274
276
277 s.put(" ");
278 s.put_start_tag(attribute_xml_tag, sizeof(attribute_xml_tag) - 1);
279
280 s.put_attribute(name_xml_attr, sizeof(name_xml_attr) - 1, p_name.c_str());
281
282 if (!p_description.empty())
283 s.put_attribute(description_xml_attr, sizeof(description_xml_attr) - 1, p_description.c_str());
284
285 s.put_attribute(type_xml_attr, sizeof(type_xml_attr) - 1, get_type().c_str());
286
287 if (!p_range.empty())
288 s.put_attribute(range_xml_attr, sizeof(range_xml_attr) - 1, p_range.c_str());
289
291 s.put_attribute(format_xml_attr, sizeof(format_xml_attr) - 1, format2str(p_format));
292
293 if (p_multi_values)
295
296 if (!p_init_value.empty())
297 s.put_attribute(init_value_xml_attr, sizeof(init_value_xml_attr) - 1, p_init_value.c_str());
298
299 if (p_no_null)
301
302 if (p_ordered)
303 s.put_attribute(ordered_xml_attr, sizeof(ordered_xml_attr) - 1, xml::bool2str(p_ordered));
304
305 s.put_end_tag();
306}
const std::string & get_type() const noexcept
Get attribute string type.
static const char * format2str(Format) noexcept
Definition attribute.cpp:61
static const char attribute_xml_tag[]
bool is_integer() const noexcept
Definition attribute.cpp:67
const char * bool2str(bool b) noexcept
Definition xml.hpp:29

◆ set_description()

void dunedaq::oks::OksAttribute::set_description ( const std::string & description)

Set attribute description.

Parameters
descriptionnew description of attribute (max 2000 bytes, see #s_max_description_length variable)
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 631 of file attribute.cpp.

632{
633 if (p_description != ds) {
634 if (p_class)
635 p_class->lock_file("OksAttribute::set_description");
636
637 p_description = ds;
638
639 if (p_class)
641 }
642}
void registrate_class_change(ChangeType, const void *, bool=true)
Definition class.cpp:2009
void lock_file(const char *)
Definition class.cpp:733

◆ set_format()

void dunedaq::oks::OksAttribute::set_format ( Format format)

Set attribute format.

There are 3 OKS formats for integer attributes:

  • dec or decimal (default),
  • oct or octal,
  • hex or hexadecimal. For other attributes the format does not make sense.

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:

Parameters
formatnew format
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 659 of file attribute.cpp.

660{
661 if (f != p_format) {
662 if (p_class)
663 p_class->lock_file("OksAttribute::set_format");
664
665 p_format = f;
666
667 if (p_class)
669 }
670}

◆ set_init_data()

void dunedaq::oks::OksAttribute::set_init_data ( )
inlineprivate

Definition at line 538 of file attribute.hpp.

539 {
540 p_init_data.set_init_value(this, false);
542 }
void set_init_value(const OksAttribute *attr, bool skip_init)
Set value defined by initial value of attribute.
Definition object.cpp:248

◆ set_init_value()

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.

Parameters
multi_valuesnew init value
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 608 of file attribute.cpp.

609{
610 if (p_init_value != init_v) {
611 std::string old_value = p_init_value;
612
613 if (p_class)
614 p_class->lock_file("OksAttribute::set_init_value");
615
616 p_init_value = init_v;
617
618 try {
620 } catch (...) {
621 p_init_value = old_value;
622 throw;
623 }
624
625 if (p_class)
627 }
628}

◆ set_is_multi_values()

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.

Parameters
multi_valuespass true to declare the value is multi-value
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 592 of file attribute.cpp.

593{
594 if (p_multi_values != is_mv) {
595 if (p_class)
596 p_class->lock_file("OksAttribute::set_is_multi_values");
597
598 p_multi_values = is_mv;
599
600 if (p_class) {
603 }
604 }
605}
void registrate_attribute_change(OksAttribute *)
Definition class.cpp:1804
@ ChangeAttributeMultiValueCardinality
Definition class.hpp:851

◆ set_is_no_null()

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.

Parameters
no_nullpass true to declare the value cannot be null
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 645 of file attribute.cpp.

646{
647 if (p_no_null != no_null) {
648 if (p_class)
649 p_class->lock_file("OksAttribute::set_is_no_null");
650
651 p_no_null = no_null;
652
653 if (p_class)
655 }
656}

◆ set_name()

void dunedaq::oks::OksAttribute::set_name ( const std::string & name)

Set attribute name.

Attributes linked with the same class shall have different names.

Parameters
namenew name of attribute (max 128 bytes, see #s_max_name_length variable)
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 544 of file attribute.cpp.

545{
546 // ignore when name is the same
547
548 if (p_name == new_name)
549 return;
550
551 // additional checks are required,
552 // if the attribute already belongs to some class
553
554 if (p_class) {
555 // check allowed length for attribute name
556
557 try {
558 validate_not_empty(new_name, "name");
559 } catch (std::exception& ex) {
560 throw SetOperationFailed("OksAttribute::set_name", ex.what());
561 }
562
563 // having a direct attribute with the same name is an error
564
565 if (p_class->find_direct_attribute(new_name) != 0) {
566 std::ostringstream text;
567 text << "Class \"" << p_class->get_name() << "\" already has direct attribute \"" << new_name << '\"';
568 throw SetOperationFailed("OksAttribute::set_name", text.str());
569 }
570
571 // check that the file can be updated
572
573 p_class->lock_file("OksAttribute::set_name");
574
575 // probably a non-direct attribute already exists
576
577 OksAttribute* a = p_class->find_attribute(new_name);
578
579 // change the name
580
581 p_name = new_name;
582
583 // registrate the change
584
586 } else {
587 p_name = new_name;
588 }
589}
OksAttribute(const std::string &name, OksClass *p=nullptr)
OKS attribute simple constructor.
OksAttribute * find_direct_attribute(const std::string &name) const noexcept
Find direct attribute.
Definition class.cpp:973
const std::string & get_name() const noexcept
Definition class.hpp:374
OksAttribute * find_attribute(const std::string &name) const noexcept
Find attribute (search in this and base classes).
Definition class.cpp:985
SetOperationFailed(const char *op, const exception &reason) noexcept
Definition class.hpp:149

◆ set_range()

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:

  • A
  • B
  • greater or equal to C and less or equal to D
  • less or equal to F
  • greater or equal to G

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:

  • boolean attributes have predefined range "true,false"
  • enumeration attributes shall have non-empty range
Parameters
rangenew range (max 1024 bytes, see #s_max_range_length variable)
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 673 of file attribute.cpp.

674{
675 if (s != p_range) {
676 std::string old_value = p_range;
677
678 if (p_class)
679 p_class->lock_file("OksAttribute::set_range");
680
681 p_range.erase();
682 int count = 0;
683 Oks::Tokenizer t(s, ", \t");
684 std::string token;
685
686 while (t.next(token)) {
687 if (count++ != 0) {
688 p_range += ',';
689 }
690
691 p_range += token;
692 }
693
694 if (count != 0) {
696 p_range.erase();
697 throw SetOperationFailed("OksAttribute::set_range", "boolean type can't have user-defined range!");
698 }
699 }
700
701 try {
702 init_enum();
703 init_range();
705 } catch (std::exception& ex) {
706 p_range = old_value;
707
708 try {
709 init_enum();
710 } catch (...) {
711 ;
712 }
713
714 try {
715 init_range();
716 } catch (...) {
717 ;
718 }
719
720 throw SetOperationFailed("OksAttribute::set_range", ex.what());
721 }
722
723 if (p_class)
725 }
726}

◆ set_type()

void dunedaq::oks::OksAttribute::set_type ( const std::string & type,
bool skip_init = false )

Set attribute type.

The valid attribute types are:

  • "bool" - boolean
  • "s8" - signed 8-bits integer number
  • "u8" - unsigned 8-bits integer number
  • "s16" - signed 16-bits integer number
  • "u16" - unsigned 16-bits integer number
  • "s32" - signed 32-bits integer number
  • "u32" - unsigned 32-bits integer number
  • "s64" - signed 64-bits integer number
  • "u64" - unsigned 64-bits integer number
  • "float" - floating-point number
  • "double" - double precision floating-point number
  • "date" - date type
  • "time" - time type
  • "string" - string
  • "enum" - enumeration
  • "class" - reference on OKS class
Parameters
typenew type
skip_initif true, do not initialise enum and range
Exceptions
oks::exceptionis thrown in case of problems.

Definition at line 510 of file attribute.cpp.

511{
513
514 if (p_dt == OksData::unknown_type) {
515 std::ostringstream text;
516 text << "the type \'" << t << "\' is not valid";
517 throw SetOperationFailed("OksAttribute::set_type", text.str());
518 }
519
520 if (p_data_type == p_dt)
521 return;
522
523 if (p_class)
524 p_class->lock_file("OksAttribute::set_type");
525
526 p_data_type = p_dt;
527
528 if (skip_init == false) {
529 try {
530 init_enum();
531 init_range();
532 } catch (std::exception& ex) {
533 throw SetOperationFailed("OksAttribute::set_type", ex.what());
534 }
535 }
536
537 if (p_class) {
540 }
541}

◆ str2format()

OksAttribute::Format dunedaq::oks::OksAttribute::str2format ( const char * s)
staticnoexcept

Definition at line 55 of file attribute.cpp.

56{
57 return (cmp_str3(s, "dec") ? Dec : cmp_str3(s, "hex") ? Hex : Oct);
58}
bool cmp_str3(const char *s1, const char s2[4])
Definition cstring.hpp:33

◆ OksClass

friend class OksClass
friend

Definition at line 96 of file attribute.hpp.

◆ OksData

friend struct OksData
friend

Definition at line 99 of file attribute.hpp.

◆ OksIndex

friend class OksIndex
friend

Definition at line 97 of file attribute.hpp.

◆ OksKernel

friend class OksKernel
friend

Definition at line 95 of file attribute.hpp.

◆ OksObject

friend class OksObject
friend

Definition at line 98 of file attribute.hpp.

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const OksAttribute & a )
friend

equality operator

Definition at line 235 of file attribute.cpp.

237{
238 s << "Attribute name: \"" << a.p_name
239 << "\"\n"
240 " type: \""
241 << a.get_type()
242 << "\"\n"
243 " range: \""
244 << a.p_range << "\"\n";
245
246 if (a.is_integer()) {
247 s << " format: \"" << OksAttribute::format2str(a.p_format) << "\"\n";
248 }
249
250 if (a.p_multi_values == true) {
251 s << " is \'multi values\'\n";
252 } else {
253 s << " is \'single value\'\n";
254 }
255
256 s << " initial value: \"" << a.p_init_value
257 << "\"\n"
258 " has description: \""
259 << a.p_description << "\"\n"
260 << (a.p_no_null == true ? " can not be null\n" : " can be null\n") << " is "
261 << (a.p_ordered == true ? "ordered" : "unordered") << std::endl;
262
263 return s;
264}

Member Data Documentation

◆ attribute_xml_tag

const char dunedaq::oks::OksAttribute::attribute_xml_tag = "attribute"
staticprivate

Valid xml tags and attributes

Definition at line 548 of file attribute.hpp.

◆ bool_type

const char * dunedaq::oks::OksAttribute::bool_type = "bool"
static

Valid attribute types

Definition at line 467 of file attribute.hpp.

◆ class_type

const char * dunedaq::oks::OksAttribute::class_type = "class"
static

Definition at line 483 of file attribute.hpp.

◆ date_type

const char * dunedaq::oks::OksAttribute::date_type = "date"
static

Definition at line 478 of file attribute.hpp.

◆ description_xml_attr

const char dunedaq::oks::OksAttribute::description_xml_attr = "description"
staticprivate

Definition at line 550 of file attribute.hpp.

◆ double_type

const char * dunedaq::oks::OksAttribute::double_type = "double"
static

Definition at line 477 of file attribute.hpp.

◆ enum_type

const char * dunedaq::oks::OksAttribute::enum_type = "enum"
static

Definition at line 482 of file attribute.hpp.

◆ float_type

const char * dunedaq::oks::OksAttribute::float_type = "float"
static

Definition at line 476 of file attribute.hpp.

◆ format_xml_attr

const char dunedaq::oks::OksAttribute::format_xml_attr = "format"
staticprivate

Definition at line 552 of file attribute.hpp.

◆ init_value_xml_attr

const char dunedaq::oks::OksAttribute::init_value_xml_attr = "init-value"
staticprivate

Definition at line 556 of file attribute.hpp.

◆ is_multi_value_xml_attr

const char dunedaq::oks::OksAttribute::is_multi_value_xml_attr = "is-multi-value"
staticprivate

Definition at line 554 of file attribute.hpp.

◆ is_not_null_xml_attr

const char dunedaq::oks::OksAttribute::is_not_null_xml_attr = "is-not-null"
staticprivate

Definition at line 557 of file attribute.hpp.

◆ mv_implement_xml_attr

const char dunedaq::oks::OksAttribute::mv_implement_xml_attr[]
staticprivate

Definition at line 555 of file attribute.hpp.

◆ name_xml_attr

const char dunedaq::oks::OksAttribute::name_xml_attr = "name"
staticprivate

Definition at line 549 of file attribute.hpp.

◆ ordered_xml_attr

const char dunedaq::oks::OksAttribute::ordered_xml_attr = "ordered"
staticprivate

Definition at line 558 of file attribute.hpp.

◆ p_class

OksClass* dunedaq::oks::OksAttribute::p_class
private

Definition at line 497 of file attribute.hpp.

◆ p_data_type

OksData::Type dunedaq::oks::OksAttribute::p_data_type
private

Definition at line 491 of file attribute.hpp.

◆ p_description

std::string dunedaq::oks::OksAttribute::p_description
private

Definition at line 496 of file attribute.hpp.

◆ p_empty_init_data

OksData dunedaq::oks::OksAttribute::p_empty_init_data
private

Definition at line 501 of file attribute.hpp.

◆ p_enumerators

std::vector<std::string>* dunedaq::oks::OksAttribute::p_enumerators
private

Definition at line 498 of file attribute.hpp.

◆ p_format

Format dunedaq::oks::OksAttribute::p_format
private

Definition at line 495 of file attribute.hpp.

◆ p_init_data

OksData dunedaq::oks::OksAttribute::p_init_data
private

Definition at line 500 of file attribute.hpp.

◆ p_init_value

std::string dunedaq::oks::OksAttribute::p_init_value
private

Definition at line 494 of file attribute.hpp.

◆ p_multi_values

bool dunedaq::oks::OksAttribute::p_multi_values
private

Definition at line 492 of file attribute.hpp.

◆ p_name

std::string dunedaq::oks::OksAttribute::p_name
private

Definition at line 489 of file attribute.hpp.

◆ p_no_null

bool dunedaq::oks::OksAttribute::p_no_null
private

Definition at line 493 of file attribute.hpp.

◆ p_ordered

bool dunedaq::oks::OksAttribute::p_ordered
private

Definition at line 502 of file attribute.hpp.

◆ p_range

std::string dunedaq::oks::OksAttribute::p_range
private

Definition at line 490 of file attribute.hpp.

◆ p_range_obj

OksRange* dunedaq::oks::OksAttribute::p_range_obj
private

Definition at line 499 of file attribute.hpp.

◆ range_xml_attr

const char dunedaq::oks::OksAttribute::range_xml_attr = "range"
staticprivate

Definition at line 553 of file attribute.hpp.

◆ s16_int_type

const char * dunedaq::oks::OksAttribute::s16_int_type = "s16"
static

Definition at line 470 of file attribute.hpp.

◆ s32_int_type

const char * dunedaq::oks::OksAttribute::s32_int_type = "s32"
static

Definition at line 472 of file attribute.hpp.

◆ s64_int_type

const char * dunedaq::oks::OksAttribute::s64_int_type = "s64"
static

Definition at line 474 of file attribute.hpp.

◆ s8_int_type

const char * dunedaq::oks::OksAttribute::s8_int_type = "s8"
static

Definition at line 468 of file attribute.hpp.

◆ string_type

const char * dunedaq::oks::OksAttribute::string_type = "string"
static

Definition at line 480 of file attribute.hpp.

◆ time_type

const char * dunedaq::oks::OksAttribute::time_type = "time"
static

Definition at line 479 of file attribute.hpp.

◆ type_xml_attr

const char dunedaq::oks::OksAttribute::type_xml_attr = "type"
staticprivate

Definition at line 551 of file attribute.hpp.

◆ u16_int_type

const char * dunedaq::oks::OksAttribute::u16_int_type = "u16"
static

Definition at line 471 of file attribute.hpp.

◆ u32_int_type

const char * dunedaq::oks::OksAttribute::u32_int_type = "u32"
static

Definition at line 473 of file attribute.hpp.

◆ u64_int_type

const char * dunedaq::oks::OksAttribute::u64_int_type = "u64"
static

Definition at line 475 of file attribute.hpp.

◆ u8_int_type

const char * dunedaq::oks::OksAttribute::u8_int_type = "u8"
static

Definition at line 469 of file attribute.hpp.

◆ uid_type

const char * dunedaq::oks::OksAttribute::uid_type = "uid"
static

Definition at line 481 of file attribute.hpp.


The documentation for this class was generated from the following files: