| 1 |
tim |
741 |
/********************************************************************** |
| 2 |
|
|
obiter.h - STL-style iterators for Open Babel. |
| 3 |
|
|
|
| 4 |
|
|
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. |
| 5 |
|
|
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison |
| 6 |
|
|
|
| 7 |
|
|
This file is part of the Open Babel project. |
| 8 |
|
|
For more information, see <http://openbabel.sourceforge.net/> |
| 9 |
|
|
|
| 10 |
|
|
This program is free software; you can redistribute it and/or modify |
| 11 |
|
|
it under the terms of the GNU General Public License as published by |
| 12 |
|
|
the Free Software Foundation version 2 of the License. |
| 13 |
|
|
|
| 14 |
|
|
This program is distributed in the hope that it will be useful, |
| 15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
|
|
GNU General Public License for more details. |
| 18 |
|
|
***********************************************************************/ |
| 19 |
|
|
|
| 20 |
|
|
#ifndef OB_OBITER_H |
| 21 |
|
|
#define OB_OBITER_H |
| 22 |
|
|
|
| 23 |
|
|
#include <vector> |
| 24 |
|
|
|
| 25 |
|
|
namespace OpenBabel |
| 26 |
|
|
{ |
| 27 |
|
|
|
| 28 |
|
|
class OBMol; |
| 29 |
|
|
class OBAtom; |
| 30 |
|
|
class OBBond; |
| 31 |
|
|
class OBResidue; |
| 32 |
|
|
|
| 33 |
|
|
//! \brief Iterate over all atoms in an OBMol |
| 34 |
|
|
class OBAPI OBMolAtomIter { |
| 35 |
|
|
std::vector<OBNodeBase*>::iterator _i; |
| 36 |
|
|
OBMol *_parent; |
| 37 |
|
|
OBAtom *_ptr; |
| 38 |
|
|
public: |
| 39 |
|
|
|
| 40 |
|
|
OBMolAtomIter() { _parent = NULL; _ptr = NULL; } |
| 41 |
|
|
OBMolAtomIter(OBMol *mol); |
| 42 |
|
|
OBMolAtomIter(OBMol &mol); |
| 43 |
|
|
OBMolAtomIter(const OBMolAtomIter &ai); |
| 44 |
|
|
|
| 45 |
|
|
OBMolAtomIter& operator=(const OBMolAtomIter &ai); |
| 46 |
|
|
operator bool() const { return _ptr != NULL; } |
| 47 |
|
|
OBMolAtomIter operator++(int); |
| 48 |
|
|
OBAtom* operator->() const { return _ptr; } |
| 49 |
|
|
OBAtom& operator*() const { return *_ptr; } |
| 50 |
|
|
}; |
| 51 |
|
|
|
| 52 |
|
|
//! \brief Iterate over all bonds in an OBMol |
| 53 |
|
|
class OBAPI OBMolBondIter { |
| 54 |
|
|
std::vector<OBEdgeBase*>::iterator _i; |
| 55 |
|
|
OBMol *_parent; |
| 56 |
|
|
OBBond *_ptr; |
| 57 |
|
|
public: |
| 58 |
|
|
|
| 59 |
|
|
OBMolBondIter() { _parent = NULL; _ptr = NULL; } |
| 60 |
|
|
OBMolBondIter(OBMol *mol); |
| 61 |
|
|
OBMolBondIter(OBMol &mol); |
| 62 |
|
|
OBMolBondIter(const OBMolBondIter &bi); |
| 63 |
|
|
|
| 64 |
|
|
OBMolBondIter& operator=(const OBMolBondIter &bi); |
| 65 |
|
|
operator bool() const { return _ptr != NULL; } |
| 66 |
|
|
OBMolBondIter operator++(int); |
| 67 |
|
|
OBBond* operator->() const { return _ptr; } |
| 68 |
|
|
OBBond& operator*() const { return *_ptr; } |
| 69 |
|
|
}; |
| 70 |
|
|
|
| 71 |
|
|
//! \brief Iterate over all neighboring atoms to an OBAtom |
| 72 |
|
|
class OBAPI OBAtomAtomIter { |
| 73 |
|
|
std::vector<OBEdgeBase*>::iterator _i; |
| 74 |
|
|
OBAtom *_parent; |
| 75 |
|
|
OBAtom *_ptr; |
| 76 |
|
|
public: |
| 77 |
|
|
|
| 78 |
|
|
OBAtomAtomIter() { _parent = NULL; _ptr = NULL; } |
| 79 |
|
|
OBAtomAtomIter(OBAtom *atm); |
| 80 |
|
|
OBAtomAtomIter(OBAtom &atm); |
| 81 |
|
|
OBAtomAtomIter(const OBAtomAtomIter &ai); |
| 82 |
|
|
|
| 83 |
|
|
OBAtomAtomIter& operator=(const OBAtomAtomIter &ai); |
| 84 |
|
|
operator bool() const { return _ptr != NULL; } |
| 85 |
|
|
OBAtomAtomIter operator++(int); |
| 86 |
|
|
OBAtom* operator->() const { return _ptr; } |
| 87 |
|
|
OBAtom& operator*() const { return *_ptr;} |
| 88 |
|
|
}; |
| 89 |
|
|
|
| 90 |
|
|
//! \brief Iterate over all bonds on an OBAtom |
| 91 |
|
|
class OBAPI OBAtomBondIter { |
| 92 |
|
|
std::vector<OBEdgeBase*>::iterator _i; |
| 93 |
|
|
OBAtom *_parent; |
| 94 |
|
|
OBBond *_ptr; |
| 95 |
|
|
public: |
| 96 |
|
|
|
| 97 |
|
|
OBAtomBondIter() { _parent = NULL; _ptr = NULL; } |
| 98 |
|
|
OBAtomBondIter(OBAtom *atm); |
| 99 |
|
|
OBAtomBondIter(OBAtom &atm); |
| 100 |
|
|
OBAtomBondIter(const OBAtomBondIter &bi); |
| 101 |
|
|
|
| 102 |
|
|
OBAtomBondIter& operator=(const OBAtomBondIter &bi); |
| 103 |
|
|
operator bool() const { return _ptr != NULL; } |
| 104 |
|
|
OBAtomBondIter operator++(int); |
| 105 |
|
|
OBBond* operator->() const { return _ptr; } |
| 106 |
|
|
OBBond& operator*() const { return *_ptr;} |
| 107 |
|
|
}; |
| 108 |
|
|
|
| 109 |
|
|
//! \brief Iterate over all residues in an OBMol |
| 110 |
|
|
class OBAPI OBResidueIter { |
| 111 |
|
|
std::vector<OBResidue*>::iterator _i; |
| 112 |
|
|
OBResidue *_ptr; |
| 113 |
|
|
OBMol *_parent; |
| 114 |
|
|
public: |
| 115 |
|
|
|
| 116 |
|
|
OBResidueIter() { _parent = NULL; _ptr = NULL; } |
| 117 |
|
|
OBResidueIter(OBMol *mol); |
| 118 |
|
|
OBResidueIter(OBMol &mol); |
| 119 |
|
|
OBResidueIter(const OBResidueIter &ri); |
| 120 |
|
|
|
| 121 |
|
|
OBResidueIter& operator=(const OBResidueIter &ri); |
| 122 |
|
|
operator bool() const { return _ptr != NULL; } |
| 123 |
|
|
OBResidueIter operator++(int); |
| 124 |
|
|
OBResidue* operator->() const{ return _ptr; } |
| 125 |
|
|
OBResidue& operator*() const { return *_ptr;} |
| 126 |
|
|
}; |
| 127 |
|
|
|
| 128 |
|
|
//! \brief Iterate over all atoms in an OBResidue |
| 129 |
|
|
class OBAPI OBResidueAtomIter { |
| 130 |
|
|
std::vector<OBAtom*>::iterator _i; |
| 131 |
|
|
OBResidue *_parent; |
| 132 |
|
|
OBAtom *_ptr; |
| 133 |
|
|
public: |
| 134 |
|
|
|
| 135 |
|
|
OBResidueAtomIter() { _parent = NULL; _ptr = NULL; } |
| 136 |
|
|
OBResidueAtomIter(OBResidue *res); |
| 137 |
|
|
OBResidueAtomIter(OBResidue &res); |
| 138 |
|
|
OBResidueAtomIter(const OBResidueAtomIter &ri); |
| 139 |
|
|
|
| 140 |
|
|
OBResidueAtomIter &operator = (const OBResidueAtomIter &ri); |
| 141 |
|
|
operator bool() const { return _ptr != NULL; } |
| 142 |
|
|
OBResidueAtomIter operator++ (int); |
| 143 |
|
|
OBAtom *operator->() const { return _ptr; } |
| 144 |
|
|
OBAtom &operator*() const { return *_ptr;} |
| 145 |
|
|
}; |
| 146 |
|
|
|
| 147 |
|
|
#define FOR_ATOMS_OF_MOL(a,m) for( OBMolAtomIter a(m); a; a++ ) |
| 148 |
|
|
#define FOR_BONDS_OF_MOL(b,m) for( OBMolBondIter b(m); b; b++ ) |
| 149 |
|
|
#define FOR_NBORS_OF_ATOM(a,p) for( OBAtomAtomIter a(p); a; a++ ) |
| 150 |
|
|
#define FOR_BONDS_OF_ATOM(b,p) for( OBAtomBondIter b(p); b; b++ ) |
| 151 |
|
|
#define FOR_RESIDUES_OF_MOL(r,m) for( OBResidueIter r(m); r; r++ ) |
| 152 |
|
|
#define FOR_ATOMS_OF_RESIDUE(a,r) for( OBResidueAtomIter a(r); a; a++ ) |
| 153 |
|
|
|
| 154 |
|
|
} // namespace OpenBabel |
| 155 |
|
|
#endif // OB_OBITER_H |
| 156 |
|
|
|
| 157 |
|
|
//! \file obiter.h |
| 158 |
|
|
//! \brief STL-style iterators for Open Babel. |