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 //! \brief a Query implementing ==: arguments must match a particular
18 //! value (within an optional tolerance)
19 template <typename MatchFuncArgType,
20  typename DataFuncArgType = MatchFuncArgType,
21  bool needsConversion = false>
23  : public Query<MatchFuncArgType, DataFuncArgType, needsConversion> {
24  public:
25  EqualityQuery() : d_tol(0) { this->df_negate = false; };
26 
27  //! constructs with our target value
28  explicit EqualityQuery(MatchFuncArgType v) : d_val(v), d_tol(0) {
29  this->df_negate = false;
30  };
31 
32  //! constructs with our target value and a tolerance
33  EqualityQuery(MatchFuncArgType v, MatchFuncArgType t) : d_val(v), d_tol(t) {
34  this->df_negate = false;
35  };
36 
37  //! sets our target value
38  void setVal(MatchFuncArgType what) { this->d_val = what; };
39  //! returns our target value
40  const MatchFuncArgType getVal() const { return this->d_val; };
41 
42  //! sets our tolerance
43  void setTol(MatchFuncArgType what) { this->d_tol = what; };
44  //! returns out tolerance
45  const MatchFuncArgType getTol() const { return this->d_tol; };
46 
47  virtual bool Match(const DataFuncArgType what) const {
48  MatchFuncArgType mfArg =
50  if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) {
51  if (this->getNegation()) {
52  return false;
53  } else {
54  return true;
55  }
56  } else {
57  if (this->getNegation()) {
58  return true;
59  } else {
60  return false;
61  }
62  }
63  };
64 
66  const {
69  res->setNegation(this->getNegation());
70  res->setVal(this->d_val);
71  res->setTol(this->d_tol);
72  res->setDataFunc(this->d_dataFunc);
73  res->d_description = this->d_description;
74  return res;
75  };
76 
77  std::string getFullDescription() const {
78  std::ostringstream res;
79  res << this->getDescription();
80  res << " " << this->d_val;
81  if (this->getNegation())
82  res << " != ";
83  else
84  res << " = ";
85  res << "val";
86  return res.str();
87  }
88 
89  protected:
90  MatchFuncArgType d_val;
91  MatchFuncArgType d_tol;
92 };
93 }
94 #endif
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:63
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:177
const std::string & getDescription() const
returns our text description
Definition: Query.h:74
std::string getFullDescription() const
returns a fuller text description
Definition: EqualityQuery.h:77
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:61
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:43
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:150
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
Definition: EqualityQuery.h:65
virtual bool Match(const DataFuncArgType what) const
returns whether or not we match the argument
Definition: EqualityQuery.h:47
const MatchFuncArgType getVal() const
returns our target value
Definition: EqualityQuery.h:40
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:38
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:33
MatchFuncArgType d_tol
Definition: EqualityQuery.h:91
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:146
a Query implementing ==: arguments must match a particular value (within an optional tolerance) ...
Definition: EqualityQuery.h:22
bool df_negate
Definition: Query.h:144
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:90
std::string d_description
Definition: Query.h:139
Base class for all queries.
Definition: Query.h:45
MatchFuncArgType d_val
Definition: EqualityQuery.h:90
EqualityQuery(MatchFuncArgType v)
constructs with our target value
Definition: EqualityQuery.h:28
const MatchFuncArgType getTol() const
returns out tolerance
Definition: EqualityQuery.h:45