DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::OksRange Class Reference

OKS range class. More...

#include <attribute.hpp>

Public Member Functions

 OksRange (const std::string &range, OksAttribute *a)
void reset (const std::string &range, OksAttribute *a)
bool validate (const OksData &) const
bool is_empty ()

Private Member Functions

void clear ()

Private Attributes

std::string m_range
std::list< OksData > m_less
std::list< OksData > m_equal
std::list< std::pair< OksData, OksData > > m_interval
std::list< OksData > m_great
std::list< boost::regex > m_like

Detailed Description

OKS range class.

The OksRange class implements OKS range that can be defined for an OKS attribute. The range is a set of list of conditions using UML syntax. For string types the range is a regular expression.

Definition at line 44 of file attribute.hpp.

Constructor & Destructor Documentation

◆ OksRange()

dunedaq::oks::OksRange::OksRange ( const std::string & range,
OksAttribute * a )
inline

Definition at line 47 of file attribute.hpp.

47{ reset(range, a); }
void reset(const std::string &range, OksAttribute *a)
DAC value out of range
Message.
Definition DACNode.hpp:32

Member Function Documentation

◆ clear()

void dunedaq::oks::OksRange::clear ( )
inlineprivate

Definition at line 68 of file attribute.hpp.

69 {
70 m_range.clear();
71
72 m_less.clear();
73 m_equal.clear();
74 m_interval.clear();
75 m_great.clear();
76 m_like.clear();
77 }
std::list< std::pair< OksData, OksData > > m_interval
Definition attribute.hpp:63
std::list< OksData > m_less
Definition attribute.hpp:61
std::list< OksData > m_great
Definition attribute.hpp:64
std::list< boost::regex > m_like
Definition attribute.hpp:65
std::list< OksData > m_equal
Definition attribute.hpp:62

◆ is_empty()

bool dunedaq::oks::OksRange::is_empty ( )
inline

Definition at line 53 of file attribute.hpp.

54 {
55 return (m_less.empty() && m_equal.empty() && m_interval.empty() && m_great.empty() && m_like.empty());
56 }

◆ reset()

void dunedaq::oks::OksRange::reset ( const std::string & range,
OksAttribute * a )

Definition at line 756 of file attribute.cpp.

757{
758 clear();
759
760 if (a->get_data_type() != OksData::string_type) {
761 if (!range.empty()) {
762 Oks::Tokenizer t(range, ",");
763 std::string token, token1, token2;
764
765 while (t.next(token)) {
766 if (is_star(token)) {
767 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
768 clear();
769 return;
770 }
771
772 static const char __dot_dot_str[] = "..";
773 std::string::size_type p = token.find(__dot_dot_str, 0, (sizeof(__dot_dot_str) - 1));
774
775 bool pi; // if true, then it is plus infinity, i.e. x..*
776
777 if (p != std::string::npos) {
778 token1.assign(token, 0, p);
779 token2.assign(token, p + 2, std::string::npos);
780 pi = (is_star(token2));
781 } else {
782 token1.assign(token);
783 token2.clear();
784 pi = false;
785 }
786
787 bool mi = (is_star(token1)); // if true, then it is minus infinity, i.e. *..x
788
789 if (mi && pi) {
790 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' allows any value";
791 clear();
792 return;
793 }
794
795 OksData d1, d2;
796
797 if (!mi) {
798 d1.type = a->get_data_type();
799 d1.ReadFrom(token1, a);
800 }
801
802 if (token2.empty()) {
803 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines equality condition";
804 m_equal.emplace_back(d1);
805 } else {
806 if (!pi) {
807 d2.type = a->get_data_type();
808 d2.ReadFrom(token2, a);
809 }
810
811 if (mi) {
812 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines smaller condition";
813 m_less.emplace_back(d2);
814 } else if (pi) {
815 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines greater condition";
816 m_great.emplace_back(d1);
817 } else {
818 TLOG_DEBUG(2) << "token \'" << token << "\' of \'" << range << "\' defines interval condition";
819 m_interval.emplace_back(d1, d2);
820 }
821 }
822 }
823 }
824 } else {
825 try {
826 m_like.emplace_back(range);
827 } catch (std::exception& ex) {
828 throw BadReqExp(range, ex.what());
829 }
830 }
831}
BadReqExp(const std::string &what, const std::string &reason) noexcept
Definition class.hpp:189
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
bool is_star(const std::string &s)

◆ validate()

bool dunedaq::oks::OksRange::validate ( const OksData & d) const

Definition at line 834 of file attribute.cpp.

835{
836 for (const auto& x : m_less) {
837 if (d <= x)
838 return true;
839 }
840
841 for (const auto& x : m_great) {
842 if (d >= x)
843 return true;
844 }
845
846 for (const auto& x : m_equal) {
847 if (d == x)
848 return true;
849 }
850
851 for (const auto& x : m_interval) {
852 if (d >= x.first && d <= x.second)
853 return true;
854 }
855
856 for (const auto& x : m_like) {
858 return true;
859
860 if (boost::regex_match(d.str(), x))
861 return true;
862 }
863
864 return false;
865}
static bool get_skip_string_range()
Get status of string range validator.
Definition kernel.hpp:822

Member Data Documentation

◆ m_equal

std::list<OksData> dunedaq::oks::OksRange::m_equal
private

Definition at line 62 of file attribute.hpp.

◆ m_great

std::list<OksData> dunedaq::oks::OksRange::m_great
private

Definition at line 64 of file attribute.hpp.

◆ m_interval

std::list<std::pair<OksData, OksData> > dunedaq::oks::OksRange::m_interval
private

Definition at line 63 of file attribute.hpp.

◆ m_less

std::list<OksData> dunedaq::oks::OksRange::m_less
private

Definition at line 61 of file attribute.hpp.

◆ m_like

std::list<boost::regex> dunedaq::oks::OksRange::m_like
private

Definition at line 65 of file attribute.hpp.

◆ m_range

std::string dunedaq::oks::OksRange::m_range
private

Definition at line 59 of file attribute.hpp.


The documentation for this class was generated from the following files: