RDCode: EqualityQuery.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Directories

# EqualityQuery.h

Go to the documentation of this file.

    00001 //
    00002 // Copyright (c) 2003-2006 Greg Landrum and Rational Discovery LLC
    00003 //
    00004 //   @@ All Rights Reserved  @@
    00005 //
    00006 #ifndef __RD_EQUALITYQUERY_H__
    00007 #define __RD_EQUALITYQUERY_H__
    00008 #include "Query.h"
    00009
    00010 namespace Queries {
    00011
    00012
    00013   //! \brief a Query implementing ==: arguments must match a particular
    00014   //!  value (within an optional tolerance)
    00015   template <typename MatchFuncArgType, typename DataFuncArgType=MatchFuncArgType,
    00016     bool needsConversion=false>
    00017   class EqualityQuery : public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
    00018
    00019   public:
    00020     EqualityQuery() : d_tol(0) {
    00021       this->df_negate=false;
    00022     };
    00023
    00024     //! constructs with our target value
    00025     explicit EqualityQuery(MatchFuncArgType v) : d_val(v), d_tol(0) {
    00026       this->df_negate=false;
    00027     };
    00028
    00029
    00030     //! constructs with our target value and a tolerance
    00031     EqualityQuery(MatchFuncArgType v,MatchFuncArgType t) : d_val(v), d_tol(t) {
    00032       this->df_negate=false;
    00033     };
    00034
    00035
    00036     //! sets our target value
    00037     void setVal(MatchFuncArgType what) { this->d_val = what; };
    00038     //! returns our target value
    00039     const MatchFuncArgType getVal() const { return this->d_val; };
    00040
    00041     //! sets our tolerance
    00042     void setTol(MatchFuncArgType what) { this->d_tol = what; };
    00043     //! returns out tolerance
    00044     const MatchFuncArgType getTol() const { return this->d_tol; };
    00045
    00046     virtual bool Match(const DataFuncArgType what) const {
    00047       MatchFuncArgType mfArg = TypeConvert(what,Int2Type<needsConversion>());
    00048       if( queryCmp(this->d_val,mfArg,this->d_tol) == 0 ){
    00049         if( this->getNegation() ){
    00050           return false;
    00051         }
    00052         else{
    00053           return true;
    00054         }
    00055       } else {
    00056         if( this->getNegation() ){
    00057           return true;
    00058         }
    00059         else{
    00060           return false;
    00061         }
    00062       }
    00063     };
    00064
    00065     virtual Query<MatchFuncArgType,DataFuncArgType,needsConversion> *
    00066     copy( ) const {
    00067       EqualityQuery<MatchFuncArgType,DataFuncArgType,needsConversion> *res =
    00068         new EqualityQuery<MatchFuncArgType,DataFuncArgType,needsConversion>();
    00069       res->setNegation(this->getNegation());
    00070       res->setVal(this->d_val);
    00071       res->setTol(this->d_tol);
    00072       res->setDataFunc(this->d_dataFunc);
    00073       res->d_description = this->d_description;
    00074       return res;
    00075     };
    00076
    00077   protected:
    00078     MatchFuncArgType d_val;
    00079     MatchFuncArgType d_tol;
    00080   };
    00081
    00082 }
    00083 #endif