11 #ifndef __RD_QUERY_H__ 12 #define __RD_QUERY_H__ 15 #pragma warning(disable : 4800) // warning: converting things to bool 20 #include <boost/smart_ptr.hpp> 44 template <
class MatchFuncArgType,
class DataFuncArgType = MatchFuncArgType,
45 bool needsConversion =
false>
48 typedef boost::shared_ptr<
60 virtual ~Query() { this->d_children.clear(); };
69 this->d_description = descr;
73 this->d_description = std::string(descr);
80 return getDescription();
82 return "not " + getDescription();
87 this->d_matchFunc = what;
90 bool (*
getMatchFunc()
const)(MatchFuncArgType) {
return this->d_matchFunc; };
93 this->d_dataFunc = what;
97 return this->d_dataFunc;
105 CHILD_VECT_CI
endChildren()
const {
return this->d_children.end(); }
108 virtual bool Match(
const DataFuncArgType arg)
const {
111 if (this->d_matchFunc)
112 tRes = this->d_matchFunc(mfArg);
114 tRes =
static_cast<bool>(mfArg);
116 if (this->getNegation())
131 for (
auto iter = this->beginChildren(); iter != this->endChildren();
135 res->
d_val = this->d_val;
136 res->
d_tol = this->d_tol;
145 MatchFuncArgType d_val = 0;
146 MatchFuncArgType d_tol = 0;
150 bool (*d_matchFunc)(MatchFuncArgType);
158 MatchFuncArgType (*d_dataFunc)(DataFuncArgType);
159 MatchFuncArgType (*d_dataFuncSameType)(MatchFuncArgType);
165 MatchFuncArgType mfArg;
166 if (this->d_dataFuncSameType != NULL &&
167 std::is_same<MatchFuncArgType, DataFuncArgType>::value) {
168 mfArg = this->d_dataFuncSameType(what);
179 MatchFuncArgType mfArg;
180 mfArg = this->d_dataFunc(what);
190 template <
class T1,
class T2>
191 int queryCmp(
const T1 v1,
const T2 v2,
const T1 tol) {
virtual std::string getFullDescription() const
returns a fuller text description
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
virtual bool Match(const DataFuncArgType arg) const
returns whether or not we match the argument
void setNegation(bool what)
sets whether or not we are negated
MatchFuncArgType TypeConvert(DataFuncArgType what, Int2Type< true >) const
calls our dataFunc (which must be set) on what and returns the
boost::shared_ptr< Query< MatchFuncArgType, DataFuncArgType, needsConversion > > CHILD_TYPE
bool getNegation() const
returns whether or not we are negated
CHILD_VECT::iterator CHILD_VECT_I
MatchFuncArgType(*)(DataFuncArgType) getDataFunc() const
returns our data function:
CHILD_VECT_CI endChildren() const
returns an iterator for the end of our child vector
void setMatchFunc(bool(*what)(MatchFuncArgType))
sets our match function
bool(* d_matchFunc)(MatchFuncArgType)
std::vector< CHILD_TYPE > CHILD_VECT
class to allow integer values to pick templates
void setDescription(const char *descr)
void addChild(CHILD_TYPE child)
adds a child to our list of children
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
bool(*)(MatchFuncArgType) getMatchFunc() const
returns our match function:
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
CHILD_VECT_CI beginChildren() const
returns an iterator for the beginning of our child vector
CHILD_VECT::const_iterator CHILD_VECT_CI
#define PRECONDITION(expr, mess)
std::string d_description
const std::string & getDescription() const
returns our text description
MatchFuncArgType TypeConvert(MatchFuncArgType what, Int2Type< false >) const
calls our dataFunc (if it's set) on what and returns the result, otherwise returns what ...
Base class for all queries.
void setDescription(const std::string &descr)
sets our text description
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query