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