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);
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
61 
62  // pre-decrement
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);
82  bool operator==(const ThisType &other) const;
83  bool operator!=(const ThisType &other) const;
84 
85  Atom_ *operator*() const;
86 
87  // pre-increment
90 
91  // pre-decrement
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){};
114  AromaticAtomIterator_(Mol_ *mol, int pos);
118  bool operator==(const ThisType &other) const;
119  bool operator!=(const ThisType &other) const;
120 
121  Atom_ *operator*() const;
122 
123  // pre-increment
126 
127  // pre-decrement
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);
150  bool operator==(const ThisType &other) const;
151  bool operator!=(const ThisType &other) const;
152 
153  Atom_ *operator*() const;
154 
155  // pre-increment
158 
159  // pre-decrement
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);
183  bool operator==(const ThisType &other) const;
184  bool operator!=(const ThisType &other) const;
185 
186  Atom_ *operator*() const;
187 
188  // pre-increment
191 
192  // pre-decrement
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::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_(Mol_ *mol, int pos)
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::MatchingAtomIterator_::operator--
ThisType & operator--()
RDKit::AtomIterator_::operator-
int operator-(ThisType &other) const
RDKit::AtomIterator_::AtomIterator_
AtomIterator_(Mol_ *mol)
RDKit::AromaticAtomIterator_::operator=
AromaticAtomIterator_ & operator=(const ThisType &other)
RDKit::AtomIterator_::operator-=
AtomIterator_ & operator-=(int val)
RDKit::AtomIterator_::operator--
ThisType operator--(int)
RDKit::QueryAtomIterator_::operator*
Atom_ * operator*() const
RDKit::MatchingAtomIterator_::operator--
ThisType operator--(int)
RDKit::AromaticAtomIterator_::~AromaticAtomIterator_
~AromaticAtomIterator_()
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_()
Definition: AtomIterators.h:177
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_(Mol_ *mol)
RDKit::AromaticAtomIterator_::operator++
ThisType operator++(int)
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_(const ThisType &other)
RDKit::AtomIterator_::ThisType
AtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:33
RDKit::AromaticAtomIterator_::operator*
Atom_ * operator*() const
RDKit::AromaticAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::QueryAtomIterator_::operator=
QueryAtomIterator_ & operator=(const ThisType &other)
RDKit::AromaticAtomIterator_::operator--
ThisType operator--(int)
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_()
Definition: AtomIterators.h:76
RDKit::HeteroatomIterator_::operator--
ThisType operator--(int)
RDKit::MatchingAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AtomIterator_::AtomIterator_
AtomIterator_(Mol_ *mol, int pos)
RDKit::AromaticAtomIterator_
Iterate over aromatic atoms, this is bidirectional.
Definition: AtomIterators.h:109
RDKit::HeteroatomIterator_::operator++
ThisType operator++(int)
RDKit::AtomIterator_::operator[]
Atom_ * operator[](const int which) const
RDKit::MatchingAtomIterator_::~MatchingAtomIterator_
~MatchingAtomIterator_()
RDKit::AromaticAtomIterator_::ThisType
AromaticAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:111
RDKit::QueryAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::HeteroatomIterator_::ThisType
HeteroatomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:75
RDKit::HeteroatomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::QueryAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::HeteroatomIterator_
Iterate over heteroatoms, this is bidirectional.
Definition: AtomIterators.h:73
RDKit::AtomIterator_::operator++
ThisType operator++(int)
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_(Mol_ *mol, int pos)
RDKit::AromaticAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::AtomIterator_::operator+
AtomIterator_ operator+(int val) const
RDKit::HeteroatomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::HeteroatomIterator_::operator*
Atom_ * operator*() const
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition: export.h:307
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_()
Definition: AtomIterators.h:144
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_(Mol_ *mol, bool(*fn)(Atom_ *))
RDKit::AtomIterator_::operator*
Atom_ * operator*() const
RDKit::HeteroatomIterator_::~HeteroatomIterator_
~HeteroatomIterator_()
RDKit::QueryAtomIterator_::operator++
ThisType & operator++()
RDKit::MatchingAtomIterator_::operator*
Atom_ * operator*() const
RDKit::MatchingAtomIterator_::ThisType
MatchingAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:176
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_(Mol_ *mol, int pos)
RDKit::AtomIterator_::operator++
ThisType & operator++()
RDKit::AtomIterator_::operator>=
bool operator>=(const ThisType &other) const
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_(Mol_ *mol, QueryAtom const *what)
RDKit::MatchingAtomIterator_::operator++
ThisType operator++(int)
RDKit::AtomIterator_::operator>
bool operator>(const ThisType &other) const
RDKit::AtomIterator_::operator+=
AtomIterator_ & operator+=(int val)
RDKit::HeteroatomIterator_::operator=
HeteroatomIterator_ & operator=(const ThisType &other)
RDKit::QueryAtomIterator_::ThisType
QueryAtomIterator_< Atom_, Mol_ > ThisType
Definition: AtomIterators.h:143
RDKit::AtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_()
Definition: AtomIterators.h:112
RDKit::AromaticAtomIterator_::operator++
ThisType & operator++()
RDKit::AtomIterator_::operator<=
bool operator<=(const ThisType &other) const
RDKit::MatchingAtomIterator_::operator=
MatchingAtomIterator_ & operator=(const ThisType &other)
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_(const ThisType &other)
RDKit::AtomIterator_::operator<
bool operator<(const ThisType &other) const
RDKit::QueryAtomIterator_::operator--
ThisType operator--(int)
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_(const ThisType &other)
RDKit::AtomIterator_::AtomIterator_
AtomIterator_(const ThisType &other)
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_(Mol_ *mol, int pos)
RDKit::QueryAtomIterator_::~QueryAtomIterator_
~QueryAtomIterator_()
RDKit::QueryAtomIterator_::operator--
ThisType & operator--()
RDKit::QueryAtomIterator_::operator++
ThisType operator++(int)
RDKit::AtomIterator_::operator=
AtomIterator_ & operator=(const ThisType &other)
RDKit::AtomIterator_::operator--
ThisType & operator--()
RDKit::QueryAtom
Class for storing atomic queries.
Definition: QueryAtom.h:27
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_(const ThisType &other)
RDKit::AtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_(Mol_ *mol)
RDKit::AtomIterator_::operator-
AtomIterator_ operator-(int val) const
RDKit::HeteroatomIterator_::operator--
ThisType & operator--()
RDKit::MatchingAtomIterator_
Iterate over atoms matching a query function. This is bidirectional.
Definition: AtomIterators.h:174
RDKit::AtomIterator_::AtomIterator_
AtomIterator_()
Definition: AtomIterators.h:34
RDKit::AromaticAtomIterator_::operator--
ThisType & operator--()
RDKit::MatchingAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::HeteroatomIterator_::operator++
ThisType & operator++()
RDKit::MatchingAtomIterator_::operator++
ThisType & operator++()
export.h