RDKit: EqualityQuery.h Source File

| 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>
23 class RDKIT_QUERY_EXPORT EqualityQuery
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
61 Query<MatchFuncArgType, DataFuncArgType, needsConversion> *copy()
62 const override {
63 EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
64 new EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
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
Query.h
Queries::EqualityQuery::getVal
const MatchFuncArgType getVal() const
returns our target value
Definition EqualityQuery.h:44
Queries::EqualityQuery::copy
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const override
returns a copy of this Query
Definition EqualityQuery.h:61
Queries::EqualityQuery::EqualityQuery
EqualityQuery(MatchFuncArgType v)
constructs with our target value
Definition EqualityQuery.h:29
Queries::EqualityQuery::Match
bool Match(const DataFuncArgType what) const override
Definition EqualityQuery.h:51
Queries::EqualityQuery::EqualityQuery
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t)
constructs with our target value and a tolerance
Definition EqualityQuery.h:35
Queries::EqualityQuery::setTol
void setTol(MatchFuncArgType what)
sets our tolerance
Definition EqualityQuery.h:47
Queries::EqualityQuery::EqualityQuery
EqualityQuery()
Definition EqualityQuery.h:26
Queries::EqualityQuery::setVal
void setVal(MatchFuncArgType what)
sets our target value
Definition EqualityQuery.h:42
Queries::EqualityQuery::getTol
const MatchFuncArgType getTol() const
returns out tolerance
Definition EqualityQuery.h:49
Queries::EqualityQuery::getFullDescription
std::string getFullDescription() const override
returns a fuller text description
Definition EqualityQuery.h:74
Queries::Int2Type
class to allow integer values to pick templates
Definition Query.h:26
Queries::Query::d_dataFunc
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition Query.h:164
Queries::Query::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:169
Queries::Query::d_queryType
std::string d_queryType
Definition Query.h:153
Queries::Query::setDataFunc
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition Query.h:94
Queries::Query::getNegation
bool getNegation() const
returns whether or not we are negated
Definition Query.h:61
Queries::Query::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition Query.h:59
Queries::Query::getDescription
const std::string & getDescription() const
returns our text description
Definition Query.h:70
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::Query
Query()
Definition Query.h:55
Queries::Query::df_negate
bool df_negate
Definition Query.h:155
Queries::Query::d_tol
MatchFuncArgType d_tol
Definition Query.h:151
Queries::Query::d_val
MatchFuncArgType d_val
Definition Query.h:150
Queries::Query::d_description
std::string d_description
Definition Query.h:152
export.h
RDKIT_QUERY_EXPORT
#define RDKIT_QUERY_EXPORT
Definition export.h:661
Queries
Definition AndQuery.h:16
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition Query.h:197