105 while (t.
next(token))
112 std::ostringstream text;
113 text <<
"range of enumeration attribute \"" <<
p_name <<
"\" is empty";
114 throw std::runtime_error(text.str().c_str());
142 const std::string * x = &((*p_enumerators)[i]);
143 if (x->length() == length)
145 if (memcmp(s, x->data(), length) == 0)
165 const std::string * x = &((*p_enumerators)[i]);
166 if (x->length() == length)
168 if (memcmp(s, x->data(), length) == 0)
175 std::ostringstream text;
176 text <<
"value \'" << s <<
"\' is out of range \'" <<
get_range() <<
'\'';
177 throw std::runtime_error(text.str().c_str());
180 throw std::runtime_error(
"attribute is not enumeration");
186 const std::string * p_enumerators_first(&((*
p_enumerators)[0]));
187 return (d.data.ENUMERATION - p_enumerators_first);
198 d.set_init_value(a,
false);
201 catch (std::exception& ex)
203 std::ostringstream text;
204 text <<
"failed to set initial value \'" << a->
get_init_value() <<
"\' of attribute \'" << a->
get_name() <<
"\':\n" << ex.what();
205 throw std::runtime_error(text.str().c_str());
228 const std::string& r,
const std::string& init_v,
const std::string& ds,
272 s <<
"Attribute name: \"" << a.
p_name <<
"\"\n"
273 " type: \"" << a.
get_type() <<
"\"\n"
274 " range: \"" << a.
p_range <<
"\"\n";
281 s <<
" is \'multi values\'\n";
284 s <<
" is \'single value\'\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;
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());
376 throw BadFileData(std::string(
"Value \'") + attr.
value() +
"\' is not a valid attribute type", s.get_line_no(), s.get_line_pos());
391 else if (!strcmp(attr.
name(),
"multi-value-implementation"))
392 s.error_msg(
"OksAttribute::OksAttribute(OksXmlInputStream&)") <<
"Obsolete oks-attribute\'s attribute \'" << attr.
name() <<
"\'\n";
394 s.throw_unexpected_attribute(attr.
name());
401 catch (std::exception & e)
410 throw FailedRead(
"oks attribute",
BadFileData(
"attribute type is not set", s.get_line_no(), s.get_line_pos()));
419 catch (std::exception& ex)
426 if (p_data_type == OksData::class_type && p_multi_values == false)
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()));
442 _d.
SetValues(p_init_value.c_str(),
this);
446 _d.
type = p_data_type;
447 _d.
SetValue(p_init_value.c_str(), 0);
452 std::ostringstream text;
453 text <<
"attribute \"" << p_name <<
"\" has bad init value:\n" << ex.what();
463 catch (std::exception& ex)
465 std::ostringstream text;
466 text <<
"attribute \"" << p_name <<
"\" has mismatch between init value and range:\n" << ex.what();
525 static std::string __types [] = {
560 std::ostringstream text;
561 text <<
"the type \'" << t <<
"\' is not valid";
569 p_class->lock_file(
"OksAttribute::set_type");
573 if (skip_init ==
false)
580 catch (std::exception& ex)
588 p_class->registrate_attribute_change(
this);
612 catch (std::exception& ex)
619 if (
p_class->find_direct_attribute(new_name) != 0)
621 std::ostringstream text;
622 text <<
"Class \"" <<
p_class->get_name() <<
"\" already has direct attribute \"" << new_name <<
'\"';
628 p_class->lock_file(
"OksAttribute::set_name");
654 p_class->lock_file(
"OksAttribute::set_is_multi_values");
661 p_class->registrate_attribute_change(
this);
674 p_class->lock_file(
"OksAttribute::set_init_value");
699 p_class->lock_file(
"OksAttribute::set_description");
715 p_class->lock_file(
"OksAttribute::set_is_no_null");
730 p_class->lock_file(
"OksAttribute::set_format");
744 std::string old_value =
p_range;
747 p_class->lock_file(
"OksAttribute::set_range");
754 while (t.
next(token))
769 throw SetOperationFailed(
"OksAttribute::set_range",
"boolean type can't have user-defined range!");
779 catch (std::exception& ex)
814 if (token && (p = strstr(
range, token)) != 0)
816 int len = strlen(token);
820 if (((p !=
range) && (p[-1] !=
',')) || ((p[len] !=
',') && (p[len] !=
'\0')))
822 p = strstr(p + 1, token);
839 return (s.size() == 1 && s[0] ==
'*');
853 std::string token, token1, token2;
855 while (t.
next(token))
859 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' allows any value";
864 static const char __dot_dot_str[] =
"..";
865 std::string::size_type p = token.find(__dot_dot_str, 0, (
sizeof(__dot_dot_str) - 1));
869 if (p != std::string::npos)
871 token1.assign(token, 0, p);
872 token2.assign(token, p + 2, std::string::npos);
877 token1.assign(token);
886 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' allows any value";
901 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines equality condition";
914 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines smaller condition";
919 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines greater condition";
924 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines interval condition";
937 catch (std::exception& ex)
947 for (
const auto& x :
m_less)
967 if (d >= x.first && d <= x.second)
971 for (
const auto& x :
m_like)
976 if (boost::regex_match(d.str(),x))
OksData::Type p_data_type
static const char * uid_type
static const char * s8_int_type
void set_range(const std::string &range)
Set attribute range.
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.
void set_is_multi_values(bool multi_values)
Set attribute is a single-value or multi-value.
void set_format(Format format)
Set attribute format.
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 bool find_token(const char *token, const char *range) noexcept
Finds token in given range.
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...
void set_is_no_null(bool no_null)
Set attribute is-no-null property.
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
void set_description(const std::string &description)
Set attribute description.
void set_init_value(const std::string &init_value)
Set attribute initialisation value.
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.
void set_name(const std::string &name)
Set attribute name.
std::string p_description
@ ChangeAttributeDescription
@ ChangeAttributeIsNoNull
@ ChangeAttributeInitValue
@ ChangeAttributeMultiValueCardinality
static bool get_skip_string_range()
Get status of string range validator.
std::list< std::pair< OksData, OksData > > m_interval
bool validate(const OksData &) const
std::list< OksData > m_less
std::list< OksData > m_great
std::list< boost::regex > m_like
std::list< OksData > m_equal
void reset(const std::string &range, OksAttribute *a)
virtual const char * what() const noexcept
#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 *)