RDKit
Open-source cheminformatics and machine learning.
EqualityQuery.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2003-2006 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef __RD_EQUALITYQUERY_H__
11 #define __RD_EQUALITYQUERY_H__
12 #include "Query.h"
13 #include <sstream>
14 
15 namespace Queries {
16 
17 
18  //! \brief a Query implementing ==: arguments must match a particular
19  //! value (within an optional tolerance)
20  template <typename MatchFuncArgType, typename DataFuncArgType=MatchFuncArgType,
21  bool needsConversion=false>
22  class EqualityQuery : public Query<MatchFuncArgType, DataFuncArgType,needsConversion> {
23 
24  public:
26  this->df_negate=false;
27  };
28 
29  //! constructs with our target value
30  explicit EqualityQuery(MatchFuncArgType v) : d_val(v), d_tol(0) {
31  this->df_negate=false;
32  };
33 
34 
35  //! constructs with our target value and a tolerance
36  EqualityQuery(MatchFuncArgType v,MatchFuncArgType t) : d_val(v), d_tol(t) {
37  this->df_negate=false;
38  };
39 
40 
41  //! sets our target value
42  void setVal(MatchFuncArgType what) { this->d_val = what; };
43  //! returns our target value
44  const MatchFuncArgType getVal() const { return this->d_val; };
45 
46  //! sets our tolerance
47  void setTol(MatchFuncArgType what) { this->d_tol = what; };
48  //! returns out tolerance
49  const MatchFuncArgType getTol() const { return this->d_tol; };
50 
51  virtual bool Match(const DataFuncArgType what) const {
52  MatchFuncArgType mfArg = this->TypeConvert(what,Int2Type<needsConversion>());
53  if( queryCmp(this->d_val,mfArg,this->d_tol) == 0 ){
54  if( this->getNegation() ){
55  return false;
56  }
57  else{
58  return true;
59  }
60  } else {
61  if( this->getNegation() ){
62  return true;
63  }
64  else{
65  return false;
66  }
67  }
68  };
69 
71  copy( ) const {
74  res->setNegation(this->getNegation());
75  res->setVal(this->d_val);
76  res->setTol(this->d_tol);
77  res->setDataFunc(this->d_dataFunc);
78  res->d_description = this->d_description;
79  return res;
80  };
81 
82  std::string getFullDescription() const {
83  std::ostringstream res;
84  res<<this->getDescription();
85  res<<" "<<this->d_val;
86  if(this->getNegation()) res<<" != ";
87  else res<<" = ";
88  res<<"val";
89  return res.str();
90  }
91 
92  protected:
93  MatchFuncArgType d_val;
94  MatchFuncArgType d_tol;
95  };
96 
97 }
98 #endif
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:60
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:161
const std::string & getDescription() const
returns our text description
Definition: Query.h:67
std::string getFullDescription() const
returns a fuller text description
Definition: EqualityQuery.h:82
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:58
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:47
MatchFuncArgType TypeConvert(MatchFuncArgType what, Int2Type< false >) const
calls our dataFunc (if it&#39;s set) on what and returns the result, otherwise returns what ...
Definition: Query.h:134
virtual bool Match(const DataFuncArgType what) const
returns whether or not we match the argument
Definition: EqualityQuery.h:51
const MatchFuncArgType getVal() const
returns our target value
Definition: EqualityQuery.h:44
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:42
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
Definition: EqualityQuery.h:71
class to allow integer values to pick templates
Definition: Query.h:26
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t)
constructs with our target value and a tolerance
Definition: EqualityQuery.h:36
MatchFuncArgType d_tol
Definition: EqualityQuery.h:94
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:130
a Query implementing ==: arguments must match a particular value (within an optional tolerance) ...
Definition: EqualityQuery.h:22
bool df_negate
Definition: Query.h:128
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:81
std::string d_description
Definition: Query.h:123
Base class for all queries.
Definition: Query.h:46
MatchFuncArgType d_val
Definition: EqualityQuery.h:93
EqualityQuery(MatchFuncArgType v)
constructs with our target value
Definition: EqualityQuery.h:30
const MatchFuncArgType getTol() const
returns out tolerance
Definition: EqualityQuery.h:49