X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrackiter.cpp;h=c3bb7d4ae5db5e8ab16def585547dfec090cb101;hb=8b7d4054b05002d82338775ac9b4ee764a8560e4;hp=c636d27c84cef8a30d6c700bb6fd454c9d49c9e0;hpb=621c5c938d70ba0d155e0eda91a708db0a52c0dc;p=r2c2.git diff --git a/source/libr2c2/trackiter.cpp b/source/libr2c2/trackiter.cpp index c636d27..c3bb7d4 100644 --- a/source/libr2c2/trackiter.cpp +++ b/source/libr2c2/trackiter.cpp @@ -1,4 +1,5 @@ #include +#include "blockiter.h" #include "track.h" #include "trackiter.h" #include "tracktype.h" @@ -21,6 +22,40 @@ TrackIter::TrackIter(Track *t, unsigned e): throw out_of_range("TrackIter::TrackIter"); } +BlockIter TrackIter::block_iter() const +{ + if(!_track) + return BlockIter(); + + Block &block = _track->get_block(); + const vector &beps = block.get_endpoints(); + + if(_track->get_type().is_turnout()) + { + /* A turnouts is the only track in its block. Go ahead and find the + matching endpoint in the block. */ + for(unsigned i=0; iget_block()==&block) + { + TrackIter fwd = rev.reverse(); + + for(unsigned i=0; iget_link(exit); - result._entry = (result._track ? result._track->get_endpoint_by_link(*_track) : 0); + result._entry = (result._track ? result._track->get_link_slot(*_track) : 0); return result; } @@ -92,7 +127,7 @@ TrackIter TrackIter::flip() const TrackIter result; result._track = _track->get_link(_entry); - result._entry = (result._track ? result._track->get_endpoint_by_link(*_track) : 0); + result._entry = (result._track ? result._track->get_link_slot(*_track) : 0); return result; }