Loading...
Searching...
No Matches
EqualityQuery.h
Go to the documentation of this file.
//
// Copyright (c) 2003-2020 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RD_EQUALITYQUERY_H
#define RD_EQUALITYQUERY_H
#include "Query.h"
#include <sstream>
namespace Queries {
//! \brief a Query implementing ==: arguments must match a particular
//! value (within an optional tolerance)
template <typename MatchFuncArgType,
typename DataFuncArgType = MatchFuncArgType,
bool needsConversion = false>
class RDKIT_QUERY_EXPORT EqualityQuery
: public Query<MatchFuncArgType, DataFuncArgType, needsConversion> {
public:
EqualityQuery() { this->df_negate = false; }
//! constructs with our target value
explicit EqualityQuery(MatchFuncArgType v) {
this->d_val = v;
this->df_negate = false;
}
//! constructs with our target value and a tolerance
EqualityQuery(MatchFuncArgType v, MatchFuncArgType t) {
this->d_val = v;
this->d_tol = t;
this->df_negate = false;
}
//! sets our target value
void setVal(MatchFuncArgType what) { this->d_val = what; }
//! returns our target value
const MatchFuncArgType getVal() const { return this->d_val; }
//! sets our tolerance
void setTol(MatchFuncArgType what) { this->d_tol = what; }
//! returns out tolerance
const MatchFuncArgType getTol() const { return this->d_tol; }
bool Match(const DataFuncArgType what) const override {
MatchFuncArgType mfArg =
this->TypeConvert(what, Int2Type<needsConversion>());
if (queryCmp(this->d_val, mfArg, this->d_tol) == 0) {
return !this->getNegation();
} else {
return this->getNegation();
}
}
Query<MatchFuncArgType, DataFuncArgType, needsConversion> *copy()
const override {
EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
new EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
res->setNegation(this->getNegation());
res->setVal(this->d_val);
res->setTol(this->d_tol);
res->setDataFunc(this->d_dataFunc);
res->d_description = this->d_description;
res->d_queryType = this->d_queryType;
return res;
}
std::string getFullDescription() const override {
std::ostringstream res;
res << this->getDescription();
res << " " << this->d_val;
if (this->getNegation()) {
res << " != ";
} else {
res << " = ";
}
res << "val";
return res.str();
}
};
} // namespace Queries
#endif
Query.h
Queries::EqualityQuery
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
Definition EqualityQuery.h:24
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
returns whether or not we match the argument
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
Base class for all queries.
Definition Query.h:45
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::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition Query.h:59
Queries::Query::d_description
std::string d_description
Definition Query.h:152
export.h
RDKIT_QUERY_EXPORT
#define RDKIT_QUERY_EXPORT
Definition export.h:629
Queries
Definition AndQuery.h:16
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition Query.h:197