Files
rdkit/Code/GraphMol/BondIterators.cpp
Greg Landrum e05580e495 This is a sizeable one: change the way BGL is used so that atoms and bonds are stored as bundled properties
instead of using the property map interface.
A nice side-effect is that the wart of having to use property maps to loop over bonds or atom neighbors
is now gone.
This potentially breaks lots of client C++ code.
2009-02-11 20:19:25 +00:00

135 lines
3.3 KiB
C++
Executable File

// $Id$
//
// Copyright (C) 2002-2006 Greg Landrum and Rational Discovery LLC
//
// @@ All Rights Reserved @@
//
#include "BondIterators.h"
namespace RDKit{
BondIterator_::BondIterator_(ROMol *mol) {
_mol = mol;
boost::tie(_beg,_end)=mol->getEdges();
_pos = _beg;
};
BondIterator_::BondIterator_(ROMol *mol,ROMol::EDGE_ITER pos) {
_mol = mol;
boost::tie(_beg,_end)=mol->getEdges();
_pos = pos;
};
BondIterator_::BondIterator_(const BondIterator_ &other){
_mol = other._mol;
_pos = other._pos;
_beg = other._beg;
_end = other._end;
}
BondIterator_ &BondIterator_::operator=(const BondIterator_ &other){
_mol = other._mol;
_pos = other._pos;
_beg = other._beg;
_end = other._end;
return *this;
}
bool BondIterator_::operator==(const BondIterator_ &other){
return _mol==other._mol && _pos==other._pos;
}
bool BondIterator_::operator!=(const BondIterator_ &other){
return _mol!=other._mol || _pos!=other._pos;
}
Bond *BondIterator_::operator*() {
return (*_mol)[*_pos].get();
}
// pre-increment
BondIterator_ &BondIterator_::operator++() {
PRECONDITION(_pos!=_end,"bad initial position")
_pos++;
return *this;
}
BondIterator_ BondIterator_::operator++(int) {
PRECONDITION(_pos!=_end,"bad initial position")
BondIterator_ res(*this);
_pos++;
return res;
}
// pre-decrement
BondIterator_ &BondIterator_::operator--() {
if(_pos == _beg) _pos = _end;
else _pos--;
return *this;
}
BondIterator_ BondIterator_::operator--(int) {
BondIterator_ res(*this);
if(_pos == _beg) _pos = _end;
else _pos--;
return res;
}
// CONST
ConstBondIterator_::ConstBondIterator_(ROMol const *mol) {
_mol = mol;
boost::tie(_beg,_end)=mol->getEdges();
_pos = _beg;
};
ConstBondIterator_::ConstBondIterator_(ROMol const *mol,ROMol::EDGE_ITER pos) {
_mol = mol;
boost::tie(_beg,_end)=mol->getEdges();
_pos = pos;
};
ConstBondIterator_::ConstBondIterator_(const ConstBondIterator_ &other){
_mol = other._mol;
_pos = other._pos;
_beg = other._beg;
_end = other._end;
}
ConstBondIterator_ &ConstBondIterator_::operator=(const ConstBondIterator_ &other){
_mol = other._mol;
_pos = other._pos;
_beg = other._beg;
_end = other._end;
return *this;
}
bool ConstBondIterator_::operator==(const ConstBondIterator_ &other){
return _mol==other._mol && _pos==other._pos;
}
bool ConstBondIterator_::operator!=(const ConstBondIterator_ &other){
return _mol!=other._mol || _pos!=other._pos;
}
Bond const *ConstBondIterator_::operator*() {
return (*_mol)[*_pos].get();
}
// pre-increment
ConstBondIterator_ &ConstBondIterator_::operator++() {
PRECONDITION(_pos!=_end,"bad initial position")
_pos++;
return *this;
}
ConstBondIterator_ ConstBondIterator_::operator++(int) {
ConstBondIterator_ res(*this);
PRECONDITION(_pos!=_end,"bad initial position")
_pos++;
return res;
}
// pre-decrement
ConstBondIterator_ &ConstBondIterator_::operator--() {
if(_pos == _beg) _pos = _end;
else _pos--;
return *this;
}
ConstBondIterator_ ConstBondIterator_::operator--(int) {
ConstBondIterator_ res(*this);
if(_pos == _beg) _pos = _end;
else _pos--;
return res;
}
}