RDCode: AtomIterators.h Source File

# AtomIterators.h

Go to the documentation of this file.

    00001 //
    00002 //  Copyright (C) 2002-2006 Greg Landrum and Rational Discovery LLC
    00003 //
    00004 //   @@ All Rights Reserved  @@
    00005 //
    00006 /*! \file AtomIterators.h
    00007
    00008   \brief various tools for iterating over a molecule's Atoms.
    00009
    00010    <b>WARNING:</b> If you go changing the molecule underneath one of
    00011    these iterators you will be sad...
    00012 */
    00013 #ifndef __RD_ATOM_ITERATORS_H__
    00014 #define __RD_ATOM_ITERATORS_H__
    00015
    00016 #ifdef _MSC_VER
    00017 #pragma warning (disable: 4661)  // no suitable definition provided for explicit template instantiation request
    00018 #endif
    00019
    00020 namespace RDKit{
    00021   class QueryAtom;
    00022
    00023   //! A general random access iterator
    00024   template <class Atom_, class Mol_>
    00025   class AtomIterator_ {
    00026   public:
    00027     typedef AtomIterator_<Atom_,Mol_> ThisType;
    00028     AtomIterator_() : _pos(0),_max(-1),_mol(0) {};
    00029     AtomIterator_(Mol_ * mol);
    00030     AtomIterator_(Mol_ * mol,int pos);
    00031     AtomIterator_(const ThisType &other);
    00032     AtomIterator_ &operator=(const ThisType &other);
    00033     AtomIterator_ &operator+=(int val);
    00034     AtomIterator_ &operator-=(int val);
    00035     AtomIterator_ operator+(int val);
    00036     AtomIterator_ operator-(int val);
    00037
    00038     // iterator subtraction
    00039     int operator-(ThisType &other);
    00040
    00041     // dereference
    00042     Atom_ * operator*();
    00043     // random access
    00044     Atom_ * operator[](const int which);
    00045     bool operator==(const ThisType &other);
    00046     bool operator!=(const ThisType &other);
    00047     bool operator<(const ThisType &other);
    00048     bool operator<=(const ThisType &other);
    00049     bool operator>(const ThisType &other);
    00050     bool operator>=(const ThisType &other);
    00051
    00052     // pre-increment
    00053     ThisType &operator++();
    00054     ThisType operator++(int);
    00055
    00056     // pre-decrement
    00057     ThisType &operator--();
    00058     ThisType operator--(int);
    00059
    00060   private:
    00061     int _pos,_max;
    00062     Mol_ * _mol;
    00063   };
    00064
    00065
    00066   //! Iterate over heteroatoms, this is bidirectional
    00067   template <class Atom_, class Mol_>
    00068   class HeteroatomIterator_ {
    00069   public:
    00070     typedef HeteroatomIterator_<Atom_,Mol_> ThisType;
    00071     HeteroatomIterator_() : _mol(0) {};
    00072     HeteroatomIterator_(Mol_ * mol);
    00073     HeteroatomIterator_(Mol_ * mol,int pos);
    00074     ~HeteroatomIterator_();
    00075     HeteroatomIterator_(const ThisType &other);
    00076     HeteroatomIterator_ &operator=(const ThisType &other);
    00077     bool operator==(const ThisType &other);
    00078     bool operator!=(const ThisType &other);
    00079
    00080     Atom_ * operator*();
    00081
    00082     // pre-increment
    00083     ThisType &operator++();
    00084     ThisType operator++(int);
    00085
    00086     // pre-decrement
    00087     ThisType &operator--();
    00088     ThisType operator--(int);
    00089   private:
    00090     int _end,_pos;
    00091     Mol_ * _mol;
    00092     //FIX: somehow changing the following to a pointer make the regression test pass
    00093     // QueryAtom _qA;
    00094     QueryAtom *_qA;
    00095
    00096     int _findNext(int from);
    00097     int _findPrev(int from);
    00098   };
    00099
    00100
    00101
    00102   //! Iterate over aromatic atoms, this is bidirectional
    00103   template <class Atom_, class Mol_>
    00104   class AromaticAtomIterator_ {
    00105   public:
    00106     typedef AromaticAtomIterator_<Atom_,Mol_> ThisType;
    00107     AromaticAtomIterator_() : _mol(0) {};
    00108     AromaticAtomIterator_(Mol_ * mol);
    00109     AromaticAtomIterator_(Mol_ * mol,int pos);
    00110     ~AromaticAtomIterator_();
    00111     AromaticAtomIterator_(const ThisType &other);
    00112     AromaticAtomIterator_ &operator=(const ThisType &other);
    00113     bool operator==(const ThisType &other);
    00114     bool operator!=(const ThisType &other);
    00115
    00116     Atom_ * operator*();
    00117
    00118     // pre-increment
    00119     ThisType &operator++();
    00120     ThisType operator++(int);
    00121
    00122     // pre-decrement
    00123     ThisType &operator--();
    00124     ThisType operator--(int);
    00125   private:
    00126     int _end,_pos;
    00127     Mol_ * _mol;
    00128
    00129     int _findNext(int from);
    00130     int _findPrev(int from);
    00131   };
    00132
    00133
    00134
    00135   //! Iterate over atoms matching a query. This is bidirectional.
    00136   template <class Atom_, class Mol_>
    00137   class QueryAtomIterator_ {
    00138   public:
    00139     typedef QueryAtomIterator_<Atom_,Mol_> ThisType;
    00140     QueryAtomIterator_() : _mol(0),_qA(0) {};
    00141     QueryAtomIterator_(Mol_ * mol,QueryAtom const *what);
    00142     QueryAtomIterator_(Mol_ * mol,int pos);
    00143     ~QueryAtomIterator_();
    00144     QueryAtomIterator_(const ThisType &other);
    00145     QueryAtomIterator_ &operator=(const ThisType &other);
    00146     bool operator==(const ThisType &other);
    00147     bool operator!=(const ThisType &other);
    00148
    00149     Atom_ * operator*();
    00150
    00151     // pre-increment
    00152     ThisType &operator++();
    00153     ThisType operator++(int);
    00154
    00155     // pre-decrement
    00156     ThisType &operator--();
    00157     ThisType operator--(int);
    00158   private:
    00159     int _end,_pos;
    00160     Mol_ * _mol;
    00161     QueryAtom *_qA;
    00162
    00163     int _findNext(int from);
    00164     int _findPrev(int from);
    00165   };
    00166
    00167
    00168 }  /* end o namespace */
    00169
    00170 #endif