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_, class PMAP_>
00025   class AtomIterator_ {
00026   public:
00027     typedef AtomIterator_<Atom_,Mol_,PMAP_> 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     PMAP_ _pMap;
00064   };
00065 
00066 
00067   //! Iterate over heteroatoms, this is bidirectional
00068   template <class Atom_, class Mol_, class PMAP_>
00069   class HeteroatomIterator_ {
00070   public:
00071     typedef HeteroatomIterator_<Atom_,Mol_,PMAP_> ThisType;
00072     HeteroatomIterator_() : _mol(0) {}; 
00073     HeteroatomIterator_(Mol_ * mol);
00074     HeteroatomIterator_(Mol_ * mol,int pos);
00075     ~HeteroatomIterator_();
00076     HeteroatomIterator_(const ThisType &other);
00077     HeteroatomIterator_ &operator=(const ThisType &other);
00078     bool operator==(const ThisType &other);
00079     bool operator!=(const ThisType &other);
00080 
00081     Atom_ * operator*();
00082 
00083     // pre-increment
00084     ThisType &operator++();
00085     ThisType operator++(int);
00086 
00087     // pre-decrement
00088     ThisType &operator--();
00089     ThisType operator--(int);
00090   private:
00091     PMAP_ _pMap;
00092     int _end,_pos;
00093     Mol_ * _mol;
00094     //FIX: somehow changing the following to a pointer make the regression test pass
00095     // QueryAtom _qA;
00096     QueryAtom *_qA;
00097 
00098     int _findNext(int from);  
00099     int _findPrev(int from);
00100   };
00101 
00102 
00103 
00104   //! Iterate over aromatic atoms, this is bidirectional
00105   template <class Atom_, class Mol_, class PMAP_>
00106   class AromaticAtomIterator_ {
00107   public:
00108     typedef AromaticAtomIterator_<Atom_,Mol_,PMAP_> ThisType;
00109     AromaticAtomIterator_() : _mol(0) {}; 
00110     AromaticAtomIterator_(Mol_ * mol);
00111     AromaticAtomIterator_(Mol_ * mol,int pos);
00112     ~AromaticAtomIterator_();
00113     AromaticAtomIterator_(const ThisType &other);
00114     AromaticAtomIterator_ &operator=(const ThisType &other);
00115     bool operator==(const ThisType &other);
00116     bool operator!=(const ThisType &other);
00117 
00118     Atom_ * operator*();
00119 
00120     // pre-increment
00121     ThisType &operator++();
00122     ThisType operator++(int);
00123 
00124     // pre-decrement
00125     ThisType &operator--();
00126     ThisType operator--(int);
00127   private:
00128     PMAP_ _pMap;
00129     int _end,_pos;
00130     Mol_ * _mol;
00131 
00132     int _findNext(int from);  
00133     int _findPrev(int from);
00134   };
00135 
00136 
00137   
00138   //! Iterate over atoms matching a query. This is bidirectional.
00139   template <class Atom_, class Mol_, class PMAP_>
00140   class QueryAtomIterator_ {
00141   public:
00142     typedef QueryAtomIterator_<Atom_,Mol_,PMAP_> ThisType;
00143     QueryAtomIterator_() : _mol(0),_qA(0) {}; 
00144     QueryAtomIterator_(Mol_ * mol,QueryAtom const *what);
00145     QueryAtomIterator_(Mol_ * mol,int pos);
00146     ~QueryAtomIterator_();
00147     QueryAtomIterator_(const ThisType &other);
00148     QueryAtomIterator_ &operator=(const ThisType &other);
00149     bool operator==(const ThisType &other);
00150     bool operator!=(const ThisType &other);
00151 
00152     Atom_ * operator*();
00153 
00154     // pre-increment
00155     ThisType &operator++();
00156     ThisType operator++(int);
00157 
00158     // pre-decrement
00159     ThisType &operator--();
00160     ThisType operator--(int);
00161   private:
00162     PMAP_ _pMap;
00163     int _end,_pos;
00164     Mol_ * _mol;
00165     QueryAtom *_qA;
00166 
00167     int _findNext(int from);  
00168     int _findPrev(int from);
00169   };
00170 
00171 }  /* end o namespace */
00172 
00173 #endif

Generated on Sat May 24 08:36:32 2008 for RDCode by  doxygen 1.5.3