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-2006 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 <openbabel/babelconfig.h> 00024 #include <openbabel/base.h> 00025 #include <openbabel/bitvec.h> 00026 00027 #include <vector> 00028 #include <stack> 00029 #include <queue> 00030 00031 namespace OpenBabel 00032 { 00033 00034 class OBMol; 00035 class OBAtom; 00036 class OBBond; 00037 class OBResidue; 00038 00039 // more detailed descriptions and documentation in obiter.cpp 00040 00042 class OBAPI OBMolAtomIter { 00043 std::vector<OBAtom*>::iterator _i; 00044 OBMol *_parent; 00045 OBAtom *_ptr; 00046 public: 00047 00048 OBMolAtomIter() :_parent(NULL), _ptr(NULL) { } 00049 OBMolAtomIter(OBMol *mol); 00050 OBMolAtomIter(OBMol &mol); 00051 OBMolAtomIter(const OBMolAtomIter &ai); 00052 ~OBMolAtomIter() { } 00053 00054 OBMolAtomIter& operator=(const OBMolAtomIter &ai); 00056 operator bool() const { return _ptr != NULL; } 00058 OBMolAtomIter& operator++(); 00060 OBMolAtomIter operator++(int); 00062 OBAtom* operator->() const { return _ptr; } 00064 OBAtom& operator*() const { return *_ptr; } 00065 }; 00066 00068 class OBAPI OBMolAtomDFSIter { 00069 OBMol *_parent; 00070 OBAtom *_ptr; 00071 OBBitVec _notVisited; 00072 std::stack<OBAtom *> _stack; 00073 public: 00074 00075 OBMolAtomDFSIter() : _parent(NULL), _ptr(NULL) { } 00076 OBMolAtomDFSIter(OBMol *mol, int StartIndex=1); 00077 OBMolAtomDFSIter(OBMol &mol, int StartIndex=1); 00078 OBMolAtomDFSIter(const OBMolAtomDFSIter &ai); 00079 ~OBMolAtomDFSIter() { } 00080 00081 OBMolAtomDFSIter& operator=(const OBMolAtomDFSIter &ai); 00083 operator bool() const { return _ptr != NULL; } 00085 OBMolAtomDFSIter& operator++(); 00087 OBMolAtomDFSIter operator++(int); 00089 OBAtom* operator->() const { return _ptr; } 00091 OBAtom& operator*() const { return *_ptr; } 00093 OBAtom* next() 00094 { 00095 if(_stack.empty()) 00096 return NULL; //end of a disconnected fragment 00097 else 00098 return _stack.top(); //the next atom 00099 } 00100 }; 00101 00103 class OBAPI OBMolAtomBFSIter { 00104 OBMol *_parent; 00105 OBAtom *_ptr; 00106 OBBitVec _notVisited; 00107 std::queue<OBAtom *> _queue; 00108 std::vector<int> _depth; 00109 public: 00110 00111 OBMolAtomBFSIter(): _parent(NULL), _ptr(NULL) { } 00112 OBMolAtomBFSIter(OBMol *mol, int StartIndex = 1); 00113 OBMolAtomBFSIter(OBMol &mol, int StartIndex = 1); 00114 OBMolAtomBFSIter(const OBMolAtomBFSIter &ai); 00115 ~OBMolAtomBFSIter() { } 00116 00117 OBMolAtomBFSIter& operator=(const OBMolAtomBFSIter &ai); 00119 operator bool() const { return _ptr != NULL; } 00121 OBMolAtomBFSIter& operator++(); 00123 OBMolAtomBFSIter operator++(int); 00125 OBAtom* operator->() const { return _ptr; } 00127 OBAtom& operator*() const { return *_ptr; } 00130 int CurrentDepth() const; 00131 }; 00132 00134 class OBAPI OBMolBondIter { 00135 std::vector<OBBond*>::iterator _i; 00136 OBMol *_parent; 00137 OBBond *_ptr; 00138 public: 00139 00140 OBMolBondIter() : _parent(NULL), _ptr(NULL) {} 00141 OBMolBondIter(OBMol *mol); 00142 OBMolBondIter(OBMol &mol); 00143 OBMolBondIter(const OBMolBondIter &bi); 00144 ~OBMolBondIter() { } 00145 00146 OBMolBondIter& operator=(const OBMolBondIter &bi); 00148 operator bool() const { return _ptr != NULL; } 00150 OBMolBondIter& operator++(); 00152 OBMolBondIter operator++(int); 00154 OBBond* operator->() const { return _ptr; } 00156 OBBond& operator*() const { return *_ptr; } 00157 }; 00158 00160 class OBAPI OBAtomAtomIter { 00161 std::vector<OBBond*>::iterator _i; 00162 OBAtom *_parent; 00163 OBAtom *_ptr; 00164 public: 00165 00166 OBAtomAtomIter() : _parent(NULL), _ptr(NULL) { } 00167 OBAtomAtomIter(OBAtom *atm); 00168 OBAtomAtomIter(OBAtom &atm); 00169 OBAtomAtomIter(const OBAtomAtomIter &ai); 00170 ~OBAtomAtomIter() { } 00171 00172 OBAtomAtomIter& operator=(const OBAtomAtomIter &ai); 00174 operator bool() const { return _ptr != NULL; } 00176 OBAtomAtomIter& operator++(); 00178 OBAtomAtomIter operator++(int); 00180 OBAtom* operator->() const { return _ptr; } 00182 OBAtom& operator*() const { return *_ptr; } 00183 }; 00184 00186 class OBAPI OBAtomBondIter { 00187 std::vector<OBBond*>::iterator _i; 00188 OBAtom *_parent; 00189 OBBond *_ptr; 00190 public: 00191 00192 OBAtomBondIter(): _parent(NULL), _ptr(NULL) { } 00193 OBAtomBondIter(OBAtom *atm); 00194 OBAtomBondIter(OBAtom &atm); 00195 OBAtomBondIter(const OBAtomBondIter &bi); 00196 ~OBAtomBondIter() { } 00197 00198 OBAtomBondIter& operator=(const OBAtomBondIter &bi); 00200 operator bool() const { return _ptr != NULL; } 00202 OBAtomBondIter& operator++(); 00204 OBAtomBondIter operator++(int); 00206 OBBond* operator->() const { return _ptr; } 00208 OBBond& operator*() const { return *_ptr;} 00209 }; 00210 00212 class OBAPI OBResidueIter { 00213 std::vector<OBResidue*>::iterator _i; 00214 OBResidue *_ptr; 00215 OBMol *_parent; 00216 public: 00217 00218 OBResidueIter() : _ptr(NULL), _parent(NULL) { } 00219 OBResidueIter(OBMol *mol); 00220 OBResidueIter(OBMol &mol); 00221 OBResidueIter(const OBResidueIter &ri); 00222 ~OBResidueIter() { } 00223 00224 OBResidueIter& operator=(const OBResidueIter &ri); 00226 operator bool() const { return _ptr != NULL; } 00228 OBResidueIter& operator++(); 00230 OBResidueIter operator++(int); 00232 OBResidue* operator->() const{ return _ptr; } 00234 OBResidue& operator*() const { return *_ptr;} 00235 }; 00236 00238 class OBAPI OBResidueAtomIter { 00239 std::vector<OBAtom*>::iterator _i; 00240 OBResidue *_parent; 00241 OBAtom *_ptr; 00242 public: 00243 00244 OBResidueAtomIter() : _parent(NULL), _ptr(NULL) { } 00245 OBResidueAtomIter(OBResidue *res); 00246 OBResidueAtomIter(OBResidue &res); 00247 OBResidueAtomIter(const OBResidueAtomIter &ri); 00248 ~OBResidueAtomIter() { } 00249 00250 OBResidueAtomIter &operator = (const OBResidueAtomIter &ri); 00252 operator bool() const { return _ptr != NULL; } 00254 OBResidueAtomIter& operator++ (); 00256 OBResidueAtomIter operator++ (int); 00258 OBAtom *operator->() const { return _ptr; } 00260 OBAtom &operator*() const { return *_ptr;} 00261 }; 00262 00264 class OBAPI OBMolAngleIter { 00265 OBMol *_parent; 00266 std::vector<std::vector<unsigned int> > _vangle; 00267 std::vector<std::vector<unsigned int> >::iterator _i; 00268 std::vector<unsigned int> _angle; 00269 public: 00270 00271 OBMolAngleIter() :_parent(NULL) { } 00272 OBMolAngleIter(OBMol *mol); 00273 OBMolAngleIter(OBMol &mol); 00274 OBMolAngleIter(const OBMolAngleIter &ai); 00275 ~OBMolAngleIter() { } 00276 00277 OBMolAngleIter& operator=(const OBMolAngleIter &ai); 00279 operator bool() const { return (_i != _vangle.end()); } 00281 OBMolAngleIter& operator++(); 00284 std::vector<unsigned int> operator*() const { return _angle; } 00285 }; 00286 00288 class OBAPI OBMolTorsionIter { 00289 OBMol *_parent; 00290 std::vector<std::vector<unsigned int> > _vtorsion; 00291 std::vector<std::vector<unsigned int> >::iterator _i; 00292 std::vector<unsigned int> _torsion; 00293 public: 00294 00295 OBMolTorsionIter() :_parent(NULL) { } 00296 OBMolTorsionIter(OBMol *mol); 00297 OBMolTorsionIter(OBMol &mol); 00298 OBMolTorsionIter(const OBMolTorsionIter &ai); 00299 ~OBMolTorsionIter() { } 00300 00301 OBMolTorsionIter& operator=(const OBMolTorsionIter &ai); 00303 operator bool() const { return (_i != _vtorsion.end()); } 00305 OBMolTorsionIter& operator++(); 00308 std::vector<unsigned int> operator*() const { return _torsion; } 00309 }; 00310 00312 class OBAPI OBMolPairIter { 00313 std::vector<OBAtom*>::iterator _i; 00314 std::vector<OBAtom*>::iterator _j; 00315 OBMol *_parent; 00316 //std::vector<std::vector<unsigned int> > _vpair; 00317 //std::vector<std::vector<unsigned int> >::iterator _i; 00318 std::vector<unsigned int> _pair; 00319 00320 public: 00321 00322 OBMolPairIter() :_parent(NULL) { } 00323 OBMolPairIter(OBMol *mol); 00324 OBMolPairIter(OBMol &mol); 00325 OBMolPairIter(const OBMolPairIter &ai); 00326 ~OBMolPairIter() { } 00327 00328 OBMolPairIter& operator=(const OBMolPairIter &ai); 00330 operator bool() const { return _pair.size()>0; } 00332 OBMolPairIter& operator++(); 00335 std::vector<unsigned int> operator*() const { return _pair; } 00336 }; 00337 00338 00340 class OBAPI OBMolRingIter { 00341 std::vector<OBRing*>::iterator _i; 00342 OBRing *_ptr; 00343 OBMol *_parent; 00344 OBRingData *_rings; 00345 public: 00346 00347 OBMolRingIter() : _ptr(NULL), _parent(NULL), _rings(NULL) { } 00348 OBMolRingIter(OBMol *mol); 00349 OBMolRingIter(OBMol &mol); 00350 OBMolRingIter(const OBMolRingIter &ri); 00351 ~OBMolRingIter() { } 00352 00353 OBMolRingIter& operator=(const OBMolRingIter &ri); 00355 operator bool() const { return _ptr != NULL; } 00357 OBMolRingIter& operator++(); 00359 OBMolRingIter operator++(int); 00361 OBRing* operator->() const { return _ptr; } 00363 OBRing& operator*() const { return *_ptr;} 00364 }; 00365 00366 #define FOR_ATOMS_OF_MOL(a,m) for( OBMolAtomIter a(m); a; ++a ) 00367 #define FOR_BONDS_OF_MOL(b,m) for( OBMolBondIter b(m); b; ++b ) 00368 #define FOR_NBORS_OF_ATOM(a,p) for( OBAtomAtomIter a(p); a; ++a ) 00369 #define FOR_BONDS_OF_ATOM(b,p) for( OBAtomBondIter b(p); b; ++b ) 00370 #define FOR_RESIDUES_OF_MOL(r,m) for( OBResidueIter r(m); r; ++r ) 00371 #define FOR_ATOMS_OF_RESIDUE(a,r) for( OBResidueAtomIter a(r); a; ++a ) 00372 #define FOR_DFS_OF_MOL(a,m) for( OBMolAtomDFSIter a(m); a; ++a ) 00373 #define FOR_BFS_OF_MOL(a,m) for( OBMolAtomBFSIter a(m); a; ++a ) 00374 #define FOR_RINGS_OF_MOL(a,m) for( OBMolRingIter r(m); r; ++r ) 00375 #define FOR_ANGLES_OF_MOL(a,m) for( OBMolAngleIter a(m); a; ++a ) 00376 #define FOR_TORSIONS_OF_MOL(t,m) for( OBMolTorsionIter t(m); t; ++t ) 00377 #define FOR_PAIRS_OF_MOL(p,m) for( OBMolPairIter p(m); p; ++p ) 00378 00379 } // namespace OpenBabel 00380 #endif // OB_OBITER_H 00381
This file is part of the documentation for Open Babel, version 2.2.0.