mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
add MatchingAtomIterator to C++
This commit is contained in:
@@ -398,6 +398,7 @@ namespace RDKit{
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
Atom_ * QueryAtomIterator_<Atom_,Mol_>::operator*() {
|
||||
PRECONDITION(_mol!=NULL,"no molecule");
|
||||
return (*_mol)[_pos].get();
|
||||
}
|
||||
// pre-increment
|
||||
@@ -426,6 +427,7 @@ namespace RDKit{
|
||||
}
|
||||
template <class Atom_, class Mol_>
|
||||
int QueryAtomIterator_<Atom_,Mol_>::_findNext(int from){
|
||||
PRECONDITION(_mol!=NULL,"no molecule");
|
||||
PRECONDITION(_qA!=NULL,"no query set");
|
||||
while(from<_end){
|
||||
if(_qA->Match((*_mol)[from])) break;
|
||||
@@ -436,6 +438,7 @@ namespace RDKit{
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
int QueryAtomIterator_<Atom_,Mol_>::_findPrev(int from){
|
||||
PRECONDITION(_mol!=NULL,"no molecule");
|
||||
PRECONDITION(_qA!=NULL,"no query set");
|
||||
while(from>0){
|
||||
if(_qA->Match((*_mol)[from])) break;
|
||||
@@ -446,6 +449,112 @@ namespace RDKit{
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------
|
||||
//
|
||||
// MatchingAtomIterator
|
||||
//
|
||||
//-----------------------------------------
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_>::MatchingAtomIterator_(Mol_ * mol,bool (*fn)(Atom_ *)){
|
||||
PRECONDITION(fn,"bad query function");
|
||||
_mol = mol;
|
||||
_qF = fn;
|
||||
_end = mol->getNumAtoms();
|
||||
_pos = _findNext(0);
|
||||
};
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_>::MatchingAtomIterator_(Mol_ * mol,int pos){
|
||||
_mol = mol;
|
||||
_qF = NULL;
|
||||
_end = mol->getNumAtoms();
|
||||
_pos = pos;
|
||||
};
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_>::~MatchingAtomIterator_() {}
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_>::MatchingAtomIterator_(const MatchingAtomIterator_<Atom_,Mol_> &other){
|
||||
_mol = other._mol;
|
||||
_pos = other._pos;
|
||||
_end = other._end;
|
||||
_qF = other._qF;
|
||||
}
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_> &
|
||||
MatchingAtomIterator_<Atom_,Mol_>::operator =(const MatchingAtomIterator_<Atom_,Mol_> &other){
|
||||
if(this!=&other){
|
||||
_mol = other._mol;
|
||||
_pos = other._pos;
|
||||
_end = other._end;
|
||||
_qF = other._qF;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
template <class Atom_, class Mol_>
|
||||
bool MatchingAtomIterator_<Atom_,Mol_>::operator==(const MatchingAtomIterator_<Atom_,Mol_> &other){
|
||||
return _mol==other._mol && _pos==other._pos;
|
||||
}
|
||||
template <class Atom_, class Mol_>
|
||||
bool MatchingAtomIterator_<Atom_,Mol_>::operator!=(const MatchingAtomIterator_<Atom_,Mol_> &other){
|
||||
return _mol!=other._mol || _pos!=other._pos;
|
||||
}
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
Atom_ * MatchingAtomIterator_<Atom_,Mol_>::operator*() {
|
||||
PRECONDITION(_mol!=NULL,"no molecule");
|
||||
return (*_mol)[_pos].get();
|
||||
}
|
||||
// pre-increment
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_> &MatchingAtomIterator_<Atom_,Mol_>::operator++() {
|
||||
_pos = _findNext(_pos+1);
|
||||
return *this;
|
||||
}
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_> MatchingAtomIterator_<Atom_,Mol_>::operator++(int) {
|
||||
MatchingAtomIterator_ res(*this);
|
||||
_pos = _findNext(_pos+1);
|
||||
return res;
|
||||
}
|
||||
// pre-decrement
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_> &MatchingAtomIterator_<Atom_,Mol_>::operator--() {
|
||||
_pos = _findPrev(_pos-1);
|
||||
return *this;
|
||||
}
|
||||
template <class Atom_, class Mol_>
|
||||
MatchingAtomIterator_<Atom_,Mol_> MatchingAtomIterator_<Atom_,Mol_>::operator--(int) {
|
||||
MatchingAtomIterator_<Atom_,Mol_> res(*this);
|
||||
_pos = _findPrev(_pos-1);
|
||||
return res;
|
||||
}
|
||||
template <class Atom_, class Mol_>
|
||||
int MatchingAtomIterator_<Atom_,Mol_>::_findNext(int from){
|
||||
PRECONDITION(_mol!=NULL,"no molecule");
|
||||
PRECONDITION(_qF!=NULL,"no query set");
|
||||
while(from<_end){
|
||||
if(_qF((*_mol)[from].get())) break;
|
||||
else ++from;
|
||||
}
|
||||
return from;
|
||||
}
|
||||
|
||||
template <class Atom_, class Mol_>
|
||||
int MatchingAtomIterator_<Atom_,Mol_>::_findPrev(int from){
|
||||
PRECONDITION(_mol!=NULL,"no molecule");
|
||||
PRECONDITION(_qF!=NULL,"no query set");
|
||||
while(from>0){
|
||||
if(_qF((*_mol)[from].get())) break;
|
||||
else --from;
|
||||
}
|
||||
if(from<0) from = _end;
|
||||
return from;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template class AtomIterator_<Atom,ROMol>;
|
||||
template class AtomIterator_<const Atom,const ROMol>;
|
||||
|
||||
@@ -455,6 +564,8 @@ namespace RDKit{
|
||||
template class HeteroatomIterator_<const Atom,const ROMol>;
|
||||
template class QueryAtomIterator_<Atom,ROMol>;
|
||||
template class QueryAtomIterator_<const Atom,const ROMol>;
|
||||
template class MatchingAtomIterator_<Atom,ROMol>;
|
||||
template class MatchingAtomIterator_<const Atom,const ROMol>;
|
||||
|
||||
|
||||
}; // end o' namespace
|
||||
|
||||
Reference in New Issue
Block a user