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() { 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  virtual bool Match(const DataFuncArgType what) const {
52  MatchFuncArgType mfArg =
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 {
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  return res;
79  };
80 
81  std::string getFullDescription() const {
82  std::ostringstream res;
83  res << this->getDescription();
84  res << " " << this->d_val;
85  if (this->getNegation())
86  res << " != ";
87  else
88  res << " = ";
89  res << "val";
90  return res.str();
91  }
92 };
93 } // namespace Queries
94 #endif
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::df_negate
bool df_negate
Definition: Query.h:149
Queries::EqualityQuery::setVal
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:42
Queries::EqualityQuery::EqualityQuery
EqualityQuery(MatchFuncArgType v)
constructs with our target value
Definition: EqualityQuery.h:29
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:63
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:191
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::d_val
MatchFuncArgType d_val
Definition: Query.h:145
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::d_dataFunc
MatchFuncArgType(* d_dataFunc)(MatchFuncArgType)
Definition: Query.h:158
Queries::EqualityQuery::getFullDescription
std::string getFullDescription() const
Definition: EqualityQuery.h:81
Query.h
Queries::EqualityQuery::EqualityQuery
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t)
constructs with our target value and a tolerance
Definition: EqualityQuery.h:35
Queries
Definition: AndQuery.h:16
Queries::EqualityQuery::Match
virtual bool Match(const DataFuncArgType what) const
Definition: EqualityQuery.h:51
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::d_description
std::string d_description
Definition: Query.h:147
Queries::EqualityQuery::EqualityQuery
EqualityQuery()
Definition: EqualityQuery.h:26
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::setDataFunc
void setDataFunc(MatchFuncArgType(*what)(MatchFuncArgType))
sets our data function
Definition: Query.h:92
Queries::EqualityQuery::copy
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
Definition: EqualityQuery.h:69
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::getNegation
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:65
Queries::Int2Type
class to allow integer values to pick templates
Definition: Query.h:27
Queries::EqualityQuery::getTol
const MatchFuncArgType getTol() const
returns out tolerance
Definition: EqualityQuery.h:49
Queries::EqualityQuery::getVal
const MatchFuncArgType getVal() const
returns our target value
Definition: EqualityQuery.h:44
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::TypeConvert
MatchFuncArgType TypeConvert(MatchFuncArgType what, Int2Type< false >) const
calls our dataFunc (if it's set) on what and returns the result, otherwise returns what
Definition: Query.h:163
Queries::EqualityQuery::setTol
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:47
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::d_tol
MatchFuncArgType d_tol
Definition: Query.h:146
Queries::Query
Base class for all queries.
Definition: Query.h:46
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::getDescription
const std::string & getDescription() const
returns our text description
Definition: Query.h:76
Queries::EqualityQuery
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
Definition: EqualityQuery.h:23
export.h