DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
attribute.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3// Fork baseline commit: oks-08-03-04 (2022-04-14).
4// Renamed since fork: no.
5
6#define _OksBuildDll_
7
8#include "oks/attribute.hpp"
9#include "oks/xml.hpp"
10#include "oks/class.hpp"
11#include "oks/kernel.hpp"
12#include "oks/object.hpp"
13#include "oks/cstring.hpp"
14
15#include "logging/Logging.hpp"
16
17#include <sstream>
18#include <stdexcept>
19
20#include <string.h>
21
22namespace dunedaq {
23namespace oks {
24
25
26const char * OksAttribute::bool_type = "bool";
27const char * OksAttribute::s8_int_type = "s8";
28const char * OksAttribute::u8_int_type = "u8";
29const char * OksAttribute::s16_int_type = "s16";
30const char * OksAttribute::u16_int_type = "u16";
31const char * OksAttribute::s32_int_type = "s32";
32const char * OksAttribute::u32_int_type = "u32";
33const char * OksAttribute::s64_int_type = "s64";
34const char * OksAttribute::u64_int_type = "u64";
35const char * OksAttribute::float_type = "float";
36const char * OksAttribute::double_type = "double";
37const char * OksAttribute::date_type = "date";
38const char * OksAttribute::time_type = "time";
39const char * OksAttribute::string_type = "string";
40const char * OksAttribute::uid_type = "uid";
41const char * OksAttribute::enum_type = "enum";
42const char * OksAttribute::class_type = "class";
43
44const char OksAttribute::attribute_xml_tag[] = "attribute";
45const char OksAttribute::name_xml_attr[] = "name";
46const char OksAttribute::description_xml_attr[] = "description";
47const char OksAttribute::type_xml_attr[] = "type";
48const char OksAttribute::range_xml_attr[] = "range";
49const char OksAttribute::format_xml_attr[] = "format";
50const char OksAttribute::is_multi_value_xml_attr[] = "is-multi-value";
51const char OksAttribute::init_value_xml_attr[] = "init-value";
52const char OksAttribute::is_not_null_xml_attr[] = "is-not-null";
53const char OksAttribute::ordered_xml_attr[] = "ordered";
54
55
57OksAttribute::str2format(const char * s) noexcept
58{
59 return (
60 cmp_str3(s, "dec") ? Dec :
61 cmp_str3(s, "hex") ? Hex :
62 Oct
63 );
64}
65
66const char *
68{
69 return (
70 f == Dec ? "dec" :
71 f == Hex ? "hex" :
72 "oct"
73 );
74}
75
76bool
81
82bool
87
88void
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}
118
119void
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}
133
134
135int
136OksAttribute::get_enum_index(const char * s, size_t length) const noexcept
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}
157
158const std::string *
159OksAttribute::get_enum_value(const char * s, size_t length) const
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}
182
183uint16_t
184OksAttribute::get_enum_value(const OksData& d) const noexcept
185{
186 const std::string * p_enumerators_first(&((*p_enumerators)[0]));
187 return (d.data.ENUMERATION - p_enumerators_first);
188}
189
190void
192{
193 if (!a->get_range().empty() && a->get_data_type() != OksData::class_type)
194 {
195 try
196 {
197 OksData d;
198 d.set_init_value(a, false);
199 d.check_range(a);
200 }
201 catch (std::exception& ex)
202 {
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());
206 }
207 }
208}
209
210
211OksAttribute::OksAttribute(const std::string& nm, OksClass * p) :
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}
225
226
227OksAttribute::OksAttribute(const std::string& nm, const std::string& t, bool is_mv,
228 const std::string& r, const std::string& init_v, const std::string& ds,
229 bool no_null, Format f, OksClass * p) :
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}
250
251bool
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 ) &&
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}
268
269std::ostream&
270operator<<(std::ostream& s, const OksAttribute& a)
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}
294
295
296void
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}
338
339
341 p_data_type (OksData::unknown_type),
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))
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 {
426 if (p_data_type == OksData::class_type && p_multi_values == false)
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 {
435 if (p_data_type == OksData::date_type || p_data_type == OksData::time_type)
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}
472
473
474OksData::Type
475OksAttribute::get_data_type(const std::string& t) noexcept
476{
477 return get_data_type(t.c_str(), t.size());
478}
479
480
482OksAttribute::get_data_type(const char * t, size_t len) noexcept
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}
520
521
522const std::string&
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}
551
552
553void
554OksAttribute::set_type(const std::string& t, bool skip_init)
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}
592
593void
594OksAttribute::set_name(const std::string& new_name)
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}
647
648void
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}
665
666void
667OksAttribute::set_init_value(const std::string& init_v)
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}
692
693void
694OksAttribute::set_description(const std::string& ds)
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}
707
708
709void
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}
723
724void
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}
738
739void
740OksAttribute::set_range(const std::string& s)
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}
808
809bool
810OksAttribute::find_token(const char * token, const char * range) noexcept
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}
835
836inline bool
837is_star(const std::string& s)
838{
839 return (s.size() == 1 && s[0] == '*');
840}
841
842
843void
844OksRange::reset(const std::string& range, OksAttribute * a)
845{
846 clear();
847
849 {
850 if (!range.empty())
851 {
852 Oks::Tokenizer t(range, ",");
853 std::string token, token1, token2;
854
855 while (t.next(token))
856 {
857 if (is_star(token))
858 {
859 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
860 clear();
861 return;
862 }
863
864 static const char __dot_dot_str[] = "..";
865 std::string::size_type p = token.find(__dot_dot_str, 0, (sizeof(__dot_dot_str) - 1));
866
867 bool pi; // if true, then it is plus infinity, i.e. x..*
868
869 if (p != std::string::npos)
870 {
871 token1.assign(token, 0, p);
872 token2.assign(token, p + 2, std::string::npos);
873 pi = (is_star(token2));
874 }
875 else
876 {
877 token1.assign(token);
878 token2.clear();
879 pi = false;
880 }
881
882 bool mi = (is_star(token1)); // if true, then it is minus infinity, i.e. *..x
883
884 if (mi && pi)
885 {
886 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
887 clear();
888 return;
889 }
890
891 OksData d1, d2;
892
893 if (!mi)
894 {
895 d1.type = a->get_data_type();
896 d1.ReadFrom(token1, a);
897 }
898
899 if (token2.empty())
900 {
901 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines equality condition";
902 m_equal.emplace_back(d1);
903 }
904 else
905 {
906 if (!pi)
907 {
908 d2.type = a->get_data_type();
909 d2.ReadFrom(token2, a);
910 }
911
912 if (mi)
913 {
914 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines smaller condition";
915 m_less.emplace_back(d2);
916 }
917 else if (pi)
918 {
919 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines greater condition";
920 m_great.emplace_back(d1);
921 }
922 else
923 {
924 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines interval condition";
925 m_interval.emplace_back(d1, d2);
926 }
927 }
928 }
929 }
930 }
931 else
932 {
933 try
934 {
935 m_like.emplace_back(range);
936 }
937 catch (std::exception& ex)
938 {
939 throw BadReqExp(range, ex.what());
940 }
941 }
942}
943
944bool
946{
947 for (const auto& x : m_less)
948 {
949 if (d <= x)
950 return true;
951 }
952
953 for (const auto& x : m_great)
954 {
955 if (d >= x)
956 return true;
957 }
958
959 for (const auto& x : m_equal)
960 {
961 if (d == x)
962 return true;
963 }
964
965 for (const auto& x : m_interval)
966 {
967 if (d >= x.first && d <= x.second)
968 return true;
969 }
970
971 for (const auto& x : m_like)
972 {
974 return true;
975
976 if (boost::regex_match(d.str(),x))
977 return true;
978 }
979
980 return false;
981}
982
983} // namespace oks
984} // namespace dunedaq
OKS attribute class.
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
Definition attribute.cpp:67
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
Definition attribute.cpp:83
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:57
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
Definition attribute.cpp:77
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.
@ ChangeAttributeMultiValueCardinality
Definition class.hpp:905
static bool get_skip_string_range()
Get status of string range validator.
Definition kernel.hpp:804
OKS range class.
Definition attribute.hpp:47
std::list< std::pair< OksData, OksData > > m_interval
Definition attribute.hpp:73
bool validate(const OksData &) const
std::list< OksData > m_less
Definition attribute.hpp:71
std::list< OksData > m_great
Definition attribute.hpp:74
std::list< boost::regex > m_like
Definition attribute.hpp:75
std::list< OksData > m_equal
Definition attribute.hpp:72
void reset(const std::string &range, OksAttribute *a)
String tokenizer.
Definition defs.hpp:63
const std::string next()
Definition time.cpp:194
virtual const char * what() const noexcept
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
const char * bool2str(bool b) noexcept
Definition xml.hpp:28
bool str2bool(const char *s) noexcept
Definition xml.hpp:31
bool cmp_str2n(const char *s1, const char s2[2])
Definition cstring.hpp:22
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
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
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:42
bool cmp_str11(const char *s1, const char s2[12])
Definition cstring.hpp:82
bool cmp_str3(const char *s1, const char s2[4])
Definition cstring.hpp:26
bool cmp_str6n(const char *s1, const char s2[6])
Definition cstring.hpp:54
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
bool cmp_str4n(const char *s1, const char s2[4])
Definition cstring.hpp:38
Including Qt Headers.
Definition module.cpp:16
DAC value out of range
Message.
Definition DACNode.hpp:32
Definition ral.hpp:35
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:454
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:752
size_t value_len() const
Definition xml.hpp:309