X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Ftrackiter.cpp;h=c3bb7d4ae5db5e8ab16def585547dfec090cb101;hb=0b75458245997b9df6da47cc4534341c8426084b;hp=3c6295bb974437720b7677cf18bdbadab9136381;hpb=1ff06c5bc46a677fa389ef86c6b26664368f1653;p=r2c2.git diff --git a/source/libr2c2/trackiter.cpp b/source/libr2c2/trackiter.cpp index 3c6295b..c3bb7d4 100644 --- a/source/libr2c2/trackiter.cpp +++ b/source/libr2c2/trackiter.cpp @@ -1,12 +1,5 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - #include -#include +#include "blockiter.h" #include "track.h" #include "trackiter.h" #include "tracktype.h" @@ -26,13 +19,47 @@ TrackIter::TrackIter(Track *t, unsigned e): _entry(t ? e : 0) { if(_track && _entry>_track->get_type().get_endpoints().size()) - throw InvalidParameterValue("Endpoint index not valid for track"); + 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_type().get_endpoint(_entry); } @@ -43,7 +70,7 @@ int TrackIter::get_exit(unsigned path) const // Find an endpoint that's connected to the entry and has the requested path 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; } @@ -100,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; } @@ -108,7 +135,7 @@ TrackIter TrackIter::flip() const Track &TrackIter::operator*() const { if(!_track) - throw InvalidState("TrackIter is null"); + throw logic_error("null track"); return *_track; }