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 template instantiation request
22 #endif
23 
24 namespace RDKit{
25  class QueryAtom;
26 
27  //! A general random access iterator
28  template <class Atom_, class Mol_>
29  class AtomIterator_ {
30  public:
32  AtomIterator_() : _pos(0),_max(-1),_mol(0) {};
33  AtomIterator_(Mol_ * mol);
34  AtomIterator_(Mol_ * mol,int pos);
35  AtomIterator_(const ThisType &other);
36  AtomIterator_ &operator=(const ThisType &other);
37  AtomIterator_ &operator+=(int val);
38  AtomIterator_ &operator-=(int val);
39  AtomIterator_ operator+(int val) const;
40  AtomIterator_ operator-(int val) const;
41 
42  // iterator subtraction
43  int operator-(ThisType &other) const;
44 
45  // dereference
46  Atom_ * operator*() const;
47  // random access
48  Atom_ * operator[](const int which) const;
49  bool operator==(const ThisType &other) 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 
56  // pre-increment
57  ThisType &operator++();
58  ThisType operator++(int);
59 
60  // pre-decrement
61  ThisType &operator--();
62  ThisType operator--(int);
63 
64  //private:
65  int _pos,_max;
66  Mol_ * _mol;
67  };
68 
69 
70  //! Iterate over heteroatoms, this is bidirectional
71  template <class Atom_, class Mol_>
73  public:
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  private:
94  int _end,_pos;
95  Mol_ * _mol;
96  //FIX: somehow changing the following to a pointer make the regression test pass
97  // QueryAtom _qA;
98  QueryAtom *_qA;
99 
100  int _findNext(int from);
101  int _findPrev(int from);
102  };
103 
104  //! Iterate over aromatic atoms, this is bidirectional
105  template <class Atom_, class Mol_>
107  public:
110  AromaticAtomIterator_(Mol_ * mol);
111  AromaticAtomIterator_(Mol_ * mol,int pos);
113  AromaticAtomIterator_(const ThisType &other);
114  AromaticAtomIterator_ &operator=(const ThisType &other);
115  bool operator==(const ThisType &other) const;
116  bool operator!=(const ThisType &other) const;
117 
118  Atom_ * operator*() const;
119 
120  // pre-increment
121  ThisType &operator++();
122  ThisType operator++(int);
123 
124  // pre-decrement
125  ThisType &operator--();
126  ThisType operator--(int);
127  private:
128  int _end,_pos;
129  Mol_ * _mol;
130 
131  int _findNext(int from);
132  int _findPrev(int from);
133  };
134 
135  //! Iterate over atoms matching a query. This is bidirectional.
136  template <class Atom_, class Mol_>
138  public:
140  QueryAtomIterator_() : _mol(0),_qA(0) {};
141  QueryAtomIterator_(Mol_ * mol,QueryAtom const *what);
142  QueryAtomIterator_(Mol_ * mol,int pos);
144  QueryAtomIterator_(const ThisType &other);
145  QueryAtomIterator_ &operator=(const ThisType &other);
146  bool operator==(const ThisType &other) const;
147  bool operator!=(const ThisType &other) const;
148 
149  Atom_ * operator*() const;
150 
151  // pre-increment
152  ThisType &operator++();
153  ThisType operator++(int);
154 
155  // pre-decrement
156  ThisType &operator--();
157  ThisType operator--(int);
158  private:
159  int _end,_pos;
160  Mol_ * _mol;
161  QueryAtom *_qA;
162 
163  int _findNext(int from);
164  int _findPrev(int from);
165  };
166 
167  //! Iterate over atoms matching a query function. This is bidirectional.
168  template <class Atom_, class Mol_>
170  public:
172  MatchingAtomIterator_() : _end(-1),_pos(-1),_mol(0),_qF(0) {};
173  MatchingAtomIterator_(Mol_ * mol,bool (*fn)(Atom_ *));
174  MatchingAtomIterator_(Mol_ * mol,int pos);
176  MatchingAtomIterator_(const ThisType &other);
177  MatchingAtomIterator_ &operator=(const ThisType &other);
178  bool operator==(const ThisType &other) const;
179  bool operator!=(const ThisType &other) const;
180 
181  Atom_ * operator*() const;
182 
183  // pre-increment
184  ThisType &operator++();
185  ThisType operator++(int);
186 
187  // pre-decrement
188  ThisType &operator--();
189  ThisType operator--(int);
190  private:
191  int _end,_pos;
192  Mol_ * _mol;
193  bool (*_qF)(Atom_ *);
194 
195  int _findNext(int from);
196  int _findPrev(int from);
197  };
198 
199 
200 
201 } /* end o namespace */
202 
203 #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.
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
QueryAtomIterator_< Atom_, Mol_ > ThisType
ThisType & operator++()
AromaticAtomIterator_< Atom_, Mol_ > ThisType
bool operator!=(const ThisType &other) const
AtomIterator_ operator+(int val) const
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
A general random access iterator.
Definition: AtomIterators.h:29
AtomIterator_ operator-(int val) const
Atom_ * operator[](const int which) const
HeteroatomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:74
Iterate over atoms matching a query function. This is bidirectional.
Atom_ * operator*() const
MatchingAtomIterator_< Atom_, Mol_ > ThisType
AtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:31
Iterate over heteroatoms, this is bidirectional.
Definition: AtomIterators.h:72
ThisType & operator--()
AtomIterator_ & operator=(const ThisType &other)
AtomIterator_ & operator-=(int val)