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