RDKit
Open-source cheminformatics and machine learning.
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 #include <RDGeneral/export.h>
18 #ifndef __RD_ATOM_ITERATORS_H__
19 #define __RD_ATOM_ITERATORS_H__
20 
21 #ifdef _MSC_VER
22 #pragma warning(disable : 4661) // no suitable definition provided for explicit
23  // template instantiation request
24 #endif
25 
26 namespace RDKit {
27 class QueryAtom;
28 
29 //! A general random access iterator
30 template <class Atom_, class Mol_>
32  public:
34  AtomIterator_() : _pos(-1), _max(-1), _mol(nullptr){};
35  AtomIterator_(Mol_ *mol);
36  AtomIterator_(Mol_ *mol, int pos);
37  AtomIterator_(const ThisType &other);
38  AtomIterator_ &operator=(const ThisType &other);
39  AtomIterator_ &operator+=(int val);
40  AtomIterator_ &operator-=(int val);
41  AtomIterator_ operator+(int val) const;
42  AtomIterator_ operator-(int val) const;
43 
44  // iterator subtraction
45  int operator-(ThisType &other) const;
46 
47  // dereference
48  Atom_ *operator*() const;
49  // random access
50  Atom_ *operator[](const int which) 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  bool operator>=(const ThisType &other) const;
57 
58  // pre-increment
59  ThisType &operator++();
60  ThisType operator++(int);
61 
62  // pre-decrement
63  ThisType &operator--();
64  ThisType operator--(int);
65 
66  private:
67  int _pos, _max;
68  Mol_ *_mol;
69 };
70 
71 //! Iterate over heteroatoms, this is bidirectional
72 template <class Atom_, class Mol_>
74  public:
76  HeteroatomIterator_() : _end(-1), _pos(-1), _mol(nullptr){};
77  HeteroatomIterator_(Mol_ *mol);
78  HeteroatomIterator_(Mol_ *mol, int pos);
80  HeteroatomIterator_(const ThisType &other);
81  HeteroatomIterator_ &operator=(const ThisType &other);
82  bool operator==(const ThisType &other) const;
83  bool operator!=(const ThisType &other) const;
84 
85  Atom_ *operator*() const;
86 
87  // pre-increment
88  ThisType &operator++();
89  ThisType operator++(int);
90 
91  // pre-decrement
92  ThisType &operator--();
93  ThisType operator--(int);
94 
95  private:
96  int _end, _pos;
97  Mol_ *_mol;
98  // FIX: somehow changing the following to a pointer make the regression test
99  // pass
100  // QueryAtom _qA;
101  QueryAtom *_qA;
102 
103  int _findNext(int from);
104  int _findPrev(int from);
105 };
106 
107 //! Iterate over aromatic atoms, this is bidirectional
108 template <class Atom_, class Mol_>
110  public:
112  AromaticAtomIterator_() : _end(-1), _pos(-1), _mol(nullptr){};
113  AromaticAtomIterator_(Mol_ *mol);
114  AromaticAtomIterator_(Mol_ *mol, int pos);
116  AromaticAtomIterator_(const ThisType &other);
117  AromaticAtomIterator_ &operator=(const ThisType &other);
118  bool operator==(const ThisType &other) const;
119  bool operator!=(const ThisType &other) const;
120 
121  Atom_ *operator*() const;
122 
123  // pre-increment
124  ThisType &operator++();
125  ThisType operator++(int);
126 
127  // pre-decrement
128  ThisType &operator--();
129  ThisType operator--(int);
130 
131  private:
132  int _end, _pos;
133  Mol_ *_mol;
134 
135  int _findNext(int from);
136  int _findPrev(int from);
137 };
138 
139 //! Iterate over atoms matching a query. This is bidirectional.
140 template <class Atom_, class Mol_>
142  public:
144  QueryAtomIterator_() : _end(-1), _pos(-1), _mol(nullptr), _qA(nullptr){};
145  QueryAtomIterator_(Mol_ *mol, QueryAtom const *what);
146  QueryAtomIterator_(Mol_ *mol, int pos);
148  QueryAtomIterator_(const ThisType &other);
149  QueryAtomIterator_ &operator=(const ThisType &other);
150  bool operator==(const ThisType &other) const;
151  bool operator!=(const ThisType &other) const;
152 
153  Atom_ *operator*() const;
154 
155  // pre-increment
156  ThisType &operator++();
157  ThisType operator++(int);
158 
159  // pre-decrement
160  ThisType &operator--();
161  ThisType operator--(int);
162 
163  private:
164  int _end, _pos;
165  Mol_ *_mol;
166  QueryAtom *_qA;
167 
168  int _findNext(int from);
169  int _findPrev(int from);
170 };
171 
172 //! Iterate over atoms matching a query function. This is bidirectional.
173 template <class Atom_, class Mol_>
175  public:
177  MatchingAtomIterator_() : _end(-1), _pos(-1), _mol(nullptr), _qF(nullptr){};
178  MatchingAtomIterator_(Mol_ *mol, bool (*fn)(Atom_ *));
179  MatchingAtomIterator_(Mol_ *mol, int pos);
181  MatchingAtomIterator_(const ThisType &other);
182  MatchingAtomIterator_ &operator=(const ThisType &other);
183  bool operator==(const ThisType &other) const;
184  bool operator!=(const ThisType &other) const;
185 
186  Atom_ *operator*() const;
187 
188  // pre-increment
189  ThisType &operator++();
190  ThisType operator++(int);
191 
192  // pre-decrement
193  ThisType &operator--();
194  ThisType operator--(int);
195 
196  private:
197  int _end, _pos;
198  Mol_ *_mol;
199  bool (*_qF)(Atom_ *);
200 
201  int _findNext(int from);
202  int _findPrev(int from);
203 };
204 
205 } // namespace RDKit
206 
207 #endif
RDKit::AtomIterator_
A general random access iterator.
Definition: AtomIterators.h:31
RDKit::QueryAtomIterator_
Iterate over atoms matching a query. This is bidirectional.
Definition: AtomIterators.h:141
RDKit::operator+
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator+(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_()
Definition: AtomIterators.h:177
RDKit::AtomIterator_::ThisType
AtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:33
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_()
Definition: AtomIterators.h:76
RDKit::AromaticAtomIterator_
Iterate over aromatic atoms, this is bidirectional.
Definition: AtomIterators.h:109
RDKit::AromaticAtomIterator_::ThisType
AromaticAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:111
RDKit::HeteroatomIterator_::ThisType
HeteroatomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:75
RDKit::HeteroatomIterator_
Iterate over heteroatoms, this is bidirectional.
Definition: AtomIterators.h:73
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_()
Definition: AtomIterators.h:144
RDKit::MatchingAtomIterator_::ThisType
MatchingAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:176
RDKit::operator-
RDKIT_DATASTRUCTS_EXPORT DiscreteValueVect operator-(const DiscreteValueVect &p1, const DiscreteValueVect &p2)
RDKit::QueryAtomIterator_::ThisType
QueryAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:143
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_()
Definition: AtomIterators.h:112
RDGeom::operator*
RDKIT_RDGEOMETRYLIB_EXPORT RDGeom::Point3D operator*(const RDGeom::Point3D &p1, double v)
RDKit::QueryAtom
Class for storing atomic queries.
Definition: QueryAtom.h:27
RDKit::MatchingAtomIterator_
Iterate over atoms matching a query function. This is bidirectional.
Definition: AtomIterators.h:174
RDKit::AtomIterator_::AtomIterator_
AtomIterator_()
Definition: AtomIterators.h:34
export.h