100 while (t.
next(token))
107 std::ostringstream text;
108 text <<
"range of enumeration attribute \"" <<
p_name <<
"\" is empty";
109 throw std::runtime_error(text.str().c_str());
135 for (
int i = 0; i < (int) p_enumerators->size(); ++i)
137 const std::string * x = &((*p_enumerators)[i]);
138 if (x->length() == length)
140 if (memcmp(s, x->data(), length) == 0)
160 const std::string * x = &((*p_enumerators)[i]);
161 if (x->length() == length)
163 if (memcmp(s, x->data(), length) == 0)
170 std::ostringstream text;
171 text <<
"value \'" << s <<
"\' is out of range \'" <<
get_range() <<
'\'';
172 throw std::runtime_error(text.str().c_str());
175 throw std::runtime_error(
"attribute is not enumeration");
181 const std::string * p_enumerators_first(&((*p_enumerators)[0]));
182 return (d.data.ENUMERATION - p_enumerators_first);
193 d.set_init_value(a,
false);
196 catch (std::exception& ex)
198 std::ostringstream text;
199 text <<
"failed to set initial value \'" << a->
get_init_value() <<
"\' of attribute \'" << a->
get_name() <<
"\':\n" << ex.what();
200 throw std::runtime_error(text.str().c_str());
208 p_data_type (
OksData::string_type),
209 p_multi_values (false),
213 p_enumerators (nullptr),
214 p_range_obj (nullptr),
223 const std::string& r,
const std::string& init_v,
const std::string& ds,
227 p_data_type (get_data_type(t)),
228 p_multi_values (is_mv),
230 p_init_value (init_v),
234 p_enumerators (nullptr),
235 p_range_obj (nullptr),
267 s <<
"Attribute name: \"" << a.
p_name <<
"\"\n"
268 " type: \"" << a.
get_type() <<
"\"\n"
269 " range: \"" << a.
p_range <<
"\"\n";
276 s <<
" is \'multi values\'\n";
279 s <<
" is \'single value\'\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;
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());
336 p_data_type (
OksData::unknown_type),
337 p_multi_values (false),
341 p_enumerators (nullptr),
342 p_range_obj (nullptr),
371 throw BadFileData(std::string(
"Value \'") + attr.
value() +
"\' is not a valid attribute type", s.get_line_no(), s.get_line_pos());
386 else if (!strcmp(attr.
name(),
"multi-value-implementation"))
387 s.error_msg(
"OksAttribute::OksAttribute(OksXmlInputStream&)") <<
"Obsolete oks-attribute\'s attribute \'" << attr.
name() <<
"\'\n";
389 s.throw_unexpected_attribute(attr.
name());
396 catch (std::exception & e)
405 throw FailedRead(
"oks attribute",
BadFileData(
"attribute type is not set", s.get_line_no(), s.get_line_pos()));
414 catch (std::exception& ex)
421 if (p_data_type == OksData::class_type && p_multi_values == false)
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()));
437 _d.
SetValues(p_init_value.c_str(),
this);
441 _d.
type = p_data_type;
442 _d.
SetValue(p_init_value.c_str(), 0);
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()));
458 catch (std::exception& ex)
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()));
470OksAttribute::get_data_type(
const std::string& t)
noexcept
472 return get_data_type(t.c_str(), t.size());
477OksAttribute::get_data_type(
const char * t,
size_t len)
noexcept
481 if (
cmp_str3n (t, uid_type) )
return OksData::uid2_type;
482 else if(
cmp_str3n (t, u32_int_type) )
return OksData::u32_int_type;
483 else if(
cmp_str3n (t, s32_int_type) )
return OksData::s32_int_type;
484 else if(
cmp_str3n (t, u16_int_type) )
return OksData::u16_int_type;
485 else if(
cmp_str3n (t, s16_int_type) )
return OksData::s16_int_type;
486 else if(
cmp_str3n (t, s64_int_type) )
return OksData::s64_int_type;
487 else if(
cmp_str3n (t, u64_int_type) )
return OksData::u64_int_type;
491 if(
cmp_str6n (t, string_type) )
return OksData::string_type;
492 else if(
cmp_str6n (t, double_type) )
return OksData::double_type;
496 if(
cmp_str4n (t, bool_type) )
return OksData::bool_type;
497 else if(
cmp_str4n (t, enum_type) )
return OksData::enum_type;
498 else if(
cmp_str4n (t, date_type) )
return OksData::date_type;
499 else if(
cmp_str4n (t, time_type) )
return OksData::time_type;
503 if(
cmp_str5n (t, float_type) )
return OksData::float_type;
504 else if(
cmp_str5n (t, class_type) )
return OksData::class_type;
508 if(
cmp_str2n (t, s8_int_type) )
return OksData::s8_int_type;
509 else if(
cmp_str2n (t, u8_int_type) )
return OksData::u8_int_type;
513 return OksData::unknown_type;
518OksAttribute::get_type()
const throw()
520 static std::string __types [] = {
544 return __types[(int)p_data_type];
549OksAttribute::set_type(
const std::string& t,
bool skip_init)
553 if (p_dt == OksData::unknown_type)
555 std::ostringstream text;
556 text <<
"the type \'" << t <<
"\' is not valid";
560 if (p_data_type == p_dt)
564 p_class->lock_file(
"OksAttribute::set_type");
568 if (skip_init ==
false)
575 catch (std::exception& ex)
583 p_class->registrate_attribute_change(
this);
584 p_class->registrate_class_change(OksClass::ChangeAttributeType, (
const void *)
this);
589OksAttribute::set_name(
const std::string& new_name)
593 if (p_name == new_name)
607 catch (std::exception& ex)
614 if (p_class->find_direct_attribute(new_name) != 0)
616 std::ostringstream text;
617 text <<
"Class \"" << p_class->get_name() <<
"\" already has direct attribute \"" << new_name <<
'\"';
623 p_class->lock_file(
"OksAttribute::set_name");
635 p_class->registrate_class_change(OksClass::ChangeAttributesList, (
const void *) a);
644OksAttribute::set_is_multi_values(
bool is_mv)
646 if (p_multi_values != is_mv)
649 p_class->lock_file(
"OksAttribute::set_is_multi_values");
651 p_multi_values = is_mv;
655 p_class->registrate_class_change(OksClass::ChangeAttributeMultiValueCardinality, (
const void *)
this);
656 p_class->registrate_attribute_change(
this);
662OksAttribute::set_init_value(
const std::string& init_v)
664 if (p_init_value != init_v)
666 std::string old_value = p_init_value;
669 p_class->lock_file(
"OksAttribute::set_init_value");
671 p_init_value = init_v;
679 p_init_value = old_value;
684 p_class->registrate_class_change(OksClass::ChangeAttributeInitValue, (
const void *)
this);
689OksAttribute::set_description(
const std::string& ds)
691 if (p_description != ds)
694 p_class->lock_file(
"OksAttribute::set_description");
699 p_class->registrate_class_change(OksClass::ChangeAttributeDescription, (
const void *)
this);
705OksAttribute::set_is_no_null(
bool no_null)
707 if (p_no_null != no_null)
710 p_class->lock_file(
"OksAttribute::set_is_no_null");
715 p_class->registrate_class_change(OksClass::ChangeAttributeIsNoNull, (
const void *)
this);
725 p_class->lock_file(
"OksAttribute::set_format");
730 p_class->registrate_class_change(OksClass::ChangeAttributeFormat, (
const void *)
this);
735OksAttribute::set_range(
const std::string& s)
739 std::string old_value = p_range;
742 p_class->lock_file(
"OksAttribute::set_range");
749 while (t.
next(token))
761 if (p_data_type == OksData::bool_type)
764 throw SetOperationFailed(
"OksAttribute::set_range",
"boolean type can't have user-defined range!");
774 catch (std::exception& ex)
800 p_class->registrate_class_change(OksClass::ChangeAttributeRange, (
const void *)
this);
805OksAttribute::find_token(
const char * token,
const char *
range)
noexcept
809 if (token && (p = strstr(
range, token)) != 0)
811 int len = strlen(token);
815 if (((p !=
range) && (p[-1] !=
',')) || ((p[len] !=
',') && (p[len] !=
'\0')))
817 p = strstr(p + 1, token);
834 return (s.size() == 1 && s[0] ==
'*');
848 std::string token, token1, token2;
850 while (t.
next(token))
854 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' allows any value";
859 static const char __dot_dot_str[] =
"..";
860 std::string::size_type p = token.find(__dot_dot_str, 0, (
sizeof(__dot_dot_str) - 1));
864 if (p != std::string::npos)
866 token1.assign(token, 0, p);
867 token2.assign(token, p + 2, std::string::npos);
872 token1.assign(token);
881 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' allows any value";
896 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines equality condition";
897 m_equal.emplace_back(d1);
909 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines smaller condition";
910 m_less.emplace_back(d2);
914 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines greater condition";
915 m_great.emplace_back(d1);
919 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines interval condition";
920 m_interval.emplace_back(d1, d2);
930 m_like.emplace_back(
range);
932 catch (std::exception& ex)
942 for (
const auto& x : m_less)
948 for (
const auto& x : m_great)
954 for (
const auto& x : m_equal)
960 for (
const auto& x : m_interval)
962 if (d >= x.first && d <= x.second)
966 for (
const auto& x : m_like)
968 if (OksKernel::get_skip_string_range())
971 if (boost::regex_match(d.str(),x))
OksData::Type p_data_type
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 format_xml_attr[]
void set_type(const std::string &type, bool skip_init=false)
Set attribute type.
static const char description_xml_attr[]
static const char * bool_type
static const char name_xml_attr[]
void __set_data_type(const char *t, size_t len) noexcept
const std::string & get_type() const noexcept
Get attribute string type.
static const char ordered_xml_attr[]
const std::string & get_range() const noexcept
Get attribute range.
const std::string & get_name() const noexcept
out stream operator
static const char * class_type
static const char * string_type
void save(OksXmlOutputStream &) const
static const char * enum_type
static const char * s32_int_type
static const char init_value_xml_attr[]
static const char * format2str(Format) noexcept
OksAttribute(const std::string &name, OksClass *p=nullptr)
OKS attribute simple constructor.
static const char attribute_xml_tag[]
static const char * s16_int_type
static const char * u64_int_type
static const char * double_type
std::vector< std::string > * p_enumerators
bool operator==(const class OksAttribute &) const
const std::string & get_init_value() const noexcept
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...
static const char is_multi_value_xml_attr[]
bool is_number() const noexcept
static const char * u16_int_type
int get_enum_index(const char *s, size_t length) const noexcept
Finds index of given string in attribute's range.
static const char * date_type
static const char is_not_null_xml_attr[]
static const char * float_type
static Format str2format(const char *) noexcept
static const char type_xml_attr[]
static const char range_xml_attr[]
bool is_integer() const noexcept
static OksData::Type get_data_type(const std::string &type) noexcept
Converts string to attribute OKS data type.
std::string p_description
virtual const char * what() const noexcept
caught dunedaq::conffwk::Exception exception
#define TLOG_DEBUG(lvl,...)
const char * bool2str(bool b) noexcept
bool str2bool(const char *s) noexcept
bool cmp_str2n(const char *s1, const char s2[2])
bool cmp_str1(const char *s1, const char s2[2])
bool cmp_str4(const char *s1, const char s2[5])
bool cmp_str6(const char *s1, const char s2[7])
bool cmp_str10(const char *s1, const char s2[11])
bool cmp_str5n(const char *s1, const char s2[5])
bool cmp_str3n(const char *s1, const char s2[3])
void validate_init2range(const OksAttribute *a)
void validate_not_empty(const std::string &value, const char *name)
std::ostream & operator<<(std::ostream &s, const oks::exception &ex)
bool is_star(const std::string &s)
bool cmp_str5(const char *s1, const char s2[6])
bool cmp_str11(const char *s1, const char s2[12])
bool cmp_str3(const char *s1, const char s2[4])
bool cmp_str6n(const char *s1, const char s2[6])
bool cmp_str14(const char *s1, const char s2[14])
bool cmp_str7(const char *s1, const char s2[8])
bool cmp_str4n(const char *s1, const char s2[4])
DAC value out of range
Message.
the structure to pass common parameters to various read() methods of OksData and OksObject class
void SetValue(const char *s, const OksAttribute *a)
void SetValues(const char *, const OksAttribute *a)
enum dunedaq::oks::OksData::Type type
void ReadFrom(const char *, Type, const OksAttribute *)