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

OKS query expression class. More...

#include <query.hpp>

Inheritance diagram for dunedaq::oks::OksQueryExpression:
[legend]

Public Member Functions

virtual ~OksQueryExpression ()
 
OksQuery::QueryType type () const
 
bool CheckSyntax () const
 
bool operator== (const class OksQueryExpression &e) const
 

Protected Member Functions

 OksQueryExpression (OksQuery::QueryType qet=OksQuery::unknown_type)
 

Private Attributes

const OksQuery::QueryType p_type
 

Friends

std::ostream & operator<< (std::ostream &s, const OksQueryExpression &qe)
 

Detailed Description

OKS query expression class.

The abstract class provides interface to OKS query expression. A query expression has type and method to check its correctness.

Definition at line 107 of file query.hpp.

Constructor & Destructor Documentation

◆ ~OksQueryExpression()

virtual dunedaq::oks::OksQueryExpression::~OksQueryExpression ( )
inlinevirtual

Definition at line 112 of file query.hpp.

112{;}

◆ OksQueryExpression()

dunedaq::oks::OksQueryExpression::OksQueryExpression ( OksQuery::QueryType qet = OksQuery::unknown_type)
inlineprotected

Definition at line 121 of file query.hpp.

121: p_type (qet) {};
const OksQuery::QueryType p_type
Definition query.hpp:126

Member Function Documentation

◆ CheckSyntax()

bool dunedaq::oks::OksQueryExpression::CheckSyntax ( ) const

Definition at line 543 of file query.cpp.

544{
545 const char * fname = "OksQueryExpression::CheckSyntax()";
546
547 switch(p_type) {
549 if(!((OksComparator *)this)->attribute && !((OksComparator *)this)->value) {
550 Oks::error_msg(fname)
551 << "OksComparator: Can't execute query for nil attribute or nil object-id\n";
552 return false;
553 }
554 else if(!((OksComparator *)this)->m_comp_f) {
555 Oks::error_msg(fname)
556 << "OksComparator: Can't execute query for nil compare function\n";
557 return false;
558 }
559
560 return true;
561
563 if(!((OksRelationshipExpression *)this)->relationship) {
564 Oks::error_msg(fname)
565 << "OksRelationshipExpression: Can't execute query for nil relationship\n";
566 return false;
567 }
568 else if(!((OksRelationshipExpression *)this)->p_expression) {
569 Oks::error_msg(fname)
570 << "OksRelationshipExpression: Can't execute query for nil query expression\n";
571 return false;
572 }
573 else
574 return (((OksRelationshipExpression *)this)->p_expression)->CheckSyntax();
575
577 if(!((OksNotExpression *)this)->p_expression) {
578 Oks::error_msg(fname)
579 << "OksNotExpression: Can't execute \'not\' for nil query expression\n";
580 return false;
581 }
582
583 return (((OksNotExpression *)this)->p_expression)->CheckSyntax();
584
586 if(((OksAndExpression *)this)->p_expressions.size() < 2) {
587 Oks::error_msg(fname)
588 << "OksAndExpression: Can't execute \'and\' for "
589 << ((OksAndExpression *)this)->p_expressions.size() << " argument\n"
590 "Two or more arguments are required\n";
591 return false;
592 }
593 else {
594 std::list<OksQueryExpression *> & elist = ((OksAndExpression *)this)->p_expressions;
595
596 for(std::list<OksQueryExpression *>::iterator i = elist.begin(); i != elist.end(); ++i)
597 if((*i)->CheckSyntax() == false) return false;
598
599 return true;
600 }
601
603 if(((OksOrExpression *)this)->p_expressions.size() < 2) {
604 Oks::error_msg(fname)
605 << "OksOrExpression: Can't execute \'or\' for "
606 << ((OksOrExpression *)this)->p_expressions.size() << " argument\n"
607 "Two or more arguments are required\n";
608
609 return false;
610 }
611 else {
612 std::list<OksQueryExpression *> & elist = ((OksOrExpression *)this)->p_expressions;
613
614 for(std::list<OksQueryExpression *>::iterator i = elist.begin(); i != elist.end(); ++i)
615 if((*i)->CheckSyntax() == false) return false;
616
617 return true;
618 }
619
620 default:
621 Oks::error_msg(fname)
622 << "Unexpected query type " << (int)p_type << std::endl;
623
624 return false;
625 }
626}
static std::ostream & error_msg(const char *)
Definition kernel.cpp:556

◆ operator==()

bool dunedaq::oks::OksQueryExpression::operator== ( const class OksQueryExpression & e) const
inline

Definition at line 116 of file query.hpp.

116{return (this == &e);}

◆ type()

OksQuery::QueryType dunedaq::oks::OksQueryExpression::type ( ) const
inline

Definition at line 114 of file query.hpp.

114{return p_type;}

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & s,
const OksQueryExpression & qe )
friend

Definition at line 778 of file query.cpp.

780{
781 s << '(';
782
783 switch(qe.type()) {
785 OksComparator *cmpr = (OksComparator *)&qe;
786 const OksAttribute *a = cmpr->GetAttribute();
787 OksData *v = cmpr->GetValue();
788 OksQuery::Comparator f = cmpr->GetFunction();
789
790 if(a) {
791 s << '\"' << a->get_name() << "\" ";
792 }
793 else if(v) {
794 s << OksQuery::OID << ' ';
795 }
796 else {
797 s << "(null) ";
798 }
799
800 if(v) {
801 s << *v << ' ';
802 }
803 else {
804 s << "(null) ";
805 }
806
807 if(f) {
809 else if(f == OksQuery::not_equal_cmp) s << OksQuery::NE;
810 else if(f == OksQuery::reg_exp_cmp) s << OksQuery::RE;
813 else if(f == OksQuery::less_cmp) s << OksQuery::LS;
814 else if(f == OksQuery::greater_cmp) s << OksQuery::GT;
815 }
816 else
817 s << "(null)";
818
819 break; }
820
822 OksRelationshipExpression *re = (OksRelationshipExpression *)&qe;
823 const OksRelationship *r = re->GetRelationship();
824 bool b = re->IsCheckAllObjects();
825 OksQueryExpression *rqe = re->get();
826
827 if(r)
828 s << '\"' << r->get_name() << "\" ";
829 else
830 s << "(null) ";
831
832 s << (b == true ? OksQuery::ALL_SUBCLASSES : OksQuery::SOME) << ' ';
833
834 if(rqe) s << *rqe;
835 else s << "(null)";
836
837 break; }
838
840 s << OksQuery::NOT << ' ' << *(((OksNotExpression *)&qe)->get());
841
842 break;
843
844 case OksQuery::and_type: {
845 s << OksQuery::AND << ' ';
846
847 const std::list<OksQueryExpression *> & elist = ((OksAndExpression *)&qe)->expressions();
848
849 if(!elist.empty()) {
850 const OksQueryExpression * last = elist.back();
851
852 for(std::list<OksQueryExpression *>::const_iterator i = elist.begin(); i != elist.end(); ++i) {
853 s << *(*i);
854 if(*i != last) s << ' ';
855 }
856 }
857
858 break;
859 }
860
861 case OksQuery::or_type: {
862 s << OksQuery::OR << ' ';
863
864 const std::list<OksQueryExpression *> & elist = ((OksOrExpression *)&qe)->expressions();
865
866 if(!elist.empty()) {
867 const OksQueryExpression * last = elist.back();
868
869 for(std::list<OksQueryExpression *>::const_iterator i = elist.begin(); i != elist.end(); ++i) {
870 s << *(*i);
871 if(*i != last) s << ' ';
872 }
873 }
874
875 break;
876 }
877
879 s << "(unknown)";
880
881 break;
882 }
883 }
884
885 s << ')';
886
887 return s;
888}
OksQueryExpression(OksQuery::QueryType qet=OksQuery::unknown_type)
Definition query.hpp:121
static const char * ALL_SUBCLASSES
Definition query.hpp:67
static bool equal_cmp(const OksData *, const OksData *)
Definition query.cpp:51
static bool reg_exp_cmp(const OksData *, const OksData *regexp)
Definition query.cpp:57
static bool greater_cmp(const OksData *, const OksData *)
Definition query.cpp:56
static const char * OR
Definition query.hpp:62
static const char * RE
Definition query.hpp:71
static const char * OID
Definition query.hpp:68
static bool less_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:53
static bool not_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:52
static const char * GT
Definition query.hpp:75
static const char * NOT
Definition query.hpp:64
bool(*) Comparator(const OksData *, const OksData *)
Definition query.hpp:88
static const char * SOME
Definition query.hpp:65
static const char * GE
Definition query.hpp:73
static const char * AND
Definition query.hpp:63
static bool greater_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:54
static const char * EQ
Definition query.hpp:69
static bool less_cmp(const OksData *, const OksData *)
Definition query.cpp:55
static const char * LE
Definition query.hpp:72
static const char * NE
Definition query.hpp:70
static const char * LS
Definition query.hpp:74

Member Data Documentation

◆ p_type

const OksQuery::QueryType dunedaq::oks::OksQueryExpression::p_type
private

Definition at line 126 of file query.hpp.


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