From: Mikko Rasa Date: Wed, 27 Oct 2010 18:40:27 +0000 (+0000) Subject: Rewrite Block::find_paths using TrackIter X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=c400ed779704cc802de977090594c3441c3e7093;p=r2c2.git Rewrite Block::find_paths using TrackIter --- diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index 02b6da5..b9b65ad 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -56,8 +56,7 @@ Block::Block(Layout &l, Track &start): { unsigned path = 1< visited; - find_paths(*endpoints[i].track, endpoints[i].track_ep, path, visited); + find_paths(TrackIter(endpoints[i].track, endpoints[i].track_ep), path); } layout.add_block(*this); @@ -167,28 +166,25 @@ bool Block::reserve(Train *t) return false; } -void Block::find_paths(Track &track, unsigned track_ep, unsigned path, set &visited) +void Block::find_paths(TrackIter track, unsigned path) { - visited.insert(&track); - - const vector &eps = track.get_type().get_endpoints(); - for(unsigned i=0; iget_endpoint_by_link(track), path, visited); - else + unsigned mask = track->get_type().get_endpoints()[track.entry()].paths; + for(unsigned i=0; mask>>i; ++i) + if(mask&(1<::iterator j=endpoints.begin(); j!=endpoints.end(); ++j) - if(j->track==&track && j->track_ep==i) - j->paths |= path; + TrackIter next = track.next(i); + if(!next) + continue; + else if(has_track(*next)) + find_paths(track.next(i), path); + else + { + next = next.flip(); + for(vector::iterator j=endpoints.begin(); j!=endpoints.end(); ++j) + if(j->track==next.track() && j->track_ep==next.entry()) + j->paths |= path; + } } - } } void Block::determine_id() diff --git a/source/libmarklin/block.h b/source/libmarklin/block.h index cf5f3e7..2aed9a4 100644 --- a/source/libmarklin/block.h +++ b/source/libmarklin/block.h @@ -16,6 +16,7 @@ namespace Marklin { class Layout; class Route; +class TrackIter; class Train; class Block @@ -59,7 +60,7 @@ public: Train *get_train() const { return train; } void print_debug(); private: - void find_paths(Track &, unsigned, unsigned, std::set &); + void find_paths(TrackIter, unsigned); void determine_id(); };