[d2dbac0] | 1 | /*
|
---|
| 2 | * WorldIterators.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Feb 25, 2010
|
---|
| 5 | * Author: crueger
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 9 | #include "Descriptors/AtomDescriptor_impl.hpp"
|
---|
[1c51c8] | 10 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 11 | #include "Descriptors/MoleculeDescriptor_impl.hpp"
|
---|
[d2dbac0] | 12 | #include "atom.hpp"
|
---|
[1c51c8] | 13 | #include "molecule.hpp"
|
---|
[d2dbac0] | 14 | #include "World.hpp"
|
---|
| 15 |
|
---|
[1c51c8] | 16 | /********************** Atoms *************************/
|
---|
| 17 |
|
---|
[d2dbac0] | 18 | World::AtomIterator::AtomIterator(){
|
---|
| 19 | state = World::get()->atomEnd();
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | World::AtomIterator::AtomIterator(AtomDescriptor _descr, World* _world) :
|
---|
| 23 | descr(_descr.get_impl()),
|
---|
[24a5e0] | 24 | index(0),
|
---|
| 25 | world(_world)
|
---|
[d2dbac0] | 26 | {
|
---|
| 27 | state = world->atoms.begin();
|
---|
| 28 | advanceState();
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | World::AtomIterator::AtomIterator(const AtomIterator& rhs) :
|
---|
| 32 | state(rhs.state),
|
---|
| 33 | descr(rhs.descr),
|
---|
| 34 | index(rhs.index),
|
---|
| 35 | world(rhs.world)
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
| 38 | World::AtomIterator& World::AtomIterator::operator=(const AtomIterator& rhs)
|
---|
| 39 | {
|
---|
| 40 | if(&rhs!=this){
|
---|
| 41 | state=rhs.state;
|
---|
| 42 | descr=rhs.descr;
|
---|
| 43 | index=rhs.index;
|
---|
| 44 | world=rhs.world;
|
---|
| 45 | }
|
---|
| 46 | return *this;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | World::AtomIterator& World::AtomIterator::operator++(){
|
---|
| 50 | ++state;
|
---|
| 51 | ++index;
|
---|
| 52 | advanceState();
|
---|
| 53 | return *this;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | World::AtomIterator World::AtomIterator::operator++(int){
|
---|
| 57 | AtomIterator res(*this);
|
---|
| 58 | ++(*this);
|
---|
| 59 | return res;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | bool World::AtomIterator::operator==(const AtomIterator& rhs){
|
---|
| 63 | return state==rhs.state;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | bool World::AtomIterator::operator==(const World::AtomSet::iterator& rhs){
|
---|
| 67 | return state==rhs;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | bool World::AtomIterator::operator!=(const AtomIterator& rhs){
|
---|
| 71 | return state!=rhs.state;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | bool World::AtomIterator::operator!=(const World::AtomSet::iterator& rhs){
|
---|
| 75 | return state!=rhs;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | atom* World::AtomIterator::operator*(){
|
---|
| 79 | return (*state).second;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | void World::AtomIterator::advanceState(){
|
---|
[1c51c8] | 83 | // go forward until we have a matching atom or the end is reached
|
---|
[d2dbac0] | 84 | while((state!=world->atoms.end()) && (!descr->predicate(*state))){
|
---|
| 85 | ++state;
|
---|
| 86 | ++index;
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | int World::AtomIterator::getCount(){
|
---|
| 91 | return index;
|
---|
| 92 | }
|
---|
[1c51c8] | 93 |
|
---|
| 94 | /*********************************** Molecules ************************/
|
---|
| 95 |
|
---|
| 96 | World::MoleculeIterator::MoleculeIterator(){
|
---|
| 97 | state = World::get()->moleculeEnd();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | World::MoleculeIterator::MoleculeIterator(MoleculeDescriptor _descr, World* _world) :
|
---|
| 101 | descr(_descr.get_impl()),
|
---|
| 102 | index(0),
|
---|
| 103 | world(_world)
|
---|
| 104 | {
|
---|
| 105 | state = world->molecules.begin();
|
---|
| 106 | advanceState();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | World::MoleculeIterator::MoleculeIterator(const MoleculeIterator& rhs) :
|
---|
| 110 | state(rhs.state),
|
---|
| 111 | descr(rhs.descr),
|
---|
| 112 | index(rhs.index),
|
---|
| 113 | world(rhs.world)
|
---|
| 114 | {}
|
---|
| 115 |
|
---|
| 116 | World::MoleculeIterator& World::MoleculeIterator::operator=(const MoleculeIterator& rhs)
|
---|
| 117 | {
|
---|
| 118 | if(&rhs!=this){
|
---|
| 119 | state=rhs.state;
|
---|
| 120 | descr=rhs.descr;
|
---|
| 121 | index=rhs.index;
|
---|
| 122 | world=rhs.world;
|
---|
| 123 | }
|
---|
| 124 | return *this;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | World::MoleculeIterator& World::MoleculeIterator::operator++(){
|
---|
| 128 | ++state;
|
---|
| 129 | ++index;
|
---|
| 130 | advanceState();
|
---|
| 131 | return *this;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | World::MoleculeIterator World::MoleculeIterator::operator++(int){
|
---|
| 135 | MoleculeIterator res(*this);
|
---|
| 136 | ++(*this);
|
---|
| 137 | return res;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | bool World::MoleculeIterator::operator==(const MoleculeIterator& rhs){
|
---|
| 141 | return state==rhs.state;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | bool World::MoleculeIterator::operator==(const World::MoleculeSet::iterator& rhs){
|
---|
| 145 | return state==rhs;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | bool World::MoleculeIterator::operator!=(const MoleculeIterator& rhs){
|
---|
| 149 | return state!=rhs.state;
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | bool World::MoleculeIterator::operator!=(const World::MoleculeSet::iterator& rhs){
|
---|
| 153 | return state!=rhs;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | molecule* World::MoleculeIterator::operator*(){
|
---|
| 157 | return (*state).second;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | void World::MoleculeIterator::advanceState(){
|
---|
| 161 | while((state!=world->molecules.end()) && (!descr->predicate(*state))){
|
---|
| 162 | ++state;
|
---|
| 163 | ++index;
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | int World::MoleculeIterator::getCount(){
|
---|
| 168 | return index;
|
---|
| 169 | }
|
---|
| 170 |
|
---|