RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
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
16namespace Queries {
17
18//! \brief a Query implementing ==: arguments must match a particular
19//! value (within an optional tolerance)
20template <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 =
54 if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) {
55 return !this->getNegation();
56 } else {
57 return this->getNegation();
58 }
59 }
60
73
74 std::string getFullDescription() const override {
75 std::ostringstream res;
76 res << this->getDescription();
77 res << " " << this->d_val;
78 if (this->getNegation()) {
79 res << " != ";
80 } else {
81 res << " = ";
82 }
83 res << "val";
84 return res.str();
85 }
86};
87} // namespace Queries
88#endif
const MatchFuncArgType getVal() const
returns our target value
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const override
returns a copy of this Query
EqualityQuery(MatchFuncArgType v)
constructs with our target value
bool Match(const DataFuncArgType what) const override
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t)
constructs with our target value and a tolerance
void setTol(MatchFuncArgType what)
sets our tolerance
void setVal(MatchFuncArgType what)
sets our target value
const MatchFuncArgType getTol() const
returns out tolerance
std::string getFullDescription() const override
returns a fuller text description
class to allow integer values to pick templates
Definition Query.h:26
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition Query.h:164
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:169
std::string d_queryType
Definition Query.h:153
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition Query.h:94
bool getNegation() const
returns whether or not we are negated
Definition Query.h:61
void setNegation(bool what)
sets whether or not we are negated
Definition Query.h:59
const std::string & getDescription() const
returns our text description
Definition Query.h:70
bool df_negate
Definition Query.h:155
MatchFuncArgType d_tol
Definition Query.h:151
MatchFuncArgType d_val
Definition Query.h:150
std::string d_description
Definition Query.h:152
#define RDKIT_QUERY_EXPORT
Definition export.h:661
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition Query.h:197