63 return (f ==
Dec ?
"dec" : f ==
Hex ?
"hex" :
"oct");
91 while (t.
next(token)) {
96 std::ostringstream text;
97 text <<
"range of enumeration attribute \"" <<
p_name <<
"\" is empty";
98 throw std::runtime_error(text.str().c_str());
108 if (
p_range.empty() ==
false) {
121 const std::string* x = &((*p_enumerators)[i]);
122 if (x->length() == length) {
123 if (memcmp(s, x->data(), length) == 0) {
140 const std::string* x = &((*p_enumerators)[i]);
141 if (x->length() == length) {
142 if (memcmp(s, x->data(), length) == 0) {
148 std::ostringstream text;
149 text <<
"value \'" << s <<
"\' is out of range \'" <<
get_range() <<
'\'';
150 throw std::runtime_error(text.str().c_str());
153 throw std::runtime_error(
"attribute is not enumeration");
159 const std::string* p_enumerators_first(&((*
p_enumerators)[0]));
160 return (d.data.ENUMERATION - p_enumerators_first);
169 d.set_init_value(a,
false);
171 }
catch (std::exception& ex) {
172 std::ostringstream text;
176 throw std::runtime_error(text.str().c_str());
197 const std::string& t,
199 const std::string& r,
200 const std::string& init_v,
201 const std::string& ds,
229 return ((
this == &a) ||
238 s <<
"Attribute name: \"" << a.
p_name
251 s <<
" is \'multi values\'\n";
253 s <<
" is \'single value\'\n";
258 " has description: \""
260 << (a.
p_no_null ==
true ?
" can not be null\n" :
" can be null\n") <<
" is "
261 << (a.
p_ordered ==
true ?
"ordered" :
"unordered") << std::endl;
270 std::ostringstream text;
271 text <<
"single-value attribute \"" <<
p_name <<
"\" is of \"class_type\" and has empty init value";
272 throw std::runtime_error(text.str().c_str());
339 throw BadFileData(std::string(
"Value \'") + attr.
value() +
"\' is not a valid attribute type",
355 else if (!strcmp(attr.
name(),
"multi-value-implementation"))
356 s.error_msg(
"OksAttribute::OksAttribute(OksXmlInputStream&)")
357 <<
"Obsolete oks-attribute\'s attribute \'" << attr.
name() <<
"\'\n";
359 s.throw_unexpected_attribute(attr.
name());
363 }
catch (std::exception& e) {
370 throw FailedRead(
"oks attribute",
BadFileData(
"attribute type is not set", s.get_line_no(), s.get_line_pos()));
377 }
catch (std::exception& ex) {
382 if (p_data_type == OksData::class_type && p_multi_values == false) {
383 std::ostringstream text;
384 text <<
"single-value attribute \"" << p_name <<
"\" is of \"class_type\" and has empty init value";
385 throw FailedRead(
"oks attribute", BadFileData(text.str(), s.get_line_no(), s.get_line_pos()));
391 if (p_multi_values) {
392 _d.
SetValues(p_init_value.c_str(),
this);
394 _d.
type = p_data_type;
395 _d.
SetValue(p_init_value.c_str(), 0);
398 std::ostringstream text;
399 text <<
"attribute \"" << p_name <<
"\" has bad init value:\n" << ex.what();
407 }
catch (std::exception& ex) {
408 std::ostringstream text;
409 text <<
"attribute \"" << p_name <<
"\" has mismatch between init value and range:\n" << ex.what();
482 static std::string __types[] = {
515 std::ostringstream text;
516 text <<
"the type \'" << t <<
"\' is not valid";
524 p_class->lock_file(
"OksAttribute::set_type");
528 if (skip_init ==
false) {
532 }
catch (std::exception& ex) {
538 p_class->registrate_attribute_change(
this);
559 }
catch (std::exception& ex) {
565 if (
p_class->find_direct_attribute(new_name) != 0) {
566 std::ostringstream text;
567 text <<
"Class \"" <<
p_class->get_name() <<
"\" already has direct attribute \"" << new_name <<
'\"';
573 p_class->lock_file(
"OksAttribute::set_name");
596 p_class->lock_file(
"OksAttribute::set_is_multi_values");
602 p_class->registrate_attribute_change(
this);
614 p_class->lock_file(
"OksAttribute::set_init_value");
635 p_class->lock_file(
"OksAttribute::set_description");
649 p_class->lock_file(
"OksAttribute::set_is_no_null");
663 p_class->lock_file(
"OksAttribute::set_format");
676 std::string old_value =
p_range;
679 p_class->lock_file(
"OksAttribute::set_range");
686 while (t.
next(token)) {
697 throw SetOperationFailed(
"OksAttribute::set_range",
"boolean type can't have user-defined range!");
705 }
catch (std::exception& ex) {
733 if (token && (p = strstr(
range, token)) != 0) {
734 int len = strlen(token);
737 if (((p !=
range) && (p[-1] !=
',')) || ((p[len] !=
',') && (p[len] !=
'\0'))) {
738 p = strstr(p + 1, token);
752 return (s.size() == 1 && s[0] ==
'*');
761 if (!
range.empty()) {
763 std::string token, token1, token2;
765 while (t.
next(token)) {
767 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' allows any value";
772 static const char __dot_dot_str[] =
"..";
773 std::string::size_type p = token.find(__dot_dot_str, 0, (
sizeof(__dot_dot_str) - 1));
777 if (p != std::string::npos) {
778 token1.assign(token, 0, p);
779 token2.assign(token, p + 2, std::string::npos);
782 token1.assign(token);
790 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' allows any value";
802 if (token2.empty()) {
803 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines equality condition";
812 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines smaller condition";
815 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines greater condition";
818 TLOG_DEBUG(2) <<
"token \'" << token <<
"\' of \'" <<
range <<
"\' defines interval condition";
827 }
catch (std::exception& ex) {
836 for (
const auto& x :
m_less) {
841 for (
const auto& x :
m_great) {
846 for (
const auto& x :
m_equal) {
852 if (d >= x.first && d <= x.second)
856 for (
const auto& x :
m_like) {
860 if (boost::regex_match(d.str(), x))
BadFileData(const std::string &what, unsigned long line_no, unsigned long line_pos, int level_arg=0) noexcept
FailedRead(const std::string &what, const exception &reason) noexcept
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
friend std::ostream & operator<<(std::ostream &, const OksAttribute &)
equality operator
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.
bool validate(const OksData &) const
OksRange(const std::string &range, OksAttribute *a)
std::list< std::pair< OksData, OksData > > m_interval
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)
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.
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 *)