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 #ifndef __RD_LESSQUERY_H__
11 #define __RD_LESSQUERY_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>
20  class LessQuery :
21  public EqualityQuery<MatchFuncArgType, DataFuncArgType,needsConversion> {
22 
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 = this->TypeConvert(what,Int2Type<needsConversion>());
40  if( queryCmp(this->d_val,mfArg,this->d_tol) < 0 ){
41  if( this->getNegation() ) return false;
42  else return true;
43  } else {
44  if( this->getNegation() ) return true;
45  else return false;
46  }
47  };
48 
50  copy( ) const {
53  res->setNegation(this->getNegation());
54  res->setVal(this->d_val);
55  res->setTol(this->d_tol);
56  res->setDataFunc(this->d_dataFunc);
57  res->d_description = this->d_description;
58  return res;
59  };
60 
61  std::string getFullDescription() const {
62  std::ostringstream res;
63  res<<this->getDescription();
64  res<<" "<<this->d_val;
65  if(this->getNegation()) res<<" ! < ";
66  else res<<" < ";
67  return res.str();
68  };
69  };
70 
71 }
72 #endif
bool getNegation() const
returns whether or not we are negated
Definition: Query.h:60
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
Definition: LessQuery.h:50
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
Definition: LessQuery.h:38
void setVal(MatchFuncArgType what)
sets our target value
Definition: EqualityQuery.h:42
LessQuery(DataFuncArgType v, DataFuncArgType t)
constructs with our target value and a tolerance
Definition: LessQuery.h:32
class to allow integer values to pick templates
Definition: Query.h:26
MatchFuncArgType d_tol
Definition: EqualityQuery.h:94
LessQuery(DataFuncArgType v)
constructs with our target value
Definition: LessQuery.h:26
MatchFuncArgType(* d_dataFunc)(DataFuncArgType)
Definition: Query.h:130
a Query implementing < using a particular value (and an optional tolerance)
Definition: LessQuery.h:20
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
std::string getFullDescription() const
returns a fuller text description
Definition: LessQuery.h:61
Base class for all queries.
Definition: Query.h:46
MatchFuncArgType d_val
Definition: EqualityQuery.h:93