From: Mikko Rasa Date: Sat, 26 Jan 2013 20:35:15 +0000 (+0200) Subject: Add a function to get a BlockIter from a TrackIter X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=32316772d422223827833366a7ee2d0a76d76ff1;p=r2c2.git Add a function to get a BlockIter from a TrackIter --- diff --git a/source/libr2c2/blockiter.h b/source/libr2c2/blockiter.h index 1e8a383..362c918 100644 --- a/source/libr2c2/blockiter.h +++ b/source/libr2c2/blockiter.h @@ -1,9 +1,10 @@ #ifndef LIBR2C2_BLOCKITER_H_ #define LIBR2C2_BLOCKITER_H_ +#include "block.h" + namespace R2C2 { -class Block; class Route; class TrackIter; diff --git a/source/libr2c2/trackiter.cpp b/source/libr2c2/trackiter.cpp index c636d27..64d223e 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; i