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> 44 template <
class MatchFuncArgType,
class DataFuncArgType=MatchFuncArgType,
45 bool needsConversion=
false>
48 typedef boost::shared_ptr< Query<MatchFuncArgType, DataFuncArgType, needsConversion> >
CHILD_TYPE;
53 Query() : d_description(
""),df_negate(false),d_matchFunc(NULL),d_dataFunc(NULL){};
54 virtual ~Query() { this->d_children.clear(); };
63 void setDescription(
const std::string &descr) { this->d_description = descr; };
65 void setDescription(
const char *descr) { this->d_description = std::string(descr); };
71 return getDescription();
73 return "not "+getDescription();
77 void setMatchFunc(
bool (*what)(MatchFuncArgType)) { this->d_matchFunc = what; };
79 bool (*
getMatchFunc()
const)(MatchFuncArgType) {
return this->d_matchFunc; };
81 void setDataFunc(MatchFuncArgType (*what)(DataFuncArgType)) { this->d_dataFunc = what; };
83 MatchFuncArgType (*
getDataFunc()
const)(DataFuncArgType) {
return this->d_dataFunc; };
86 void addChild(CHILD_TYPE child) { this->d_children.push_back(child); };
88 CHILD_VECT_CI
beginChildren()
const {
return this->d_children.begin(); }
90 CHILD_VECT_CI
endChildren()
const {
return this->d_children.end(); }
93 virtual bool Match(
const DataFuncArgType arg)
const{
96 if(this->d_matchFunc) tRes = this->d_matchFunc(mfArg);
97 else tRes =
static_cast<bool>(mfArg);
99 if( this->getNegation() )
return !tRes;
113 for(iter=this->beginChildren();
114 iter!=this->endChildren();
129 bool (*d_matchFunc) (MatchFuncArgType);
130 MatchFuncArgType (*d_dataFunc)(DataFuncArgType);
135 MatchFuncArgType mfArg;
136 if( this->d_dataFunc != NULL ){
137 mfArg = this->d_dataFunc(what);
146 MatchFuncArgType mfArg;
147 mfArg = this->d_dataFunc(what);
160 template <
class T1,
class T2>
161 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
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
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)
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)
std::vector< CHILD_TYPE > CHILD_VECT
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 result
Base class for all queries.
void setDescription(const std::string &descr)
sets our text description