RDKit
Open-source cheminformatics and machine learning.
EqualityQuery.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2003-2020 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() { this->df_negate = false; }
27 
28  //! constructs with our target value
29  explicit EqualityQuery(MatchFuncArgType v) {
30  this->d_val = v;
31  this->df_negate = false;
32  }
33 
34  //! constructs with our target value and a tolerance
35  EqualityQuery(MatchFuncArgType v, MatchFuncArgType t) {
36  this->d_val = v;
37  this->d_tol = t;
38  this->df_negate = false;
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  bool Match(const DataFuncArgType what) const override {
52  MatchFuncArgType mfArg =
53  this->TypeConvert(what, Int2Type<needsConversion>());
54  if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) {
55  if (this->getNegation()) {
56  return false;
57  } else {
58  return true;
59  }
60  } else {
61  if (this->getNegation()) {
62  return true;
63  } else {
64  return false;
65  }
66  }
67  }
68 
70  const override {
73  res->setNegation(this->getNegation());
74  res->setVal(this->d_val);
75  res->setTol(this->d_tol);
76  res->setDataFunc(this->d_dataFunc);
77  res->d_description = this->d_description;
78  res->d_queryType = this->d_queryType;
79  return res;
80  }
81 
82  std::string getFullDescription() const override {
83  std::ostringstream res;
84  res << this->getDescription();
85  res << " " << this->d_val;
86  if (this->getNegation())
87  res << " != ";
88  else
89  res << " = ";
90  res << "val";
91  return res.str();
92  }
93 };
94 } // namespace Queries
95 #endif
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
Definition: EqualityQuery.h:24
const MatchFuncArgType getVal() const
returns our target value
Definition: EqualityQuery.h:44
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const override
returns a copy of this Query
Definition: EqualityQuery.h:69
EqualityQuery(MatchFuncArgType v)
constructs with our target value
Definition: EqualityQuery.h:29
bool Match(const DataFuncArgType what) const override
Definition: EqualityQuery.h:51
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t)
constructs with our target value and a tolerance
Definition: EqualityQuery.h:35
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:47
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:42
const MatchFuncArgType getTol() const
returns out tolerance
Definition: EqualityQuery.h:49
std::string getFullDescription() const override
returns a fuller text description
Definition: EqualityQuery.h:82
class to allow integer values to pick templates
Definition: Query.h:26
Base class for all queries.
Definition: Query.h:45
std::string d_queryType
Definition: Query.h:150
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:93
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:59
std::string d_description
Definition: Query.h:149
#define RDKIT_QUERY_EXPORT
Definition: export.h:549
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:194