obiter.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 obiter.h - STL-style iterators for Open Babel.
00003  
00004 Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
00005 Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison
00006  
00007 This file is part of the Open Babel project.
00008 For more information, see <http://openbabel.sourceforge.net/>
00009  
00010 This program is free software; you can redistribute it and/or modify
00011 it under the terms of the GNU General Public License as published by
00012 the Free Software Foundation version 2 of the License.
00013  
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 ***********************************************************************/
00019 
00020 #ifndef OB_OBITER_H
00021 #define OB_OBITER_H
00022 
00023 #include <vector>
00024 
00025 namespace OpenBabel
00026 {
00027 
00028   class OBMol;
00029   class OBAtom;
00030   class OBBond;
00031   class OBResidue;
00032 
00034 class OBAPI OBMolAtomIter {
00035     std::vector<OBNodeBase*>::iterator _i;
00036     OBMol *_parent;
00037     OBAtom *_ptr;
00038 public:
00039 
00040     OBMolAtomIter()              { _parent = NULL; _ptr = NULL; }
00041     OBMolAtomIter(OBMol *mol);
00042     OBMolAtomIter(OBMol &mol);
00043     OBMolAtomIter(const OBMolAtomIter &ai);
00044 
00045     OBMolAtomIter& operator=(const OBMolAtomIter &ai);
00046     operator bool() const        { return _ptr != NULL; }
00047     OBMolAtomIter operator++(int);
00048     OBAtom* operator->() const   { return _ptr;      }
00049     OBAtom& operator*() const    { return *_ptr;     }
00050 };
00051 
00053 class OBAPI OBMolBondIter {
00054     std::vector<OBEdgeBase*>::iterator _i;
00055     OBMol *_parent;
00056     OBBond *_ptr;
00057 public:
00058 
00059     OBMolBondIter()              { _parent = NULL; _ptr = NULL; }
00060     OBMolBondIter(OBMol *mol);
00061     OBMolBondIter(OBMol &mol);
00062     OBMolBondIter(const OBMolBondIter &bi);
00063 
00064     OBMolBondIter& operator=(const OBMolBondIter &bi);
00065     operator bool() const        { return _ptr != NULL; }
00066     OBMolBondIter operator++(int);
00067     OBBond* operator->() const   { return _ptr;      }
00068     OBBond& operator*() const    { return *_ptr;     }
00069 };
00070 
00072 class OBAPI OBAtomAtomIter {
00073     std::vector<OBEdgeBase*>::iterator _i;
00074     OBAtom *_parent;
00075     OBAtom *_ptr;
00076 public:
00077 
00078     OBAtomAtomIter()             { _parent = NULL; _ptr = NULL; }
00079     OBAtomAtomIter(OBAtom *atm);
00080     OBAtomAtomIter(OBAtom &atm);
00081     OBAtomAtomIter(const OBAtomAtomIter &ai);
00082 
00083     OBAtomAtomIter& operator=(const OBAtomAtomIter &ai);
00084     operator bool() const        { return _ptr != NULL; }
00085     OBAtomAtomIter operator++(int);
00086     OBAtom* operator->() const   { return _ptr; }
00087     OBAtom& operator*() const    { return *_ptr;}
00088 };
00089 
00091 class OBAPI OBAtomBondIter {
00092     std::vector<OBEdgeBase*>::iterator _i;
00093     OBAtom *_parent;
00094     OBBond *_ptr;
00095 public:
00096 
00097     OBAtomBondIter()             { _parent = NULL; _ptr = NULL; }
00098     OBAtomBondIter(OBAtom *atm);
00099     OBAtomBondIter(OBAtom &atm);
00100     OBAtomBondIter(const OBAtomBondIter &bi);
00101 
00102     OBAtomBondIter& operator=(const OBAtomBondIter &bi);
00103     operator bool() const        { return _ptr != NULL; }
00104     OBAtomBondIter operator++(int);
00105     OBBond* operator->() const   { return _ptr; }
00106     OBBond& operator*() const    { return *_ptr;}
00107 };
00108 
00110 class OBAPI OBResidueIter {
00111     std::vector<OBResidue*>::iterator _i;
00112     OBResidue *_ptr;
00113     OBMol *_parent;
00114 public:
00115 
00116     OBResidueIter()              { _parent = NULL; _ptr = NULL; }
00117     OBResidueIter(OBMol *mol);
00118     OBResidueIter(OBMol &mol);
00119     OBResidueIter(const OBResidueIter &ri);
00120 
00121     OBResidueIter& operator=(const OBResidueIter &ri);
00122     operator bool() const        { return _ptr != NULL; }
00123     OBResidueIter operator++(int);
00124     OBResidue* operator->() const{ return _ptr; }
00125     OBResidue& operator*() const { return *_ptr;}
00126 };
00127 
00129 class OBAPI OBResidueAtomIter {
00130     std::vector<OBAtom*>::iterator _i;
00131     OBResidue *_parent;
00132     OBAtom    *_ptr;
00133 public:
00134 
00135     OBResidueAtomIter()          { _parent = NULL; _ptr = NULL; }
00136     OBResidueAtomIter(OBResidue *res);
00137     OBResidueAtomIter(OBResidue &res);
00138     OBResidueAtomIter(const OBResidueAtomIter &ri);
00139 
00140     OBResidueAtomIter &operator = (const OBResidueAtomIter &ri);
00141     operator bool() const        { return _ptr != NULL; }
00142     OBResidueAtomIter operator++ (int);
00143     OBAtom *operator->() const   { return _ptr; }
00144     OBAtom &operator*() const    { return *_ptr;}
00145 };
00146 
00147 #define FOR_ATOMS_OF_MOL(a,m)     for( OBMolAtomIter     a(m); a; a++ )
00148 #define FOR_BONDS_OF_MOL(b,m)     for( OBMolBondIter     b(m); b; b++ )
00149 #define FOR_NBORS_OF_ATOM(a,p)    for( OBAtomAtomIter    a(p); a; a++ )
00150 #define FOR_BONDS_OF_ATOM(b,p)    for( OBAtomBondIter    b(p); b; b++ )
00151 #define FOR_RESIDUES_OF_MOL(r,m)  for( OBResidueIter     r(m); r; r++ )
00152 #define FOR_ATOMS_OF_RESIDUE(a,r) for( OBResidueAtomIter a(r); a; a++ )
00153 
00154 } // namespace OpenBabel
00155 #endif // OB_OBITER_H
00156