RDKit
Open-source cheminformatics and machine learning.
LessQuery.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 #include <RDGeneral/export.h>
11 #ifndef __RD_LESSQUERY_H__
12 #define __RD_LESSQUERY_H__
13 #include "Query.h"
14 #include "EqualityQuery.h"
15 
16 namespace Queries {
17 //! \brief a Query implementing < using a particular
18 //! value (and an optional tolerance)
19 template <class MatchFuncArgType, class DataFuncArgType = MatchFuncArgType,
20  bool needsConversion = false>
21 class LessQuery
22  : public EqualityQuery<MatchFuncArgType, DataFuncArgType, needsConversion> {
23  public:
24  LessQuery() { this->d_tol = 0; };
25  //! constructs with our target value
26  explicit LessQuery(DataFuncArgType v) {
27  this->d_val = v;
28  this->d_tol = 0;
29  this->df_negate = false;
30  };
31  //! constructs with our target value and a tolerance
32  LessQuery(DataFuncArgType v, DataFuncArgType t) {
33  this->d_val = v;
34  this->d_tol = t;
35  this->df_negate = false;
36  };
37 
38  bool Match(const DataFuncArgType what) const {
39  MatchFuncArgType mfArg =
41  if (queryCmp(this->d_val, mfArg, this->d_tol) < 0) {
42  if (this->getNegation())
43  return false;
44  else
45  return true;
46  } else {
47  if (this->getNegation())
48  return true;
49  else
50  return false;
51  }
52  };
53 
57  res->setNegation(this->getNegation());
58  res->setVal(this->d_val);
59  res->setTol(this->d_tol);
60  res->setDataFunc(this->d_dataFunc);
61  res->d_description = this->d_description;
62  return res;
63  };
64 
65  std::string getFullDescription() const {
66  std::ostringstream res;
67  res << this->getDescription();
68  res << " " << this->d_val;
69  if (this->getNegation())
70  res << " ! < ";
71  else
72  res << " < ";
73  return res.str();
74  };
75 };
76 } // namespace Queries
77 #endif
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::df_negate
bool df_negate
Definition: Query.h:149
Queries::LessQuery::copy
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
Definition: LessQuery.h:54
Queries::EqualityQuery< MatchFuncArgType, MatchFuncArgType, false >::setVal
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:42
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:63
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:191
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::d_val
MatchFuncArgType d_val
Definition: Query.h:145
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::d_dataFunc
MatchFuncArgType(* d_dataFunc)(MatchFuncArgType)
Definition: Query.h:158
Query.h
Queries::LessQuery::LessQuery
LessQuery(DataFuncArgType v)
constructs with our target value
Definition: LessQuery.h:26
Queries::LessQuery::Match
bool Match(const DataFuncArgType what) const
Definition: LessQuery.h:38
Queries
Definition: AndQuery.h:16
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::d_description
std::string d_description
Definition: Query.h:147
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::setDataFunc
void setDataFunc(MatchFuncArgType(*what)(MatchFuncArgType))
sets our data function
Definition: Query.h:92
Queries::LessQuery::LessQuery
LessQuery()
Definition: LessQuery.h:24
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::getNegation
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:65
Queries::Int2Type
class to allow integer values to pick templates
Definition: Query.h:27
Queries::LessQuery
a Query implementing < using a particular value (and an optional tolerance)
Definition: LessQuery.h:21
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::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:163
EqualityQuery.h
Queries::EqualityQuery< MatchFuncArgType, MatchFuncArgType, false >::setTol
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:47
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::d_tol
MatchFuncArgType d_tol
Definition: Query.h:146
Queries::Query
Base class for all queries.
Definition: Query.h:46
Queries::LessQuery::LessQuery
LessQuery(DataFuncArgType v, DataFuncArgType t)
constructs with our target value and a tolerance
Definition: LessQuery.h:32
Queries::Query< MatchFuncArgType, MatchFuncArgType, needsConversion >::getDescription
const std::string & getDescription() const
returns our text description
Definition: Query.h:76
Queries::LessQuery::getFullDescription
std::string getFullDescription() const
Definition: LessQuery.h:65
Queries::EqualityQuery
a Query implementing ==: arguments must match a particular value (within an optional tolerance)
Definition: EqualityQuery.h:23
export.h