RDKit: EqualityQuery.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 #ifndef __RD_EQUALITYQUERY_H__
11 #define __RD_EQUALITYQUERY_H__
12 #include "Query.h"
13 #include <sstream>
14
15 namespace Queries {
16
17 //! \brief a Query implementing ==: arguments must match a particular
18 //! value (within an optional tolerance)
19 template <typename MatchFuncArgType,
20 typename DataFuncArgType = MatchFuncArgType,
21 bool needsConversion = false>
22 class EqualityQuery
23 : public Query<MatchFuncArgType, DataFuncArgType, needsConversion> {
24 public:
25 EqualityQuery() : d_tol(0) { this->df_negate = false; };
26
27 //! constructs with our target value
28 explicit EqualityQuery(MatchFuncArgType v) : d_val(v), d_tol(0) {
29 this->df_negate = false;
30 };
31
32 //! constructs with our target value and a tolerance
33 EqualityQuery(MatchFuncArgType v, MatchFuncArgType t) : d_val(v), d_tol(t) {
34 this->df_negate = false;
35 };
36
37 //! sets our target value
38 void setVal(MatchFuncArgType what) { this->d_val = what; };
39 //! returns our target value
40 const MatchFuncArgType getVal() const { return this->d_val; };
41
42 //! sets our tolerance
43 void setTol(MatchFuncArgType what) { this->d_tol = what; };
44 //! returns out tolerance
45 const MatchFuncArgType getTol() const { return this->d_tol; };
46
47 virtual bool Match(const DataFuncArgType what) const {
48 MatchFuncArgType mfArg =
49 this->TypeConvert(what, Int2Type<needsConversion>());
50 if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) {
51 if (this->getNegation()) {
52 return false;
53 } else {
54 return true;
55 }
56 } else {
57 if (this->getNegation()) {
58 return true;
59 } else {
60 return false;
61 }
62 }
63 };
64
65 virtual Query<MatchFuncArgType, DataFuncArgType, needsConversion> *copy()
66 const {
67 EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
68 new EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
69 res->setNegation(this->getNegation());
70 res->setVal(this->d_val);
71 res->setTol(this->d_tol);
72 res->setDataFunc(this->d_dataFunc);
73 res->d_description = this->d_description;
74 return res;
75 };
76
77 std::string getFullDescription() const {
78 std::ostringstream res;
79 res << this->getDescription();
80 res << " " << this->d_val;
81 if (this->getNegation())
82 res << " != ";
83 else
84 res << " = ";
85 res << "val";
86 return res.str();
87 }
88
89 protected:
90 MatchFuncArgType d_val;
91 MatchFuncArgType d_tol;
92 };
93 }
94 #endif
Queries::Query::getNegation
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:63
Queries
Definition: AndQuery.h:15
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:177
Queries::Query::getDescription
const std::string & getDescription() const
returns our text description
Definition: Query.h:74
Queries::EqualityQuery::EqualityQuery
EqualityQuery()
Definition: EqualityQuery.h:25
Queries::EqualityQuery::getFullDescription
std::string getFullDescription() const
returns a fuller text description
Definition: EqualityQuery.h:77
Queries::Query::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:61
Queries::EqualityQuery::setTol
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:43
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:150
Queries::EqualityQuery::copy
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
Definition: EqualityQuery.h:65
Queries::EqualityQuery::Match
virtual bool Match(const DataFuncArgType what) const
returns whether or not we match the argument
Definition: EqualityQuery.h:47
Query.h
Queries::EqualityQuery::getVal
const MatchFuncArgType getVal() const
returns our target value
Definition: EqualityQuery.h:40
Queries::EqualityQuery::setVal
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:38
Queries::Int2Type
class to allow integer values to pick templates
Definition: Query.h:26
Queries::EqualityQuery::EqualityQuery
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t)
constructs with our target value and a tolerance
Definition: EqualityQuery.h:33
Queries::EqualityQuery::d_tol
MatchFuncArgType d_tol
Definition: EqualityQuery.h:91
Queries::Query::d_dataFunc
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:146
Queries::EqualityQuery
a Query implementing ==: arguments must match a particular value (within an optional tolerance) ...
Definition: EqualityQuery.h:22
Queries::Query::df_negate
bool df_negate
Definition: Query.h:144
Queries::Query::setDataFunc
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:90
Queries::Query::d_description
std::string d_description
Definition: Query.h:139
Queries::Query
Base class for all queries.
Definition: Query.h:45
Queries::EqualityQuery::d_val
MatchFuncArgType d_val
Definition: EqualityQuery.h:90
Queries::EqualityQuery::EqualityQuery
EqualityQuery(MatchFuncArgType v)
constructs with our target value
Definition: EqualityQuery.h:28
Queries::EqualityQuery::getTol
const MatchFuncArgType getTol() const
returns out tolerance
Definition: EqualityQuery.h:45