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<
59 virtual ~Query() { this->d_children.clear(); };
68 this->d_description = descr;
72 this->d_description = std::string(descr);
79 return getDescription();
81 return "not " + getDescription();
86 this->d_matchFunc = what;
89 bool (*
getMatchFunc()
const)(MatchFuncArgType) {
return this->d_matchFunc; };
92 this->d_dataFunc = what;
96 return this->d_dataFunc;
100 void addChild(CHILD_TYPE child) { this->d_children.push_back(child); };
104 CHILD_VECT_CI
endChildren()
const {
return this->d_children.end(); }
107 virtual bool Match(
const DataFuncArgType arg)
const {
110 if (this->d_matchFunc)
111 tRes = this->d_matchFunc(mfArg);
113 tRes =
static_cast<bool>(mfArg);
115 if (this->getNegation())
130 typename Query<MatchFuncArgType, DataFuncArgType,
132 for (iter = this->beginChildren(); iter != this->endChildren(); ++iter) {
146 bool (*d_matchFunc)(MatchFuncArgType);
153 MatchFuncArgType (*d_dataFunc)(DataFuncArgType);
154 MatchFuncArgType (*d_dataFuncSameType)(MatchFuncArgType);
160 MatchFuncArgType mfArg;
161 if (this->d_dataFuncSameType != NULL && std::is_same<MatchFuncArgType, DataFuncArgType>::value) {
162 mfArg = this->d_dataFuncSameType(what);
173 MatchFuncArgType mfArg;
174 mfArg = this->d_dataFunc(what);
184 template <
class T1,
class T2>
185 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