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
 
OksClassp_class
 
std::vector< std::string > * p_enumerators
 
OksRangep_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 101 of file attribute.hpp.

Member Enumeration Documentation

◆ Format

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

Enumerator
Oct 
Dec 
Hex 

Definition at line 113 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 206 of file attribute.cpp.

206 :
207 p_name (nm),
209 p_multi_values (false),
210 p_no_null (false),
212 p_class (p),
213 p_enumerators (nullptr),
214 p_range_obj (nullptr),
215 p_ordered (false)
216
217{
218 validate_not_empty(p_name, "attribute name");
219}
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 222 of file attribute.cpp.

224 :
225 p_name (nm),
226 p_range (r),
228 p_multi_values (is_mv),
229 p_no_null (no_null),
230 p_init_value (init_v),
231 p_format (f),
232 p_description (ds),
233 p_class (p),
234 p_enumerators (nullptr),
235 p_range_obj (nullptr),
236 p_ordered (false)
237{
238 set_type(t, true);
239 validate_not_empty(p_name, "attribute name");
240 init_enum();
241 init_range();
242 // cannot call set_init_data() because of the CLASS data type, since other class may not be known yet;
243 // initialize the init_data in the register_all_classes() call
244}
void set_type(const std::string &type, bool skip_init=false)
Set attribute type.
OksData::Type get_data_type() const noexcept

◆ ~OksAttribute()

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

Definition at line 157 of file attribute.hpp.

158 {
159 if (p_enumerators)
160 delete p_enumerators;
161
162 clean_range();
163 }

◆ OksAttribute() [3/4]

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

Private constructor used by OksData

Definition at line 606 of file attribute.hpp.

606 :
607 p_data_type(t), p_class(const_cast<OksClass*>(c)), p_enumerators(nullptr), p_range_obj(nullptr), p_ordered(false)
608 {
609 ;
610 }

◆ OksAttribute() [4/4]

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

Private constructor from XML stream

Definition at line 335 of file attribute.cpp.

335 :
337 p_multi_values (false),
338 p_no_null (false),
340 p_class (parent),
341 p_enumerators (nullptr),
342 p_range_obj (nullptr),
343 p_ordered (false)
344{
345 // read attributes of OksAttribute from xml
346
347 try
348 {
349 while (true)
350 {
351 OksXmlAttribute attr(s);
352
353 // check for close of tag
354
355 if (cmp_str1(attr.name(), "/"))
356 {
357 break;
358 }
359
360 // check for known oks-attribute' attributes
361
362 else if (cmp_str4(attr.name(), name_xml_attr))
363 p_name.assign(attr.value(), attr.value_len());
364 else if (cmp_str11(attr.name(), description_xml_attr))
365 p_description.assign(attr.value(), attr.value_len());
366 else if (cmp_str4(attr.name(), type_xml_attr))
367 {
368 __set_data_type(attr.value(), attr.value_len());
370 {
371 throw BadFileData(std::string("Value \'") + attr.value() + "\' is not a valid attribute type", s.get_line_no(), s.get_line_pos());
372 }
373 }
374 else if (cmp_str5(attr.name(), range_xml_attr))
375 p_range.assign(attr.value(), attr.value_len());
376 else if (cmp_str6(attr.name(), format_xml_attr))
377 p_format = str2format(attr.value());
378 else if (cmp_str14(attr.name(), is_multi_value_xml_attr))
379 p_multi_values = xml::str2bool(attr.value());
380 else if (cmp_str10(attr.name(), init_value_xml_attr))
381 p_init_value.assign(attr.value(), attr.value_len());
382 else if (cmp_str11(attr.name(), is_not_null_xml_attr))
383 p_no_null = xml::str2bool(attr.value());
384 else if (cmp_str7(attr.name(), ordered_xml_attr))
385 p_ordered = xml::str2bool(attr.value());
386 else if (!strcmp(attr.name(), "multi-value-implementation"))
387 s.error_msg("OksAttribute::OksAttribute(OksXmlInputStream&)") << "Obsolete oks-attribute\'s attribute \'" << attr.name() << "\'\n";
388 else
389 s.throw_unexpected_attribute(attr.name());
390 }
391 }
392 catch (exception & e)
393 {
394 throw FailedRead("xml attribute", e);
395 }
396 catch (std::exception & e)
397 {
398 throw FailedRead("xml attribute", e.what());
399 }
400
401 // check validity of read values
402
404 {
405 throw FailedRead("oks attribute", BadFileData("attribute type is not set", s.get_line_no(), s.get_line_pos()));
406 }
407
408 try
409 {
410 validate_not_empty(p_name, "attribute name");
411 init_enum();
412 init_range();
413 }
414 catch (std::exception& ex)
415 {
416 throw FailedRead("oks attribute", BadFileData(ex.what(), s.get_line_no(), s.get_line_pos()));
417 }
418
419 if (p_init_value.empty())
420 {
422 {
423 std::ostringstream text;
424 text << "single-value attribute \"" << p_name << "\" is of \"class_type\" and has empty init value";
425 throw FailedRead("oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
426 }
427 }
428 else
429 {
431 {
432 try
433 {
434 OksData _d;
435 if (p_multi_values)
436 {
437 _d.SetValues(p_init_value.c_str(), this);
438 }
439 else
440 {
441 _d.type = p_data_type;
442 _d.SetValue(p_init_value.c_str(), 0);
443 }
444 }
445 catch (exception& ex)
446 {
447 std::ostringstream text;
448 text << "attribute \"" << p_name << "\" has bad init value:\n" << ex.what();
449 throw FailedRead("oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
450 }
451 }
452 }
453
454 try
455 {
457 }
458 catch (std::exception& ex)
459 {
460 std::ostringstream text;
461 text << "attribute \"" << p_name << "\" has mismatch between init value and range:\n" << ex.what();
462 throw FailedRead("oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
463 }
464
465// set_init_data();
466}
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:52
static const char type_xml_attr[]
static const char range_xml_attr[]
caught dunedaq::conffwk::Exception exception
bool str2bool(const char *s) noexcept
Definition xml.hpp:26
bool cmp_str1(const char *s1, const char s2[2])
Definition cstring.hpp:9
bool cmp_str4(const char *s1, const char s2[5])
Definition cstring.hpp:29
bool cmp_str6(const char *s1, const char s2[7])
Definition cstring.hpp:45
bool cmp_str10(const char *s1, const char s2[11])
Definition cstring.hpp:73
void validate_init2range(const OksAttribute *a)
bool cmp_str5(const char *s1, const char s2[6])
Definition cstring.hpp:37
bool cmp_str11(const char *s1, const char s2[12])
Definition cstring.hpp:77
bool cmp_str14(const char *s1, const char s2[14])
Definition cstring.hpp:89
bool cmp_str7(const char *s1, const char s2[8])
Definition cstring.hpp:53

Member Function Documentation

◆ __set_data_type()

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

Definition at line 665 of file attribute.hpp.

666{
667 p_data_type = get_data_type(t, len);
668}

◆ clean_range()

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

Definition at line 630 of file attribute.hpp.

631 {
632 if (p_range_obj)
633 {
634 delete p_range_obj;
635 p_range_obj = nullptr;
636 }
637 }

◆ 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 805 of file attribute.cpp.

806{
807 const char * p;
808
809 if (token && (p = strstr(range, token)) != 0)
810 {
811 int len = strlen(token);
812
813 do
814 {
815 if (((p != range) && (p[-1] != ',')) || ((p[len] != ',') && (p[len] != '\0')))
816 {
817 p = strstr(p + 1, token);
818 }
819 else
820 {
821 return true;
822 }
823
824 }
825 while (p != 0);
826 }
827
828 return false;
829}
DAC value out of range
Message.
Definition DACNode.hpp:32

◆ format2str()

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

Definition at line 62 of file attribute.cpp.

63{
64 return (
65 f == Dec ? "dec" :
66 f == Hex ? "hex" :
67 "oct"
68 );
69}

◆ get_data_type() [1/3]

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

Get attribute OKS data type.

Definition at line 304 of file attribute.hpp.

305 {
306 return p_data_type;
307 }

◆ 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 477 of file attribute.cpp.

478{
479 switch(len) {
480 case 3:
481 if ( cmp_str3n (t, uid_type) ) return OksData::uid2_type; // "uid"
482 else if( cmp_str3n (t, u32_int_type) ) return OksData::u32_int_type; // "u32"
483 else if( cmp_str3n (t, s32_int_type) ) return OksData::s32_int_type; // "s32"
484 else if( cmp_str3n (t, u16_int_type) ) return OksData::u16_int_type; // "u16"
485 else if( cmp_str3n (t, s16_int_type) ) return OksData::s16_int_type; // "s16"
486 else if( cmp_str3n (t, s64_int_type) ) return OksData::s64_int_type; // "s64"
487 else if( cmp_str3n (t, u64_int_type) ) return OksData::u64_int_type; // "u64"
488 break;
489
490 case 6:
491 if( cmp_str6n (t, string_type) ) return OksData::string_type; // "string"
492 else if( cmp_str6n (t, double_type) ) return OksData::double_type; // "double"
493 break;
494
495 case 4:
496 if( cmp_str4n (t, bool_type) ) return OksData::bool_type; // "bool"
497 else if( cmp_str4n (t, enum_type) ) return OksData::enum_type; // "enum"
498 else if( cmp_str4n (t, date_type) ) return OksData::date_type; // "date"
499 else if( cmp_str4n (t, time_type) ) return OksData::time_type; // "time"
500 break;
501
502 case 5:
503 if( cmp_str5n (t, float_type) ) return OksData::float_type; // "float"
504 else if( cmp_str5n (t, class_type) ) return OksData::class_type; // "class"
505 break;
506
507 case 2:
508 if( cmp_str2n (t, s8_int_type) ) return OksData::s8_int_type; // "s8"
509 else if( cmp_str2n (t, u8_int_type) ) return OksData::u8_int_type; // "u8"
510 break;
511 }
512
514}
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:17
bool cmp_str5n(const char *s1, const char s2[5])
Definition cstring.hpp:41
bool cmp_str3n(const char *s1, const char s2[3])
Definition cstring.hpp:25
bool cmp_str6n(const char *s1, const char s2[6])
Definition cstring.hpp:49
bool cmp_str4n(const char *s1, const char s2[4])
Definition cstring.hpp:33

◆ 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 470 of file attribute.cpp.

471{
472 return get_data_type(t.c_str(), t.size());
473}

◆ get_description()

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

Return description of attribute

Definition at line 417 of file attribute.hpp.

418 {
419 return p_description;
420 }

◆ 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 131 of file attribute.cpp.

132{
134 {
135 for (int i = 0; i < (int) p_enumerators->size(); ++i)
136 {
137 const std::string * x = &((*p_enumerators)[i]);
138 if (x->length() == length)
139 {
140 if (memcmp(s, x->data(), length) == 0)
141 {
142 return i;
143 }
144 }
145 }
146
147 return (-1);
148 }
149
150 return (-2);
151}

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

491 {
492 return get_enum_index(s.data(), s.length());
493 }
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 551 of file attribute.hpp.

552 {
553 return &(*p_enumerators)[idx];
554 }

◆ 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 154 of file attribute.cpp.

155{
157 {
158 for (unsigned int i = 0; i < p_enumerators->size(); ++i)
159 {
160 const std::string * x = &((*p_enumerators)[i]);
161 if (x->length() == length)
162 {
163 if (memcmp(s, x->data(), length) == 0)
164 {
165 return x;
166 }
167 }
168 }
169
170 std::ostringstream text;
171 text << "value \'" << s << "\' is out of range \'" << get_range() << '\'';
172 throw std::runtime_error(text.str().c_str());
173 }
174
175 throw std::runtime_error("attribute is not enumeration");
176}
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 179 of file attribute.cpp.

180{
181 const std::string * p_enumerators_first(&((*p_enumerators)[0]));
182 return (d.data.ENUMERATION - p_enumerators_first);
183}

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

520 {
521 return get_enum_value(s.data(), s.length());
522 }
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 317 of file attribute.hpp.

318 {
319 return p_format;
320 }

◆ get_init_value()

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

The attribute initialisation value.

Definition at line 384 of file attribute.hpp.

385 {
386 return p_init_value;
387 }

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

362 {
363 return p_multi_values;
364 }

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

439 {
440 return p_no_null;
441 }

◆ get_name()

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

out stream operator

Definition at line 170 of file attribute.hpp.

171 {
172 return p_name;
173 }

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

239 {
240 return p_range;
241 }

◆ 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 518 of file attribute.cpp.

519{
520 static std::string __types [] = {
521 "unknown", // unknown_type = 0
522 "s8", // s8_int_type = 1
523 "u8", // u8_int_type = 2
524 "s16", // s16_int_type = 3,
525 "u16", // u16_int_type = 4,
526 "s32", // s32_int_type = 5,
527 "u32", // u32_int_type = 6,
528 "s64", // s64_int_type = 7,
529 "u64", // u64_int_type = 8,
530 "float", // float_type = 9,
531 "double", // double_type = 10,
532 "bool", // bool_type = 11,
533 "class", // class_type = 12,
534 "object", // object_type = 13,
535 "date", // date_type = 14,
536 "time", // time_type = 15,
537 "string", // string_type = 16,
538 "list", // list_type = 17,
539 "uid", // uid_type = 18,
540 "uid2", // uid2_type = 19,
541 "enum" // enum_type = 20
542 };
543
544 return __types[(int)p_data_type];
545}

◆ init_enum()

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

Definition at line 84 of file attribute.cpp.

85{
87 {
88 if (p_enumerators)
89 {
90 p_enumerators->clear();
91 }
92 else
93 {
94 p_enumerators = new std::vector<std::string>();
95 }
96
97 Oks::Tokenizer t(p_range, ",");
98 std::string token;
99
100 while (t.next(token))
101 {
102 p_enumerators->push_back(token);
103 }
104
105 if (p_enumerators->empty())
106 {
107 std::ostringstream text;
108 text << "range of enumeration attribute \"" << p_name << "\" is empty";
109 throw std::runtime_error(text.str().c_str());
110 }
111 }
112}

◆ init_range()

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

Definition at line 115 of file attribute.cpp.

116{
117 clean_range();
118
119 if (p_range.empty() == false)
120 {
121 p_range_obj = new OksRange(p_range, this);
122 if (p_range_obj->is_empty())
123 {
124 clean_range();
125 }
126 }
127}

◆ is_integer()

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

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

Definition at line 72 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 78 of file attribute.cpp.

◆ operator==()

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

Definition at line 247 of file attribute.cpp.

248{
249 return (
250 ( this == &a ) ||
251 (
252 ( p_name == a.p_name ) &&
253 ( p_range == a.p_range ) &&
254 ( p_data_type == a.p_data_type ) &&
255 ( p_multi_values == a.p_multi_values ) &&
256 ( p_init_value == a.p_init_value ) &&
257 ( p_description == a.p_description ) &&
258 ( p_no_null == a.p_no_null ) &&
259 ( p_ordered == a.p_ordered )
260 )
261 );
262}

◆ save()

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

Private method to save in XML stream

Definition at line 292 of file attribute.cpp.

293{
294 if (p_data_type == OksData::class_type && p_init_value.empty() && p_multi_values == false)
295 {
296 std::ostringstream text;
297 text << "single-value attribute \"" << p_name << "\" is of \"class_type\" and has empty init value";
298 throw std::runtime_error(text.str().c_str());
299 }
300
302
303 s.put(" ");
304 s.put_start_tag(attribute_xml_tag, sizeof(attribute_xml_tag) - 1);
305
306 s.put_attribute(name_xml_attr, sizeof(name_xml_attr) - 1, p_name.c_str());
307
308 if (!p_description.empty())
309 s.put_attribute(description_xml_attr, sizeof(description_xml_attr) - 1, p_description.c_str());
310
311 s.put_attribute(type_xml_attr, sizeof(type_xml_attr) - 1, get_type().c_str());
312
313 if (!p_range.empty())
314 s.put_attribute(range_xml_attr, sizeof(range_xml_attr) - 1, p_range.c_str());
315
317 s.put_attribute(format_xml_attr, sizeof(format_xml_attr) - 1, format2str(p_format));
318
319 if (p_multi_values)
321
322 if (!p_init_value.empty())
323 s.put_attribute(init_value_xml_attr, sizeof(init_value_xml_attr) - 1, p_init_value.c_str());
324
325 if (p_no_null)
327
328 if (p_ordered)
329 s.put_attribute(ordered_xml_attr, sizeof(ordered_xml_attr) - 1, xml::bool2str(p_ordered));
330
331 s.put_end_tag();
332}
const std::string & get_type() const noexcept
Get attribute string type.
static const char * format2str(Format) noexcept
Definition attribute.cpp:62
static const char attribute_xml_tag[]
bool is_integer() const noexcept
Definition attribute.cpp:72
const char * bool2str(bool b) noexcept
Definition xml.hpp:23

◆ 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 689 of file attribute.cpp.

690{
691 if (p_description != ds)
692 {
693 if (p_class)
694 p_class->lock_file("OksAttribute::set_description");
695
696 p_description = ds;
697
698 if (p_class)
700 }
701}
void registrate_class_change(ChangeType, const void *, bool=true)
Definition class.cpp:2035
void lock_file(const char *)
Definition class.cpp:766

◆ 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 720 of file attribute.cpp.

721{
722 if (f != p_format)
723 {
724 if (p_class)
725 p_class->lock_file("OksAttribute::set_format");
726
727 p_format = f;
728
729 if (p_class)
731 }
732}

◆ set_init_data()

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

Definition at line 640 of file attribute.hpp.

641 {
642 p_init_data.set_init_value(this, false);
644 }
void set_init_value(const OksAttribute *attr, bool skip_init)
Set value defined by initial value of attribute.
Definition object.cpp:242

◆ 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 662 of file attribute.cpp.

663{
664 if (p_init_value != init_v)
665 {
666 std::string old_value = p_init_value;
667
668 if (p_class)
669 p_class->lock_file("OksAttribute::set_init_value");
670
671 p_init_value = init_v;
672
673 try
674 {
676 }
677 catch (...)
678 {
679 p_init_value = old_value;
680 throw;
681 }
682
683 if (p_class)
685 }
686}

◆ 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 644 of file attribute.cpp.

645{
646 if (p_multi_values != is_mv)
647 {
648 if (p_class)
649 p_class->lock_file("OksAttribute::set_is_multi_values");
650
651 p_multi_values = is_mv;
652
653 if (p_class)
654 {
657 }
658 }
659}
void registrate_attribute_change(OksAttribute *)
Definition class.cpp:1829
@ ChangeAttributeMultiValueCardinality
Definition class.hpp:900

◆ 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 705 of file attribute.cpp.

706{
707 if (p_no_null != no_null)
708 {
709 if (p_class)
710 p_class->lock_file("OksAttribute::set_is_no_null");
711
712 p_no_null = no_null;
713
714 if (p_class)
716 }
717}

◆ 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 589 of file attribute.cpp.

590{
591 // ignore when name is the same
592
593 if (p_name == new_name)
594 return;
595
596 // additional checks are required,
597 // if the attribute already belongs to some class
598
599 if (p_class)
600 {
601 // check allowed length for attribute name
602
603 try
604 {
605 validate_not_empty(new_name, "name");
606 }
607 catch (std::exception& ex)
608 {
609 throw SetOperationFailed("OksAttribute::set_name", ex.what());
610 }
611
612 // having a direct attribute with the same name is an error
613
614 if (p_class->find_direct_attribute(new_name) != 0)
615 {
616 std::ostringstream text;
617 text << "Class \"" << p_class->get_name() << "\" already has direct attribute \"" << new_name << '\"';
618 throw SetOperationFailed("OksAttribute::set_name", text.str());
619 }
620
621 // check that the file can be updated
622
623 p_class->lock_file("OksAttribute::set_name");
624
625 // probably a non-direct attribute already exists
626
627 OksAttribute * a = p_class->find_attribute(new_name);
628
629 // change the name
630
631 p_name = new_name;
632
633 // registrate the change
634
636 }
637 else
638 {
639 p_name = new_name;
640 }
641}
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:1014
const std::string & get_name() const noexcept
Definition class.hpp:363
OksAttribute * find_attribute(const std::string &name) const noexcept
Find attribute (search in this and base classes).
Definition class.cpp:1026

◆ 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 735 of file attribute.cpp.

736{
737 if (s != p_range)
738 {
739 std::string old_value = p_range;
740
741 if (p_class)
742 p_class->lock_file("OksAttribute::set_range");
743
744 p_range.erase();
745 int count = 0;
746 Oks::Tokenizer t(s, ", \t");
747 std::string token;
748
749 while (t.next(token))
750 {
751 if (count++ != 0)
752 {
753 p_range += ',';
754 }
755
756 p_range += token;
757 }
758
759 if (count != 0)
760 {
762 {
763 p_range.erase();
764 throw SetOperationFailed("OksAttribute::set_range", "boolean type can't have user-defined range!");
765 }
766 }
767
768 try
769 {
770 init_enum();
771 init_range();
773 }
774 catch (std::exception& ex)
775 {
776 p_range = old_value;
777
778 try
779 {
780 init_enum();
781 }
782 catch (...)
783 {
784 ;
785 }
786
787 try
788 {
789 init_range();
790 }
791 catch (...)
792 {
793 ;
794 }
795
796 throw SetOperationFailed("OksAttribute::set_range", ex.what());
797 }
798
799 if (p_class)
801 }
802}

◆ 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 549 of file attribute.cpp.

550{
552
553 if (p_dt == OksData::unknown_type)
554 {
555 std::ostringstream text;
556 text << "the type \'" << t << "\' is not valid";
557 throw SetOperationFailed("OksAttribute::set_type", text.str());
558 }
559
560 if (p_data_type == p_dt)
561 return;
562
563 if (p_class)
564 p_class->lock_file("OksAttribute::set_type");
565
566 p_data_type = p_dt;
567
568 if (skip_init == false)
569 {
570 try
571 {
572 init_enum();
573 init_range();
574 }
575 catch (std::exception& ex)
576 {
577 throw SetOperationFailed("OksAttribute::set_type", ex.what());
578 }
579 }
580
581 if (p_class)
582 {
585 }
586}

◆ str2format()

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

Definition at line 52 of file attribute.cpp.

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

Friends And Related Symbol Documentation

◆ OksClass

friend class OksClass
friend

Definition at line 104 of file attribute.hpp.

◆ OksData

friend struct OksData
friend

Definition at line 107 of file attribute.hpp.

◆ OksIndex

friend class OksIndex
friend

Definition at line 105 of file attribute.hpp.

◆ OksKernel

friend class OksKernel
friend

Definition at line 103 of file attribute.hpp.

◆ OksObject

friend class OksObject
friend

Definition at line 106 of file attribute.hpp.

◆ operator<<

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

equality operator

Definition at line 264 of file attribute.cpp.

266{
267 s << "Attribute name: \"" << a.p_name << "\"\n"
268 " type: \"" << a.get_type() << "\"\n"
269 " range: \"" << a.p_range << "\"\n";
270
271 if(a.is_integer()) {
272 s << " format: \"" << OksAttribute::format2str(a.p_format) << "\"\n";
273 }
274
275 if(a.p_multi_values == true) {
276 s << " is \'multi values\'\n";
277 }
278 else {
279 s << " is \'single value\'\n";
280 }
281
282 s << " initial value: \"" << a.p_init_value << "\"\n"
283 " has description: \"" << a.p_description << "\"\n"
284 << (a.p_no_null == true ? " can not be null\n" : " can be null\n")
285 << " is " << (a.p_ordered == true ? "ordered" : "unordered") << std::endl;
286
287 return s;
288}

Member Data Documentation

◆ attribute_xml_tag

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

Valid xml tags and attributes

Definition at line 650 of file attribute.hpp.

◆ bool_type

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

Valid attribute types

Definition at line 561 of file attribute.hpp.

◆ class_type

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

Definition at line 577 of file attribute.hpp.

◆ date_type

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

Definition at line 572 of file attribute.hpp.

◆ description_xml_attr

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

Definition at line 652 of file attribute.hpp.

◆ double_type

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

Definition at line 571 of file attribute.hpp.

◆ enum_type

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

Definition at line 576 of file attribute.hpp.

◆ float_type

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

Definition at line 570 of file attribute.hpp.

◆ format_xml_attr

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

Definition at line 654 of file attribute.hpp.

◆ init_value_xml_attr

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

Definition at line 658 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 656 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 659 of file attribute.hpp.

◆ mv_implement_xml_attr

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

Definition at line 657 of file attribute.hpp.

◆ name_xml_attr

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

Definition at line 651 of file attribute.hpp.

◆ ordered_xml_attr

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

Definition at line 660 of file attribute.hpp.

◆ p_class

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

Definition at line 594 of file attribute.hpp.

◆ p_data_type

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

Definition at line 588 of file attribute.hpp.

◆ p_description

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

Definition at line 593 of file attribute.hpp.

◆ p_empty_init_data

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

Definition at line 598 of file attribute.hpp.

◆ p_enumerators

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

Definition at line 595 of file attribute.hpp.

◆ p_format

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

Definition at line 592 of file attribute.hpp.

◆ p_init_data

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

Definition at line 597 of file attribute.hpp.

◆ p_init_value

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

Definition at line 591 of file attribute.hpp.

◆ p_multi_values

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

Definition at line 589 of file attribute.hpp.

◆ p_name

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

Definition at line 586 of file attribute.hpp.

◆ p_no_null

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

Definition at line 590 of file attribute.hpp.

◆ p_ordered

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

Definition at line 599 of file attribute.hpp.

◆ p_range

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

Definition at line 587 of file attribute.hpp.

◆ p_range_obj

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

Definition at line 596 of file attribute.hpp.

◆ range_xml_attr

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

Definition at line 655 of file attribute.hpp.

◆ s16_int_type

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

Definition at line 564 of file attribute.hpp.

◆ s32_int_type

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

Definition at line 566 of file attribute.hpp.

◆ s64_int_type

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

Definition at line 568 of file attribute.hpp.

◆ s8_int_type

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

Definition at line 562 of file attribute.hpp.

◆ string_type

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

Definition at line 574 of file attribute.hpp.

◆ time_type

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

Definition at line 573 of file attribute.hpp.

◆ type_xml_attr

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

Definition at line 653 of file attribute.hpp.

◆ u16_int_type

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

Definition at line 565 of file attribute.hpp.

◆ u32_int_type

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

Definition at line 567 of file attribute.hpp.

◆ u64_int_type

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

Definition at line 569 of file attribute.hpp.

◆ u8_int_type

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

Definition at line 563 of file attribute.hpp.

◆ uid_type

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

Definition at line 575 of file attribute.hpp.


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