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 #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_>
31  public:
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_>
73  public:
75  HeteroatomIterator_() : _mol(0){};
76  HeteroatomIterator_(Mol_ *mol);
77  HeteroatomIterator_(Mol_ *mol, int pos);
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_>
109  public:
111  AromaticAtomIterator_() : _mol(0){};
112  AromaticAtomIterator_(Mol_ *mol);
113  AromaticAtomIterator_(Mol_ *mol, int pos);
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_>
141  public:
143  QueryAtomIterator_() : _mol(0), _qA(0){};
144  QueryAtomIterator_(Mol_ *mol, QueryAtom const *what);
145  QueryAtomIterator_(Mol_ *mol, int pos);
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_>
174  public:
176  MatchingAtomIterator_() : _end(-1), _pos(-1), _mol(0), _qF(0){};
177  MatchingAtomIterator_(Mol_ *mol, bool (*fn)(Atom_ *));
178  MatchingAtomIterator_(Mol_ *mol, int pos);
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
AtomIterator_ & operator+=(int val)
Iterate over aromatic atoms, this is bidirectional.
bool operator==(const ThisType &other) const
bool operator>(const ThisType &other) const
Iterate over atoms matching a query. This is bidirectional.
AromaticAtomIterator_< Atom_, Mol_ > ThisType
bool operator>=(const ThisType &other) const
Class for storing atomic queries.
Definition: QueryAtom.h:26
bool operator<(const ThisType &other) const
bool operator<=(const ThisType &other) const
ThisType & operator++()
HeteroatomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:74
bool operator!=(const ThisType &other) const
AtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:32
AtomIterator_ operator+(int val) const
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
A general random access iterator.
Definition: AtomIterators.h:30
QueryAtomIterator_< Atom_, Mol_ > ThisType
AtomIterator_ operator-(int val) const
Atom_ * operator[](const int which) const
Iterate over atoms matching a query function. This is bidirectional.
MatchingAtomIterator_< Atom_, Mol_ > ThisType
Atom_ * operator*() const
Iterate over heteroatoms, this is bidirectional.
Definition: AtomIterators.h:72
ThisType & operator--()
AtomIterator_ & operator=(const ThisType &other)
AtomIterator_ & operator-=(int val)