RDKit
Open-source cheminformatics and machine learning.
LessEqualQuery.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_LESSEQUALQUERY_H__
11 #define __RD_LESSEQUALQUERY_H__
12 #include "Query.h"
13 #include "EqualityQuery.h"
14 
15 namespace Queries {
16  //! \brief a Query implementing <= using a particular
17  //! value (and an optional tolerance)
18  template <class MatchFuncArgType, class DataFuncArgType=MatchFuncArgType,
19  bool needsConversion=false>
21  public EqualityQuery<MatchFuncArgType, DataFuncArgType,needsConversion> {
22 
23  public:
24  LessEqualQuery() {this->d_tol = 0;};
25  //! constructs with our target value
26  explicit LessEqualQuery(DataFuncArgType what) {
27  this->d_val = what;
28  this->d_tol = 0;
29  this->df_negate = false;
30  };
31  //! constructs with our target value and a tolerance
32  LessEqualQuery(DataFuncArgType v,DataFuncArgType t) {
33  this->d_val = v;
34  this->d_tol = t;
35  this->df_negate = false;
36  };
37 
38 
39  bool Match(const DataFuncArgType what) const {
40  MatchFuncArgType mfArg = this->TypeConvert(what,Int2Type<needsConversion>());
41  if( queryCmp(this->d_val,mfArg,this->d_tol) <= 0 ){
42  if( this->getNegation() ) return false;
43  else return true;
44  } else {
45  if( this->getNegation() ) return true;
46  else return false;
47  }
48  };
49 
51  copy( ) const {
54  res->setNegation(this->getNegation());
55  res->setVal(this->d_val);
56  res->setTol(this->d_tol);
57  res->setDataFunc(this->d_dataFunc);
58  res->d_description = this->d_description;
59  return res;
60  };
61 
62  std::string getFullDescription() const {
63  std::ostringstream res;
64  res<<this->getDescription();
65  res<<" "<<this->d_val;
66  if(this->getNegation()) res<<" ! <= ";
67  else res<<" <= ";
68  return res.str();
69  };
70 
71  };
72 
73 }
74 #endif
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:60
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition: Query.h:161
const std::string & getDescription() const
returns our text description
Definition: Query.h:67
void setNegation(bool what)
sets whether or not we are negated
Definition: Query.h:58
void setTol(MatchFuncArgType what)
sets our tolerance
Definition: EqualityQuery.h:47
MatchFuncArgType TypeConvert(MatchFuncArgType what, Int2Type< false >) const
calls our dataFunc (if it&#39;s set) on what and returns the result, otherwise returns what ...
Definition: Query.h:134
bool Match(const DataFuncArgType what) const
returns whether or not we match the argument
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:42
LessEqualQuery(DataFuncArgType what)
constructs with our target value
class to allow integer values to pick templates
Definition: Query.h:26
LessEqualQuery(DataFuncArgType v, DataFuncArgType t)
constructs with our target value and a tolerance
a Query implementing <= using a particular value (and an optional tolerance)
MatchFuncArgType d_tol
Definition: EqualityQuery.h:94
std::string getFullDescription() const
returns a fuller text description
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:130
a Query implementing ==: arguments must match a particular value (within an optional tolerance) ...
Definition: EqualityQuery.h:22
bool df_negate
Definition: Query.h:128
void setDataFunc(MatchFuncArgType(*what)(DataFuncArgType))
sets our data function
Definition: Query.h:81
std::string d_description
Definition: Query.h:123
Base class for all queries.
Definition: Query.h:46
MatchFuncArgType d_val
Definition: EqualityQuery.h:93
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query