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

Member Enumeration Documentation

◆ Format

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

Enumerator
Oct 
Dec 
Hex 

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

211 :
212 p_name (nm),
214 p_multi_values (false),
215 p_no_null (false),
217 p_class (p),
218 p_enumerators (nullptr),
219 p_range_obj (nullptr),
220 p_ordered (false)
221
222{
223 validate_not_empty(p_name, "attribute name");
224}
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 227 of file attribute.cpp.

229 :
230 p_name (nm),
231 p_range (r),
233 p_multi_values (is_mv),
234 p_no_null (no_null),
235 p_init_value (init_v),
236 p_format (f),
237 p_description (ds),
238 p_class (p),
239 p_enumerators (nullptr),
240 p_range_obj (nullptr),
241 p_ordered (false)
242{
243 set_type(t, true);
244 validate_not_empty(p_name, "attribute name");
245 init_enum();
246 init_range();
247 // cannot call set_init_data() because of the CLASS data type, since other class may not be known yet;
248 // initialize the init_data in the register_all_classes() call
249}
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 162 of file attribute.hpp.

163 {
164 if (p_enumerators)
165 delete p_enumerators;
166
167 clean_range();
168 }

◆ OksAttribute() [3/4]

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

Private constructor used by OksData

Definition at line 611 of file attribute.hpp.

611 :
612 p_data_type(t), p_class(const_cast<OksClass*>(c)), p_enumerators(nullptr), p_range_obj(nullptr), p_ordered(false)
613 {
614 ;
615 }

◆ OksAttribute() [4/4]

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

Private constructor from XML stream

Definition at line 340 of file attribute.cpp.

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

Member Function Documentation

◆ __set_data_type()

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

Definition at line 670 of file attribute.hpp.

671{
672 p_data_type = get_data_type(t, len);
673}

◆ clean_range()

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

Definition at line 635 of file attribute.hpp.

636 {
637 if (p_range_obj)
638 {
639 delete p_range_obj;
640 p_range_obj = nullptr;
641 }
642 }

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

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

◆ format2str()

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

Definition at line 67 of file attribute.cpp.

68{
69 return (
70 f == Dec ? "dec" :
71 f == Hex ? "hex" :
72 "oct"
73 );
74}

◆ get_data_type() [1/3]

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

Get attribute OKS data type.

Definition at line 309 of file attribute.hpp.

310 {
311 return p_data_type;
312 }

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

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

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

476{
477 return get_data_type(t.c_str(), t.size());
478}

◆ get_description()

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

Return description of attribute

Definition at line 422 of file attribute.hpp.

423 {
424 return p_description;
425 }

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

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

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

496 {
497 return get_enum_index(s.data(), s.length());
498 }
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 556 of file attribute.hpp.

557 {
558 return &(*p_enumerators)[idx];
559 }

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

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

185{
186 const std::string * p_enumerators_first(&((*p_enumerators)[0]));
187 return (d.data.ENUMERATION - p_enumerators_first);
188}

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

525 {
526 return get_enum_value(s.data(), s.length());
527 }
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 322 of file attribute.hpp.

323 {
324 return p_format;
325 }

◆ get_init_value()

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

The attribute initialisation value.

Definition at line 389 of file attribute.hpp.

390 {
391 return p_init_value;
392 }

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

367 {
368 return p_multi_values;
369 }

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

444 {
445 return p_no_null;
446 }

◆ get_name()

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

out stream operator

Definition at line 175 of file attribute.hpp.

176 {
177 return p_name;
178 }

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

244 {
245 return p_range;
246 }

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

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

◆ init_enum()

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

Definition at line 89 of file attribute.cpp.

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

◆ init_range()

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

Definition at line 120 of file attribute.cpp.

121{
122 clean_range();
123
124 if (p_range.empty() == false)
125 {
126 p_range_obj = new OksRange(p_range, this);
127 if (p_range_obj->is_empty())
128 {
129 clean_range();
130 }
131 }
132}

◆ is_integer()

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

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

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

◆ operator==()

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

Definition at line 252 of file attribute.cpp.

253{
254 return (
255 ( this == &a ) ||
256 (
257 ( p_name == a.p_name ) &&
258 ( p_range == a.p_range ) &&
259 ( p_data_type == a.p_data_type ) &&
260 ( p_multi_values == a.p_multi_values ) &&
261 ( p_init_value == a.p_init_value ) &&
262 ( p_description == a.p_description ) &&
263 ( p_no_null == a.p_no_null ) &&
264 ( p_ordered == a.p_ordered )
265 )
266 );
267}

◆ save()

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

Private method to save in XML stream

Definition at line 297 of file attribute.cpp.

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

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

695{
696 if (p_description != ds)
697 {
698 if (p_class)
699 p_class->lock_file("OksAttribute::set_description");
700
701 p_description = ds;
702
703 if (p_class)
704 p_class->registrate_class_change(OksClass::ChangeAttributeDescription, (const void *) this);
705 }
706}

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

726{
727 if (f != p_format)
728 {
729 if (p_class)
730 p_class->lock_file("OksAttribute::set_format");
731
732 p_format = f;
733
734 if (p_class)
735 p_class->registrate_class_change(OksClass::ChangeAttributeFormat, (const void *) this);
736 }
737}

◆ set_init_data()

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

Definition at line 645 of file attribute.hpp.

646 {
647 p_init_data.set_init_value(this, false);
648 p_empty_init_data.set_init_value(this, true);
649 }

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

668{
669 if (p_init_value != init_v)
670 {
671 std::string old_value = p_init_value;
672
673 if (p_class)
674 p_class->lock_file("OksAttribute::set_init_value");
675
676 p_init_value = init_v;
677
678 try
679 {
681 }
682 catch (...)
683 {
684 p_init_value = old_value;
685 throw;
686 }
687
688 if (p_class)
689 p_class->registrate_class_change(OksClass::ChangeAttributeInitValue, (const void *) this);
690 }
691}

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

650{
651 if (p_multi_values != is_mv)
652 {
653 if (p_class)
654 p_class->lock_file("OksAttribute::set_is_multi_values");
655
656 p_multi_values = is_mv;
657
658 if (p_class)
659 {
660 p_class->registrate_class_change(OksClass::ChangeAttributeMultiValueCardinality, (const void *) this);
661 p_class->registrate_attribute_change(this);
662 }
663 }
664}
@ ChangeAttributeMultiValueCardinality
Definition class.hpp:905

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

711{
712 if (p_no_null != no_null)
713 {
714 if (p_class)
715 p_class->lock_file("OksAttribute::set_is_no_null");
716
717 p_no_null = no_null;
718
719 if (p_class)
720 p_class->registrate_class_change(OksClass::ChangeAttributeIsNoNull, (const void *) this);
721 }
722}

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

595{
596 // ignore when name is the same
597
598 if (p_name == new_name)
599 return;
600
601 // additional checks are required,
602 // if the attribute already belongs to some class
603
604 if (p_class)
605 {
606 // check allowed length for attribute name
607
608 try
609 {
610 validate_not_empty(new_name, "name");
611 }
612 catch (std::exception& ex)
613 {
614 throw SetOperationFailed("OksAttribute::set_name", ex.what());
615 }
616
617 // having a direct attribute with the same name is an error
618
619 if (p_class->find_direct_attribute(new_name) != 0)
620 {
621 std::ostringstream text;
622 text << "Class \"" << p_class->get_name() << "\" already has direct attribute \"" << new_name << '\"';
623 throw SetOperationFailed("OksAttribute::set_name", text.str());
624 }
625
626 // check that the file can be updated
627
628 p_class->lock_file("OksAttribute::set_name");
629
630 // probably a non-direct attribute already exists
631
632 OksAttribute * a = p_class->find_attribute(new_name);
633
634 // change the name
635
636 p_name = new_name;
637
638 // registrate the change
639
640 p_class->registrate_class_change(OksClass::ChangeAttributesList, (const void *) a);
641 }
642 else
643 {
644 p_name = new_name;
645 }
646}
OksAttribute(const std::string &name, OksClass *p=nullptr)
OKS attribute simple constructor.

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

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

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

555{
557
558 if (p_dt == OksData::unknown_type)
559 {
560 std::ostringstream text;
561 text << "the type \'" << t << "\' is not valid";
562 throw SetOperationFailed("OksAttribute::set_type", text.str());
563 }
564
565 if (p_data_type == p_dt)
566 return;
567
568 if (p_class)
569 p_class->lock_file("OksAttribute::set_type");
570
571 p_data_type = p_dt;
572
573 if (skip_init == false)
574 {
575 try
576 {
577 init_enum();
578 init_range();
579 }
580 catch (std::exception& ex)
581 {
582 throw SetOperationFailed("OksAttribute::set_type", ex.what());
583 }
584 }
585
586 if (p_class)
587 {
588 p_class->registrate_attribute_change(this);
589 p_class->registrate_class_change(OksClass::ChangeAttributeType, (const void *) this);
590 }
591}

◆ str2format()

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

Definition at line 57 of file attribute.cpp.

58{
59 return (
60 cmp_str3(s, "dec") ? Dec :
61 cmp_str3(s, "hex") ? Hex :
62 Oct
63 );
64}
bool cmp_str3(const char *s1, const char s2[4])
Definition cstring.hpp:26

◆ OksClass

friend class OksClass
friend

Definition at line 109 of file attribute.hpp.

◆ OksData

friend struct OksData
friend

Definition at line 112 of file attribute.hpp.

◆ OksIndex

friend class OksIndex
friend

Definition at line 110 of file attribute.hpp.

◆ OksKernel

friend class OksKernel
friend

Definition at line 108 of file attribute.hpp.

◆ OksObject

friend class OksObject
friend

Definition at line 111 of file attribute.hpp.

◆ operator<<

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

equality operator

Definition at line 269 of file attribute.cpp.

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

Member Data Documentation

◆ attribute_xml_tag

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

Valid xml tags and attributes

Definition at line 655 of file attribute.hpp.

◆ bool_type

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

Valid attribute types

Definition at line 566 of file attribute.hpp.

◆ class_type

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

Definition at line 582 of file attribute.hpp.

◆ date_type

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

Definition at line 577 of file attribute.hpp.

◆ description_xml_attr

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

Definition at line 657 of file attribute.hpp.

◆ double_type

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

Definition at line 576 of file attribute.hpp.

◆ enum_type

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

Definition at line 581 of file attribute.hpp.

◆ float_type

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

Definition at line 575 of file attribute.hpp.

◆ format_xml_attr

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

Definition at line 659 of file attribute.hpp.

◆ init_value_xml_attr

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

Definition at line 663 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 661 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 664 of file attribute.hpp.

◆ mv_implement_xml_attr

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

Definition at line 662 of file attribute.hpp.

◆ name_xml_attr

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

Definition at line 656 of file attribute.hpp.

◆ ordered_xml_attr

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

Definition at line 665 of file attribute.hpp.

◆ p_class

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

Definition at line 599 of file attribute.hpp.

◆ p_data_type

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

Definition at line 593 of file attribute.hpp.

◆ p_description

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

Definition at line 598 of file attribute.hpp.

◆ p_empty_init_data

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

Definition at line 603 of file attribute.hpp.

◆ p_enumerators

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

Definition at line 600 of file attribute.hpp.

◆ p_format

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

Definition at line 597 of file attribute.hpp.

◆ p_init_data

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

Definition at line 602 of file attribute.hpp.

◆ p_init_value

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

Definition at line 596 of file attribute.hpp.

◆ p_multi_values

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

Definition at line 594 of file attribute.hpp.

◆ p_name

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

Definition at line 591 of file attribute.hpp.

◆ p_no_null

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

Definition at line 595 of file attribute.hpp.

◆ p_ordered

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

Definition at line 604 of file attribute.hpp.

◆ p_range

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

Definition at line 592 of file attribute.hpp.

◆ p_range_obj

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

Definition at line 601 of file attribute.hpp.

◆ range_xml_attr

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

Definition at line 660 of file attribute.hpp.

◆ s16_int_type

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

Definition at line 569 of file attribute.hpp.

◆ s32_int_type

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

Definition at line 571 of file attribute.hpp.

◆ s64_int_type

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

Definition at line 573 of file attribute.hpp.

◆ s8_int_type

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

Definition at line 567 of file attribute.hpp.

◆ string_type

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

Definition at line 579 of file attribute.hpp.

◆ time_type

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

Definition at line 578 of file attribute.hpp.

◆ type_xml_attr

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

Definition at line 658 of file attribute.hpp.

◆ u16_int_type

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

Definition at line 570 of file attribute.hpp.

◆ u32_int_type

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

Definition at line 572 of file attribute.hpp.

◆ u64_int_type

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

Definition at line 574 of file attribute.hpp.

◆ u8_int_type

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

Definition at line 568 of file attribute.hpp.

◆ uid_type

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

Definition at line 580 of file attribute.hpp.


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