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
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 =
53 this->TypeConvert(what, Int2Type<needsConversion>());
54 if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) {
55 return !this->getNegation();
56 } else {
57 return this->getNegation();
58 }
59 }
60
62 const override {
65 res->setNegation(this->getNegation());
66 res->setVal(this->d_val);
67 res->setTol(this->d_tol);
68 res->setDataFunc(this->d_dataFunc);
69 res->d_description = this->d_description;
70 res->d_queryType = this->d_queryType;
71 return res;
72 }
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
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:61
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:74
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:153
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:94
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:59
std::string d_description
Definition: Query.h:152
#define RDKIT_QUERY_EXPORT
Definition: export.h:565
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:197