RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
RangeQuery.h
Go to the documentation of this file.
1
//
2
// Copyright (c) 2003-2020 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_RANGEQUERY_H
12
#define RD_RANGEQUERY_H
13
#include "
Query.h
"
14
#include <utility>
15
16
namespace
Queries
{
17
18
//! \brief a Query implementing a range: arguments must
19
//! fall in a particular range of values.
20
//!
21
//! The ends of the range default to be open, but they can
22
//! individually set to be closed.
23
//!
24
//! There is also an optional tolerance to be used in comparisons
25
template
<
class
MatchFuncArgType,
class
DataFuncArgType = MatchFuncArgType,
26
bool
needsConversion =
false
>
27
class
RDKIT_QUERY_EXPORT
RangeQuery
28
:
public
Query
<MatchFuncArgType, DataFuncArgType, needsConversion> {
29
public
:
30
RangeQuery
() :
d_upper
(0),
d_lower
(0) { this->
df_negate
=
false
; }
31
//! construct and set the lower and upper bounds
32
RangeQuery
(MatchFuncArgType lower, MatchFuncArgType upper)
33
:
d_upper
(upper),
d_lower
(lower),
df_upperOpen
(true),
df_lowerOpen
(true) {
34
this->
df_negate
=
false
;
35
}
36
37
//! sets our upper bound
38
void
setUpper
(MatchFuncArgType what) { this->
d_upper
= what; }
39
//! returns our upper bound
40
const
MatchFuncArgType
getUpper
()
const
{
return
this->
d_upper
; }
41
//! sets our lower bound
42
void
setLower
(MatchFuncArgType what) { this->
d_lower
= what; }
43
//! returns our lower bound
44
const
MatchFuncArgType
getLower
()
const
{
return
this->
d_lower
; }
45
46
//! sets whether or not the ends of the range are open
47
void
setEndsOpen
(
bool
lower,
bool
upper) {
48
this->
df_lowerOpen
= lower;
49
this->
df_upperOpen
= upper;
50
}
51
//! returns the state of our ends (open or not)
52
std::pair<bool, bool>
getEndsOpen
()
const
{
53
return
std::make_pair(this->
df_lowerOpen
, this->
df_upperOpen
);
54
}
55
56
//! sets our tolerance
57
void
setTol
(MatchFuncArgType what) { this->
d_tol
= what; }
58
//! returns our tolerance
59
const
MatchFuncArgType
getTol
()
const
{
return
this->
d_tol
; }
60
61
bool
Match
(
const
DataFuncArgType what)
const override
{
62
MatchFuncArgType mfArg =
63
this->
TypeConvert
(what,
Int2Type<needsConversion>
());
64
int
lCmp =
queryCmp
(this->
d_lower
, mfArg, this->
d_tol
);
65
int
uCmp =
queryCmp
(this->
d_upper
, mfArg, this->
d_tol
);
66
bool
lowerRes, upperRes;
67
if
(this->
df_lowerOpen
) {
68
lowerRes = lCmp < 0;
69
}
else
{
70
lowerRes = lCmp <= 0;
71
}
72
if
(this->
df_upperOpen
) {
73
upperRes = uCmp > 0;
74
}
else
{
75
upperRes = uCmp >= 0;
76
}
77
78
bool
tempR = !(lowerRes && upperRes);
79
if
(this->
getNegation
()) {
80
return
tempR;
81
}
else
{
82
return
!tempR;
83
}
84
}
85
86
Query<MatchFuncArgType, DataFuncArgType, needsConversion>
*
copy
()
87
const override
{
88
RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>
*res =
89
new
RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>
();
90
res->
setUpper
(this->
d_upper
);
91
res->
setLower
(this->
d_lower
);
92
res->
setTol
(this->
d_tol
);
93
res->
setNegation
(this->
getNegation
());
94
res->
setEndsOpen
(this->
df_lowerOpen
, this->
df_upperOpen
);
95
res->
setDataFunc
(this->
d_dataFunc
);
96
res->
d_description
= this->
d_description
;
97
res->
d_queryType
= this->
d_queryType
;
98
return
res;
99
}
100
101
std::string
getFullDescription
()
const override
{
102
std::ostringstream res;
103
res << this->
getDescription
();
104
if
(this->
getNegation
()) {
105
res <<
" ! "
;
106
}
107
res <<
" "
<< this->
d_lower
<<
" val "
<< this->
d_upper
;
108
return
res.str();
109
}
110
111
protected
:
112
MatchFuncArgType
d_upper
,
d_lower
;
113
bool
df_upperOpen
{
true
}, df_lowerOpen{
true
};
114
};
115
}
// namespace Queries
116
#endif
Query.h
Queries::Int2Type
class to allow integer values to pick templates
Definition
Query.h:27
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:174
Queries::Query::d_dataFunc
std::function< MatchFuncArgType(DataFuncArgType)> d_dataFunc
Definition
Query.h:169
Queries::Query::d_queryType
std::string d_queryType
Definition
Query.h:158
Queries::Query::setDataFunc
void setDataFunc(std::function< MatchFuncArgType(DataFuncArgType)> what)
sets our data function
Definition
Query.h:99
Queries::Query::getNegation
bool getNegation() const
returns whether or not we are negated
Definition
Query.h:64
Queries::Query::setNegation
void setNegation(bool what)
sets whether or not we are negated
Definition
Query.h:62
Queries::Query::getDescription
const std::string & getDescription() const
returns our text description
Definition
Query.h:73
Queries::Query< MatchFuncArgType, MatchFuncArgType, false >::Query
Query()
Definition
Query.h:58
Queries::Query::df_negate
bool df_negate
Definition
Query.h:160
Queries::Query::d_tol
MatchFuncArgType d_tol
Definition
Query.h:156
Queries::Query::d_description
std::string d_description
Definition
Query.h:157
Queries::RangeQuery::getFullDescription
std::string getFullDescription() const override
returns a fuller text description
Definition
RangeQuery.h:101
Queries::RangeQuery::RangeQuery
RangeQuery(MatchFuncArgType lower, MatchFuncArgType upper)
construct and set the lower and upper bounds
Definition
RangeQuery.h:32
Queries::RangeQuery::setTol
void setTol(MatchFuncArgType what)
sets our tolerance
Definition
RangeQuery.h:57
Queries::RangeQuery< double, const ROMol &, true >::d_upper
double d_upper
Definition
RangeQuery.h:112
Queries::RangeQuery< double, const ROMol &, true >::df_lowerOpen
bool df_lowerOpen
Definition
RangeQuery.h:113
Queries::RangeQuery::setUpper
void setUpper(MatchFuncArgType what)
sets our upper bound
Definition
RangeQuery.h:38
Queries::RangeQuery< double, const ROMol &, true >::df_upperOpen
bool df_upperOpen
Definition
RangeQuery.h:113
Queries::RangeQuery::Match
bool Match(const DataFuncArgType what) const override
Definition
RangeQuery.h:61
Queries::RangeQuery::getLower
const MatchFuncArgType getLower() const
returns our lower bound
Definition
RangeQuery.h:44
Queries::RangeQuery< double, const ROMol &, true >::d_lower
double d_lower
Definition
RangeQuery.h:112
Queries::RangeQuery::RangeQuery
RangeQuery()
Definition
RangeQuery.h:30
Queries::RangeQuery::getUpper
const MatchFuncArgType getUpper() const
returns our upper bound
Definition
RangeQuery.h:40
Queries::RangeQuery::getEndsOpen
std::pair< bool, bool > getEndsOpen() const
returns the state of our ends (open or not)
Definition
RangeQuery.h:52
Queries::RangeQuery::getTol
const MatchFuncArgType getTol() const
returns our tolerance
Definition
RangeQuery.h:59
Queries::RangeQuery::setEndsOpen
void setEndsOpen(bool lower, bool upper)
sets whether or not the ends of the range are open
Definition
RangeQuery.h:47
Queries::RangeQuery::setLower
void setLower(MatchFuncArgType what)
sets our lower bound
Definition
RangeQuery.h:42
Queries::RangeQuery::copy
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const override
returns a copy of this Query
Definition
RangeQuery.h:86
export.h
RDKIT_QUERY_EXPORT
#define RDKIT_QUERY_EXPORT
Definition
export.h:833
Queries
Definition
AndQuery.h:16
Queries::queryCmp
int queryCmp(const T1 v1, const T2 v2, const T1 tol)
Definition
Query.h:202
Query
RangeQuery.h
Generated on
for RDKit by
1.17.0