DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
attribute.cpp
Go to the documentation of this file.
1#define _OksBuildDll_
2
3#include "oks/attribute.hpp"
4#include "oks/xml.hpp"
5#include "oks/class.hpp"
6#include "oks/kernel.hpp"
7#include "oks/object.hpp"
8#include "oks/cstring.hpp"
9
10#include "logging/Logging.hpp"
11
12#include <sstream>
13#include <stdexcept>
14
15#include <string.h>
16
17namespace dunedaq {
18namespace oks {
19
20
21const char * OksAttribute::bool_type = "bool";
22const char * OksAttribute::s8_int_type = "s8";
23const char * OksAttribute::u8_int_type = "u8";
24const char * OksAttribute::s16_int_type = "s16";
25const char * OksAttribute::u16_int_type = "u16";
26const char * OksAttribute::s32_int_type = "s32";
27const char * OksAttribute::u32_int_type = "u32";
28const char * OksAttribute::s64_int_type = "s64";
29const char * OksAttribute::u64_int_type = "u64";
30const char * OksAttribute::float_type = "float";
31const char * OksAttribute::double_type = "double";
32const char * OksAttribute::date_type = "date";
33const char * OksAttribute::time_type = "time";
34const char * OksAttribute::string_type = "string";
35const char * OksAttribute::uid_type = "uid";
36const char * OksAttribute::enum_type = "enum";
37const char * OksAttribute::class_type = "class";
38
39const char OksAttribute::attribute_xml_tag[] = "attribute";
40const char OksAttribute::name_xml_attr[] = "name";
41const char OksAttribute::description_xml_attr[] = "description";
42const char OksAttribute::type_xml_attr[] = "type";
43const char OksAttribute::range_xml_attr[] = "range";
44const char OksAttribute::format_xml_attr[] = "format";
45const char OksAttribute::is_multi_value_xml_attr[] = "is-multi-value";
46const char OksAttribute::init_value_xml_attr[] = "init-value";
47const char OksAttribute::is_not_null_xml_attr[] = "is-not-null";
48const char OksAttribute::ordered_xml_attr[] = "ordered";
49
50
52OksAttribute::str2format(const char * s) noexcept
53{
54 return (
55 cmp_str3(s, "dec") ? Dec :
56 cmp_str3(s, "hex") ? Hex :
57 Oct
58 );
59}
60
61const char *
63{
64 return (
65 f == Dec ? "dec" :
66 f == Hex ? "hex" :
67 "oct"
68 );
69}
70
71bool
76
77bool
82
83void
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}
113
114void
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}
128
129
130int
131OksAttribute::get_enum_index(const char * s, size_t length) const noexcept
132{
133 if (p_data_type == OksData::enum_type)
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}
152
153const std::string *
154OksAttribute::get_enum_value(const char * s, size_t length) const
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}
177
178uint16_t
179OksAttribute::get_enum_value(const OksData& d) const noexcept
180{
181 const std::string * p_enumerators_first(&((*p_enumerators)[0]));
182 return (d.data.ENUMERATION - p_enumerators_first);
183}
184
185void
187{
188 if (!a->get_range().empty() && a->get_data_type() != OksData::class_type)
189 {
190 try
191 {
192 OksData d;
193 d.set_init_value(a, false);
194 d.check_range(a);
195 }
196 catch (std::exception& ex)
197 {
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());
201 }
202 }
203}
204
205
206OksAttribute::OksAttribute(const std::string& nm, OksClass * p) :
207 p_name (nm),
208 p_data_type (OksData::string_type),
209 p_multi_values (false),
210 p_no_null (false),
211 p_format (OksAttribute::Dec),
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}
220
221
222OksAttribute::OksAttribute(const std::string& nm, const std::string& t, bool is_mv,
223 const std::string& r, const std::string& init_v, const std::string& ds,
224 bool no_null, Format f, OksClass * p) :
225 p_name (nm),
226 p_range (r),
227 p_data_type (get_data_type(t)),
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}
245
246bool
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 ) &&
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}
263
264std::ostream&
265operator<<(std::ostream& s, const OksAttribute& a)
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}
289
290
291void
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}
333
334
336 p_data_type (OksData::unknown_type),
337 p_multi_values (false),
338 p_no_null (false),
339 p_format (OksAttribute::Dec),
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))
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 {
421 if (p_data_type == OksData::class_type && p_multi_values == false)
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 {
430 if (p_data_type == OksData::date_type || p_data_type == OksData::time_type)
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}
467
468
469OksData::Type
470OksAttribute::get_data_type(const std::string& t) noexcept
471{
472 return get_data_type(t.c_str(), t.size());
473}
474
475
477OksAttribute::get_data_type(const char * t, size_t len) noexcept
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
513 return OksData::unknown_type;
514}
515
516
517const std::string&
518OksAttribute::get_type() const throw()
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}
546
547
548void
549OksAttribute::set_type(const std::string& t, bool skip_init)
550{
551 OksData::Type p_dt = get_data_type(t);
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 {
583 p_class->registrate_attribute_change(this);
584 p_class->registrate_class_change(OksClass::ChangeAttributeType, (const void *) this);
585 }
586}
587
588void
589OksAttribute::set_name(const std::string& new_name)
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
635 p_class->registrate_class_change(OksClass::ChangeAttributesList, (const void *) a);
636 }
637 else
638 {
639 p_name = new_name;
640 }
641}
642
643void
644OksAttribute::set_is_multi_values(bool is_mv)
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 {
655 p_class->registrate_class_change(OksClass::ChangeAttributeMultiValueCardinality, (const void *) this);
656 p_class->registrate_attribute_change(this);
657 }
658 }
659}
660
661void
662OksAttribute::set_init_value(const std::string& init_v)
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)
684 p_class->registrate_class_change(OksClass::ChangeAttributeInitValue, (const void *) this);
685 }
686}
687
688void
689OksAttribute::set_description(const std::string& ds)
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)
699 p_class->registrate_class_change(OksClass::ChangeAttributeDescription, (const void *) this);
700 }
701}
702
703
704void
705OksAttribute::set_is_no_null(bool no_null)
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)
715 p_class->registrate_class_change(OksClass::ChangeAttributeIsNoNull, (const void *) this);
716 }
717}
718
719void
720OksAttribute::set_format(Format f)
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)
730 p_class->registrate_class_change(OksClass::ChangeAttributeFormat, (const void *) this);
731 }
732}
733
734void
735OksAttribute::set_range(const std::string& s)
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 {
761 if (p_data_type == OksData::bool_type)
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)
800 p_class->registrate_class_change(OksClass::ChangeAttributeRange, (const void *) this);
801 }
802}
803
804bool
805OksAttribute::find_token(const char * token, const char * range) noexcept
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}
830
831inline bool
832is_star(const std::string& s)
833{
834 return (s.size() == 1 && s[0] == '*');
835}
836
837
838void
839OksRange::reset(const std::string& range, OksAttribute * a)
840{
841 clear();
842
843 if (a->get_data_type() != OksData::string_type)
844 {
845 if (!range.empty())
846 {
847 Oks::Tokenizer t(range, ",");
848 std::string token, token1, token2;
849
850 while (t.next(token))
851 {
852 if (is_star(token))
853 {
854 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
855 clear();
856 return;
857 }
858
859 static const char __dot_dot_str[] = "..";
860 std::string::size_type p = token.find(__dot_dot_str, 0, (sizeof(__dot_dot_str) - 1));
861
862 bool pi; // if true, then it is plus infinity, i.e. x..*
863
864 if (p != std::string::npos)
865 {
866 token1.assign(token, 0, p);
867 token2.assign(token, p + 2, std::string::npos);
868 pi = (is_star(token2));
869 }
870 else
871 {
872 token1.assign(token);
873 token2.clear();
874 pi = false;
875 }
876
877 bool mi = (is_star(token1)); // if true, then it is minus infinity, i.e. *..x
878
879 if (mi && pi)
880 {
881 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
882 clear();
883 return;
884 }
885
886 OksData d1, d2;
887
888 if (!mi)
889 {
890 d1.type = a->get_data_type();
891 d1.ReadFrom(token1, a);
892 }
893
894 if (token2.empty())
895 {
896 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines equality condition";
897 m_equal.emplace_back(d1);
898 }
899 else
900 {
901 if (!pi)
902 {
903 d2.type = a->get_data_type();
904 d2.ReadFrom(token2, a);
905 }
906
907 if (mi)
908 {
909 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines smaller condition";
910 m_less.emplace_back(d2);
911 }
912 else if (pi)
913 {
914 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines greater condition";
915 m_great.emplace_back(d1);
916 }
917 else
918 {
919 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines interval condition";
920 m_interval.emplace_back(d1, d2);
921 }
922 }
923 }
924 }
925 }
926 else
927 {
928 try
929 {
930 m_like.emplace_back(range);
931 }
932 catch (std::exception& ex)
933 {
934 throw BadReqExp(range, ex.what());
935 }
936 }
937}
938
939bool
940OksRange::validate(const OksData& d) const
941{
942 for (const auto& x : m_less)
943 {
944 if (d <= x)
945 return true;
946 }
947
948 for (const auto& x : m_great)
949 {
950 if (d >= x)
951 return true;
952 }
953
954 for (const auto& x : m_equal)
955 {
956 if (d == x)
957 return true;
958 }
959
960 for (const auto& x : m_interval)
961 {
962 if (d >= x.first && d <= x.second)
963 return true;
964 }
965
966 for (const auto& x : m_like)
967 {
968 if (OksKernel::get_skip_string_range())
969 return true;
970
971 if (boost::regex_match(d.str(),x))
972 return true;
973 }
974
975 return false;
976}
977
978} // namespace oks
979} // namespace dunedaq
OKS attribute class.
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
Definition attribute.cpp:62
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
Definition attribute.cpp:78
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
Definition attribute.cpp:52
static const char type_xml_attr[]
static const char range_xml_attr[]
bool is_integer() const noexcept
Definition attribute.cpp:72
static OksData::Type get_data_type(const std::string &type) noexcept
Converts string to attribute OKS data type.
The OKS class.
Definition class.hpp:200
OKS range class.
Definition attribute.hpp:42
String tokenizer.
Definition defs.hpp:58
const std::string next()
Definition time.cpp:189
virtual const char * what() const noexcept
caught dunedaq::conffwk::Exception exception
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
const char * bool2str(bool b) noexcept
Definition xml.hpp:23
bool str2bool(const char *s) noexcept
Definition xml.hpp:26
bool cmp_str2n(const char *s1, const char s2[2])
Definition cstring.hpp:17
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
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
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])
Definition cstring.hpp:37
bool cmp_str11(const char *s1, const char s2[12])
Definition cstring.hpp:77
bool cmp_str3(const char *s1, const char s2[4])
Definition cstring.hpp:21
bool cmp_str6n(const char *s1, const char s2[6])
Definition cstring.hpp:49
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
bool cmp_str4n(const char *s1, const char s2[4])
Definition cstring.hpp:33
Including Qt Headers.
DAC value out of range
Message.
Definition DACNode.hpp:32
Definition __init__.py:1
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:449
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 *)
Definition object.hpp:747
size_t value_len() const
Definition xml.hpp:304