10 #ifndef __RD_QUERY_H__ 11 #define __RD_QUERY_H__ 14 #pragma warning(disable : 4800) // warning: converting things to bool 19 #include <boost/smart_ptr.hpp> 43 template <
class MatchFuncArgType,
class DataFuncArgType = MatchFuncArgType,
44 bool needsConversion =
false>
47 typedef boost::shared_ptr<
58 virtual ~Query() { this->d_children.clear(); };
67 this->d_description = descr;
71 this->d_description = std::string(descr);
78 return getDescription();
80 return "not " + getDescription();
85 this->d_matchFunc = what;
88 bool (*
getMatchFunc()
const)(MatchFuncArgType) {
return this->d_matchFunc; };
91 this->d_dataFunc = what;
95 return this->d_dataFunc;
99 void addChild(CHILD_TYPE child) { this->d_children.push_back(child); };
103 CHILD_VECT_CI
endChildren()
const {
return this->d_children.end(); }
106 virtual bool Match(
const DataFuncArgType arg)
const {
109 if (this->d_matchFunc)
110 tRes = this->d_matchFunc(mfArg);
112 tRes =
static_cast<bool>(mfArg);
114 if (this->getNegation())
129 typename Query<MatchFuncArgType, DataFuncArgType,
131 for (iter = this->beginChildren(); iter != this->endChildren(); ++iter) {
145 bool (*d_matchFunc)(MatchFuncArgType);
146 MatchFuncArgType (*d_dataFunc)(DataFuncArgType);
152 MatchFuncArgType mfArg;
153 if (this->d_dataFunc != NULL) {
154 mfArg = this->d_dataFunc(what);
165 MatchFuncArgType mfArg;
166 mfArg = this->d_dataFunc(what);
176 template <
class T1,
class T2>
177 int queryCmp(
const T1 v1,
const T2 v2,
const T1 tol) {
bool getNegation() const
returns whether or not we are negated
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
CHILD_VECT_CI beginChildren() const
returns an iterator for the beginning of our child vector
const std::string & getDescription() const
returns our text description
void setNegation(bool what)
sets whether or not we are negated
CHILD_VECT_CI endChildren() const
returns an iterator for the end of our child vector
boost::shared_ptr< Query< MatchFuncArgType, DataFuncArgType, needsConversion > > CHILD_TYPE
MatchFuncArgType TypeConvert(MatchFuncArgType what, Int2Type< false >) const
calls our dataFunc (if it's set) on what and returns the result, otherwise returns what ...
CHILD_VECT::iterator CHILD_VECT_I
MatchFuncArgType(*)(DataFuncArgType) getDataFunc() const
returns our data function:
void setMatchFunc(bool(*what)(MatchFuncArgType))
sets our match function
virtual bool Match(const DataFuncArgType arg) const
returns whether or not we match the argument
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::const_iterator CHILD_VECT_CI
#define PRECONDITION(expr, mess)
virtual std::string getFullDescription() const
returns a fuller text description
std::string d_description
MatchFuncArgType TypeConvert(DataFuncArgType what, Int2Type< true >) const
calls our dataFunc (which must be set) on what and returns the
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