00001
00002
00003
00004
00005
00006 #ifndef __RD_RANGEQUERY_H__
00007 #define __RD_RANGEQUERY_H__
00008 #include "Query.h"
00009 #include <utility>
00010
00011 namespace Queries {
00012
00013
00014
00015
00016
00017
00018
00019
00020 template <class MatchFuncArgType, class DataFuncArgType=MatchFuncArgType,
00021 bool needsConversion=false>
00022 class RangeQuery :
00023 public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
00024
00025 public:
00026 RangeQuery() : d_upper(0), d_lower(0), d_tol(0), df_upperOpen(true), df_lowerOpen(true){
00027 this->df_negate = false;
00028 };
00029
00030 RangeQuery(MatchFuncArgType lower,MatchFuncArgType upper) : d_upper(upper), d_lower(lower), d_tol(0), df_upperOpen(true), df_lowerOpen(true){
00031 this->df_negate = false;
00032 };
00033
00034
00035 void setUpper (MatchFuncArgType what) { this->d_upper = what; };
00036
00037 const MatchFuncArgType getUpper() const { return this->d_upper; };
00038
00039 void setLower (MatchFuncArgType what) { this->d_lower = what; };
00040
00041 const MatchFuncArgType getLower() const { return this->d_lower; };
00042
00043
00044 void setEndsOpen(bool lower, bool upper) {
00045 this->df_lowerOpen = lower;
00046 this->df_upperOpen = upper;
00047 };
00048
00049 std::pair<bool,bool> getEndsOpen() const {
00050 return std::make_pair(this->df_lowerOpen,this->df_upperOpen);
00051 };
00052
00053
00054 void setTol(MatchFuncArgType what) { this->d_tol = what; };
00055
00056 const MatchFuncArgType getTol() const { return this->d_tol; };
00057
00058 bool Match(const DataFuncArgType what) const {
00059 MatchFuncArgType mfArg = TypeConvert(what,Int2Type<needsConversion>());
00060 int lCmp = queryCmp(this->d_lower,mfArg,this->d_tol);
00061 int uCmp = queryCmp(this->d_upper,mfArg,this->d_tol);
00062 bool lowerRes,upperRes;
00063 if( this->df_lowerOpen ) lowerRes = lCmp < 0;
00064 else lowerRes = lCmp <= 0;
00065 if( this->df_upperOpen ) upperRes = uCmp > 0;
00066 else upperRes = uCmp >= 0;
00067
00068 bool tempR = !(lowerRes && upperRes);
00069 if( this->getNegation() ) return tempR;
00070 else return !tempR;
00071 };
00072
00073 Query<MatchFuncArgType,DataFuncArgType,needsConversion> *
00074 copy( ) const {
00075 RangeQuery<MatchFuncArgType,DataFuncArgType,needsConversion> *res =
00076 new RangeQuery<MatchFuncArgType,DataFuncArgType,needsConversion>();
00077 res->setUpper(this->d_upper);
00078 res->setLower(this->d_lower);
00079 res->setTol(this->d_tol);
00080 res->setNegation(this->getNegation());
00081 res->setEndsOpen(this->df_lowerOpen,this->df_upperOpen);
00082 res->setDataFunc(this->d_dataFunc);
00083 res->d_description = this->d_description;
00084 return res;
00085 };
00086
00087 protected:
00088 MatchFuncArgType d_upper,d_lower;
00089 MatchFuncArgType d_tol;
00090 bool df_upperOpen,df_lowerOpen;
00091 };
00092
00093 }
00094 #endif