#include <algorithm>
+#include "blockiter.h"
#include "track.h"
#include "trackiter.h"
#include "tracktype.h"
throw out_of_range("TrackIter::TrackIter");
}
+BlockIter TrackIter::block_iter() const
+{
+ if(!_track)
+ return BlockIter();
+
+ Block &block = _track->get_block();
+ const vector<Block::Endpoint> &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; i<beps.size(); ++i)
+ if(beps[i].track==_track && beps[i].track_ep==_entry)
+ return BlockIter(&block, i);
+ }
+ else
+ {
+ TrackIter rev = reverse();
+ while(rev && &rev.track()->get_block()==&block)
+ {
+ TrackIter fwd = rev.reverse();
+
+ for(unsigned i=0; i<beps.size(); ++i)
+ if(beps[i].track==fwd.track() && beps[i].track_ep==fwd.entry())
+ return BlockIter(&block, i);
+
+ rev = rev.next();
+ }
+ }
+
+ throw logic_error("internal error (didn't find block entry endpoint)");
+}
+
const TrackType::Endpoint &TrackIter::endpoint() const
{
if(!_track)
namespace R2C2 {
+class BlockIter;
class Track;
/**
Track *track() const { return _track; }
unsigned entry() const { return _entry; }
+ BlockIter block_iter() const;
const TrackType::Endpoint &endpoint() const;
private: