RDKit: AtomIterators.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

AtomIterators.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-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 /*! \file AtomIterators.h
11
12 \brief various tools for iterating over a molecule's Atoms.
13
14 <b>WARNING:</b> If you go changing the molecule underneath one of
15 these iterators you will be sad...
16 */
17 #ifndef __RD_ATOM_ITERATORS_H__
18 #define __RD_ATOM_ITERATORS_H__
19
20 #ifdef _MSC_VER
21 #pragma warning(disable : 4661) // no suitable definition provided for explicit
22 // template instantiation request
23 #endif
24
25 namespace RDKit {
26 class QueryAtom;
27
28 //! A general random access iterator
29 template <class Atom_, class Mol_>
30 class AtomIterator_ {
31 public:
32 typedef AtomIterator_<Atom_, Mol_> ThisType;
33 AtomIterator_() : _pos(0), _max(-1), _mol(0){};
34 AtomIterator_(Mol_ *mol);
35 AtomIterator_(Mol_ *mol, int pos);
36 AtomIterator_(const ThisType &other);
37 AtomIterator_ &operator=(const ThisType &other);
38 AtomIterator_ &operator+=(int val);
39 AtomIterator_ &operator-=(int val);
40 AtomIterator_ operator+(int val) const;
41 AtomIterator_ operator-(int val) const;
42
43 // iterator subtraction
44 int operator-(ThisType &other) const;
45
46 // dereference
47 Atom_ *operator*() const;
48 // random access
49 Atom_ *operator[](const int which) const;
50 bool operator==(const ThisType &other) const;
51 bool operator!=(const ThisType &other) const;
52 bool operator<(const ThisType &other) const;
53 bool operator<=(const ThisType &other) const;
54 bool operator>(const ThisType &other) const;
55 bool operator>=(const ThisType &other) const;
56
57 // pre-increment
58 ThisType &operator++();
59 ThisType operator++(int);
60
61 // pre-decrement
62 ThisType &operator--();
63 ThisType operator--(int);
64
65 // private:
66 int _pos, _max;
67 Mol_ *_mol;
68 };
69
70 //! Iterate over heteroatoms, this is bidirectional
71 template <class Atom_, class Mol_>
72 class HeteroatomIterator_ {
73 public:
74 typedef HeteroatomIterator_<Atom_, Mol_> ThisType;
75 HeteroatomIterator_() : _mol(0){};
76 HeteroatomIterator_(Mol_ *mol);
77 HeteroatomIterator_(Mol_ *mol, int pos);
78 ~HeteroatomIterator_();
79 HeteroatomIterator_(const ThisType &other);
80 HeteroatomIterator_ &operator=(const ThisType &other);
81 bool operator==(const ThisType &other) const;
82 bool operator!=(const ThisType &other) const;
83
84 Atom_ *operator*() const;
85
86 // pre-increment
87 ThisType &operator++();
88 ThisType operator++(int);
89
90 // pre-decrement
91 ThisType &operator--();
92 ThisType operator--(int);
93
94 private:
95 int _end, _pos;
96 Mol_ *_mol;
97 // FIX: somehow changing the following to a pointer make the regression test
98 // pass
99 // QueryAtom _qA;
100 QueryAtom *_qA;
101
102 int _findNext(int from);
103 int _findPrev(int from);
104 };
105
106 //! Iterate over aromatic atoms, this is bidirectional
107 template <class Atom_, class Mol_>
108 class AromaticAtomIterator_ {
109 public:
110 typedef AromaticAtomIterator_<Atom_, Mol_> ThisType;
111 AromaticAtomIterator_() : _mol(0){};
112 AromaticAtomIterator_(Mol_ *mol);
113 AromaticAtomIterator_(Mol_ *mol, int pos);
114 ~AromaticAtomIterator_();
115 AromaticAtomIterator_(const ThisType &other);
116 AromaticAtomIterator_ &operator=(const ThisType &other);
117 bool operator==(const ThisType &other) const;
118 bool operator!=(const ThisType &other) const;
119
120 Atom_ *operator*() const;
121
122 // pre-increment
123 ThisType &operator++();
124 ThisType operator++(int);
125
126 // pre-decrement
127 ThisType &operator--();
128 ThisType operator--(int);
129
130 private:
131 int _end, _pos;
132 Mol_ *_mol;
133
134 int _findNext(int from);
135 int _findPrev(int from);
136 };
137
138 //! Iterate over atoms matching a query. This is bidirectional.
139 template <class Atom_, class Mol_>
140 class QueryAtomIterator_ {
141 public:
142 typedef QueryAtomIterator_<Atom_, Mol_> ThisType;
143 QueryAtomIterator_() : _mol(0), _qA(0){};
144 QueryAtomIterator_(Mol_ *mol, QueryAtom const *what);
145 QueryAtomIterator_(Mol_ *mol, int pos);
146 ~QueryAtomIterator_();
147 QueryAtomIterator_(const ThisType &other);
148 QueryAtomIterator_ &operator=(const ThisType &other);
149 bool operator==(const ThisType &other) const;
150 bool operator!=(const ThisType &other) const;
151
152 Atom_ *operator*() const;
153
154 // pre-increment
155 ThisType &operator++();
156 ThisType operator++(int);
157
158 // pre-decrement
159 ThisType &operator--();
160 ThisType operator--(int);
161
162 private:
163 int _end, _pos;
164 Mol_ *_mol;
165 QueryAtom *_qA;
166
167 int _findNext(int from);
168 int _findPrev(int from);
169 };
170
171 //! Iterate over atoms matching a query function. This is bidirectional.
172 template <class Atom_, class Mol_>
173 class MatchingAtomIterator_ {
174 public:
175 typedef MatchingAtomIterator_<Atom_, Mol_> ThisType;
176 MatchingAtomIterator_() : _end(-1), _pos(-1), _mol(0), _qF(0){};
177 MatchingAtomIterator_(Mol_ *mol, bool (*fn)(Atom_ *));
178 MatchingAtomIterator_(Mol_ *mol, int pos);
179 ~MatchingAtomIterator_();
180 MatchingAtomIterator_(const ThisType &other);
181 MatchingAtomIterator_ &operator=(const ThisType &other);
182 bool operator==(const ThisType &other) const;
183 bool operator!=(const ThisType &other) const;
184
185 Atom_ *operator*() const;
186
187 // pre-increment
188 ThisType &operator++();
189 ThisType operator++(int);
190
191 // pre-decrement
192 ThisType &operator--();
193 ThisType operator--(int);
194
195 private:
196 int _end, _pos;
197 Mol_ *_mol;
198 bool (*_qF)(Atom_ *);
199
200 int _findNext(int from);
201 int _findPrev(int from);
202 };
203
204 } /* end o namespace */
205
206 #endif
RDKit::HeteroatomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AromaticAtomIterator_::operator=
AromaticAtomIterator_ & operator=(const ThisType &other)
RDKit::HeteroatomIterator_::operator*
Atom_ * operator*() const
RDKit::HeteroatomIterator_::operator++
ThisType & operator++()
RDKit::HeteroatomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::AtomIterator_::_mol
Mol_ * _mol
Definition: AtomIterators.h:67
RDKit::AtomIterator_::operator+=
AtomIterator_ & operator+=(int val)
RDKit::AromaticAtomIterator_::operator*
Atom_ * operator*() const
RDKit::AromaticAtomIterator_
Iterate over aromatic atoms, this is bidirectional.
Definition: AtomIterators.h:108
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_()
Definition: AtomIterators.h:75
RDKit::AtomIterator_::AtomIterator_
AtomIterator_()
Definition: AtomIterators.h:33
RDKit::AtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::AtomIterator_::operator>
bool operator>(const ThisType &other) const
RDKit::AromaticAtomIterator_::operator++
ThisType & operator++()
RDKit::QueryAtomIterator_::operator=
QueryAtomIterator_ & operator=(const ThisType &other)
RDKit::QueryAtomIterator_
Iterate over atoms matching a query. This is bidirectional.
Definition: AtomIterators.h:140
RDKit::AromaticAtomIterator_::ThisType
AromaticAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:110
RDKit::AtomIterator_::operator>=
bool operator>=(const ThisType &other) const
RDKit::QueryAtom
Class for storing atomic queries.
Definition: QueryAtom.h:26
RDKit::AtomIterator_::operator<
bool operator<(const ThisType &other) const
RDKit::QueryAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AtomIterator_::operator<=
bool operator<=(const ThisType &other) const
RDKit::AromaticAtomIterator_::operator--
ThisType & operator--()
RDKit::AtomIterator_::operator++
ThisType & operator++()
RDKit::HeteroatomIterator_::ThisType
HeteroatomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:74
RDKit::AromaticAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::AromaticAtomIterator_::~AromaticAtomIterator_
~AromaticAtomIterator_()
RDKit::AtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_()
Definition: AtomIterators.h:143
RDKit::MatchingAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::MatchingAtomIterator_::~MatchingAtomIterator_
~MatchingAtomIterator_()
RDKit::AtomIterator_::ThisType
AtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:32
RDKit::HeteroatomIterator_::~HeteroatomIterator_
~HeteroatomIterator_()
RDKit::MatchingAtomIterator_::operator*
Atom_ * operator*() const
RDKit::AromaticAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::MatchingAtomIterator_::operator++
ThisType & operator++()
RDKit::AtomIterator_::operator+
AtomIterator_ operator+(int val) const
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::AtomIterator_
A general random access iterator.
Definition: AtomIterators.h:30
RDKit::QueryAtomIterator_::ThisType
QueryAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:142
RDKit::AtomIterator_::operator-
AtomIterator_ operator-(int val) const
RDKit::AtomIterator_::operator[]
Atom_ * operator[](const int which) const
RDKit::QueryAtomIterator_::~QueryAtomIterator_
~QueryAtomIterator_()
RDKit::QueryAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::MatchingAtomIterator_::operator--
ThisType & operator--()
RDKit::MatchingAtomIterator_
Iterate over atoms matching a query function. This is bidirectional.
Definition: AtomIterators.h:173
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_()
Definition: AtomIterators.h:111
RDKit::HeteroatomIterator_::operator=
HeteroatomIterator_ & operator=(const ThisType &other)
RDKit::QueryAtomIterator_::operator--
ThisType & operator--()
RDKit::MatchingAtomIterator_::ThisType
MatchingAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:175
RDKit::AtomIterator_::operator*
Atom_ * operator*() const
RDKit::AtomIterator_::_pos
int _pos
Definition: AtomIterators.h:66
RDKit::QueryAtomIterator_::operator++
ThisType & operator++()
RDKit::MatchingAtomIterator_::operator=
MatchingAtomIterator_ & operator=(const ThisType &other)
RDKit::MatchingAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AtomIterator_::_max
int _max
Definition: AtomIterators.h:66
RDKit::QueryAtomIterator_::operator*
Atom_ * operator*() const
RDKit::HeteroatomIterator_
Iterate over heteroatoms, this is bidirectional.
Definition: AtomIterators.h:72
RDKit::AtomIterator_::operator--
ThisType & operator--()
RDKit::AtomIterator_::operator=
AtomIterator_ & operator=(const ThisType &other)
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_()
Definition: AtomIterators.h:176
RDKit::HeteroatomIterator_::operator--
ThisType & operator--()
RDKit::AtomIterator_::operator-=
AtomIterator_ & operator-=(int val)