RDKit
Open-source cheminformatics and machine learning.
Toggle main menu visibility
Loading...
Searching...
No Matches
SetQuery.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_SETQUERY_H
12
#define RD_SETQUERY_H
13
#include <set>
14
#include "
Query.h
"
15
#include <sstream>
16
#include <algorithm>
17
#include <iterator>
18
19
namespace
Queries
{
20
//! \brief a Query implementing a set: arguments must
21
//! one of a set of values
22
//!
23
template
<
class
MatchFuncArgType,
class
DataFuncArgType = MatchFuncArgType,
24
bool
needsConversion =
false
>
25
class
RDKIT_QUERY_EXPORT
SetQuery
26
:
public
Query
<MatchFuncArgType, DataFuncArgType, needsConversion> {
27
public
:
28
typedef
std::set<MatchFuncArgType>
CONTAINER_TYPE
;
29
30
SetQuery
() :
Query
<MatchFuncArgType, DataFuncArgType, needsConversion>() {}
31
32
//! insert an entry into our \c set
33
void
insert
(
const
MatchFuncArgType what) {
34
if
(
d_set
.find(what) == this->d_set.end()) {
35
this->
d_set
.insert(what);
36
}
37
}
38
39
//! clears our \c set
40
void
clear
() { this->
d_set
.clear(); }
41
42
bool
Match
(
const
DataFuncArgType what)
const override
{
43
MatchFuncArgType mfArg =
44
this->
TypeConvert
(what,
Int2Type<needsConversion>
());
45
return
(this->
d_set
.find(mfArg) != this->d_set.end()) ^ this->
getNegation
();
46
}
47
48
Query<MatchFuncArgType, DataFuncArgType, needsConversion>
*
copy
()
49
const override
{
50
SetQuery<MatchFuncArgType, DataFuncArgType, needsConversion>
*res =
51
new
SetQuery<MatchFuncArgType, DataFuncArgType, needsConversion>
();
52
res->
setDataFunc
(this->
d_dataFunc
);
53
typename
std::set<MatchFuncArgType>::const_iterator i;
54
for
(i = this->
d_set
.begin(); i != this->d_set.end(); ++i) {
55
res->
insert
(*i);
56
}
57
res->
setNegation
(this->
getNegation
());
58
res->
d_description
= this->
d_description
;
59
res->
d_queryType
= this->
d_queryType
;
60
return
res;
61
}
62
63
typename
CONTAINER_TYPE::const_iterator
beginSet
()
const
{
64
return
d_set
.begin();
65
}
66
typename
CONTAINER_TYPE::const_iterator
endSet
()
const
{
return
d_set
.end(); }
67
unsigned
int
size
()
const
{
return
rdcast<unsigned int>
(
d_set
.size()); }
68
69
std::string
getFullDescription
()
const override
{
70
std::ostringstream res;
71
res << this->
getDescription
() <<
" val"
;
72
if
(this->
getNegation
()) {
73
res <<
" not in "
;
74
}
else
{
75
res <<
" in ("
;
76
}
77
std::copy(
d_set
.begin(),
d_set
.end(),
78
std::ostream_iterator<MatchFuncArgType>(res,
", "
));
79
res <<
")"
;
80
return
res.str();
81
}
82
83
protected
:
84
CONTAINER_TYPE
d_set
;
85
};
86
}
// namespace Queries
87
#endif
rdcast
#define rdcast
Definition
Invariant.h:191
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::d_description
std::string d_description
Definition
Query.h:157
Queries::SetQuery::beginSet
CONTAINER_TYPE::const_iterator beginSet() const
Definition
SetQuery.h:63
Queries::SetQuery::copy
Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const override
returns a copy of this Query
Definition
SetQuery.h:48
Queries::SetQuery::clear
void clear()
clears our set
Definition
SetQuery.h:40
Queries::SetQuery< int, Atom const *, true >::CONTAINER_TYPE
std::set< int > CONTAINER_TYPE
Definition
SetQuery.h:28
Queries::SetQuery::insert
void insert(const MatchFuncArgType what)
insert an entry into our set
Definition
SetQuery.h:33
Queries::SetQuery::size
unsigned int size() const
Definition
SetQuery.h:67
Queries::SetQuery< int, Atom const *, true >::d_set
CONTAINER_TYPE d_set
Definition
SetQuery.h:84
Queries::SetQuery::Match
bool Match(const DataFuncArgType what) const override
Definition
SetQuery.h:42
Queries::SetQuery::endSet
CONTAINER_TYPE::const_iterator endSet() const
Definition
SetQuery.h:66
Queries::SetQuery::getFullDescription
std::string getFullDescription() const override
returns a fuller text description
Definition
SetQuery.h:69
Queries::SetQuery::SetQuery
SetQuery()
Definition
SetQuery.h:30
export.h
RDKIT_QUERY_EXPORT
#define RDKIT_QUERY_EXPORT
Definition
export.h:833
Queries
Definition
AndQuery.h:16
Query
SetQuery.h
Generated on
for RDKit by
1.17.0