/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #ifndef RULES_H 00002 #define RULES_H 00003 00004 #include <string> 00005 #include "RuleParser/Queriable.h" 00006 00007 00013 00014 namespace RuleParser{ 00015 00018 00019 00020 class Rule 00021 { 00022 public: 00023 virtual ~Rule() { if(mA) delete mA; if(mB) delete mB; }; 00024 virtual bool select(const Queriable*) = 0; 00025 virtual const std::string& name() const { return m_name; }; 00026 00027 protected: 00028 Rule( std::string name = "unnamed rule", 00029 Rule* a=0, Rule* b=0) 00030 : m_name(name), mA(a), mB(b) {}; 00031 std::string m_name; 00032 Rule* mA; 00033 Rule* mB; 00034 }; 00036 00037 00038 00043 00044 class AnyRule : public Rule 00045 { 00046 public: 00047 AnyRule(std::string n = "AnyRule") : Rule(n) {}; 00048 virtual ~AnyRule() {}; 00049 virtual bool select(const Queriable*) { return true; }; 00050 }; 00052 00053 00054 00059 00060 class NoneRule : public Rule 00061 { 00062 public: 00063 NoneRule(std::string n = "NoneRule") : Rule(n) {}; 00064 virtual ~NoneRule() {}; 00065 virtual bool select(const Queriable*) { return false; }; 00066 }; 00068 00069 00070 00075 00076 class AndRule : public Rule 00077 { 00078 public: 00079 AndRule(std::string n, 00080 Rule* a, Rule* b) : Rule(n,a,b) {}; 00081 virtual ~AndRule() {}; 00082 virtual bool select(const Queriable* thing) { 00083 if(this->mA->select(thing)) return this->mB->select(thing); 00084 return false; 00085 }; 00086 }; 00088 00089 00090 00095 class OrRule : public Rule 00096 { 00097 public: 00098 00099 OrRule(std::string n, 00100 Rule* a, Rule* b) : Rule(n,a,b) {}; 00101 virtual ~OrRule() {}; 00102 virtual bool select(const Queriable* thing) { 00103 if(this->mA->select(thing)) return true; 00104 return this->mB->select(thing); 00105 }; 00106 }; 00108 00109 00110 00115 class NotRule : public Rule 00116 { 00117 public: 00118 00119 NotRule(std::string n, 00120 Rule* a) : Rule(n,a) {}; 00121 virtual ~NotRule() {}; 00122 virtual bool select(const Queriable* thing) { 00123 return (! this->mA->select(thing) ); 00124 }; 00125 }; 00127 00128 00133 template<typename Type> 00134 class LT_Rule : public Rule 00135 { 00136 public: 00137 00138 LT_Rule(std::string n, 00139 int whichParam,Type value) 00140 : Rule(n) 00141 , mParameterId(whichParam),mCut(value) {}; 00142 virtual ~LT_Rule() {}; 00143 virtual bool select(const Queriable* thing) { 00144 Type value; 00145 thing->queryParam(mParameterId,value); 00146 if(value < mCut) return true; 00147 return false; 00148 } 00149 protected: 00150 int mParameterId; 00151 Type mCut; 00152 }; 00154 00155 00160 template<typename Type> 00161 class LE_Rule : public Rule 00162 { 00163 public: 00164 00165 LE_Rule(std::string n, 00166 int whichParam,Type value) 00167 : Rule(n) 00168 , mParameterId(whichParam),mCut(value) {}; 00169 virtual ~LE_Rule() {}; 00170 virtual bool select(const Queriable* thing) { 00171 Type value; 00172 thing->queryParam(mParameterId,value); 00173 if(value <= mCut) return true; 00174 return false; 00175 } 00176 protected: 00177 int mParameterId; 00178 Type mCut; 00179 }; 00181 00182 00187 template<typename Type> 00188 class GT_Rule : public Rule 00189 { 00190 public: 00191 00192 GT_Rule(std::string n, 00193 int whichParam,Type value) 00194 : Rule(n) 00195 , mParameterId(whichParam),mCut(value) {}; 00196 virtual ~GT_Rule() {}; 00197 virtual bool select(const Queriable* thing) { 00198 Type value; 00199 thing->queryParam(mParameterId,value); 00200 if(value > mCut) return true; 00201 return false; 00202 } 00203 protected: 00204 int mParameterId; 00205 Type mCut; 00206 }; 00208 00209 00214 template<typename Type> 00215 class GE_Rule : public Rule 00216 { 00217 public: 00218 00219 GE_Rule(std::string n, 00220 int whichParam,Type value) 00221 : Rule(n) 00222 , mParameterId(whichParam),mCut(value) {}; 00223 virtual ~GE_Rule() {}; 00224 virtual bool select(const Queriable* thing) { 00225 Type value; 00226 thing->queryParam(mParameterId,value); 00227 if(value >= mCut) return true; 00228 return false; 00229 } 00230 protected: 00231 int mParameterId; 00232 Type mCut; 00233 }; 00235 00236 00241 template<typename Type> 00242 class EQ_Rule : public Rule 00243 { 00244 public: 00245 00246 EQ_Rule(std::string n, 00247 int whichParam,Type value) 00248 : Rule(n) 00249 , mParameterId(whichParam),mCut(value) {}; 00250 virtual ~EQ_Rule() {}; 00251 virtual bool select(const Queriable* thing) { 00252 Type value; 00253 thing->queryParam(mParameterId,value); 00254 if(value == mCut) return true; 00255 return false; 00256 } 00257 protected: 00258 int mParameterId; 00259 Type mCut; 00260 }; 00262 00263 00268 template<typename Type> 00269 class NEQ_Rule : public Rule 00270 { 00271 public: 00272 00273 NEQ_Rule(std::string n, 00274 int whichParam,Type value) 00275 : Rule(n) 00276 , mParameterId(whichParam),mCut(value) {}; 00277 virtual ~NEQ_Rule() {}; 00278 virtual bool select(const Queriable* thing) { 00279 Type value; 00280 thing->queryParam(mParameterId,value); 00281 if(value != mCut) return true; 00282 return false; 00283 } 00284 protected: 00285 int mParameterId; 00286 Type mCut; 00287 }; 00289 00290 } 00291 00292 00293 #endif 00294