X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibr2c2%2Fblockiter.cpp;h=9dcca6c68672a9392883ff4ccb4803358588a7f1;hb=d3d1850e950f3c38c8ef983228013fc82c287ec4;hp=db052ac5e059da47a50e6b3945e01817928596c2;hpb=1ff06c5bc46a677fa389ef86c6b26664368f1653;p=r2c2.git diff --git a/source/libr2c2/blockiter.cpp b/source/libr2c2/blockiter.cpp index db052ac..9dcca6c 100644 --- a/source/libr2c2/blockiter.cpp +++ b/source/libr2c2/blockiter.cpp @@ -1,11 +1,3 @@ -/* $Id$ - -This file is part of R²C² -Copyright © 2010 Mikkosoft Productions, Mikko Rasa -Distributed under the GPL -*/ - -#include #include "block.h" #include "blockiter.h" #include "route.h" @@ -26,7 +18,7 @@ BlockIter::BlockIter(Block *b, unsigned e): _entry(b ? e : 0) { if(_block && _entry>_block->get_endpoints().size()) - throw InvalidParameterValue("Endpoint index not valid for block"); + throw out_of_range("BlockIter::BlockIter"); } TrackIter BlockIter::track_iter() const @@ -34,14 +26,13 @@ TrackIter BlockIter::track_iter() const if(!_block) return TrackIter(); - const Block::Endpoint &ep = _block->get_endpoint(_entry); - return TrackIter(ep.track, ep.track_ep); + return _block->get_endpoint(_entry).track_iter(); } const Block::Endpoint &BlockIter::endpoint() const { if(!_block) - throw InvalidState("BlockIter is null"); + throw logic_error("null block"); return _block->get_endpoint(_entry); } @@ -49,24 +40,18 @@ const Block::Endpoint &BlockIter::endpoint() const int BlockIter::get_exit(const Route *route) const { const vector &eps = _block->get_endpoints(); - TrackIter t_iter = track_iter(); - - while(t_iter) + if(_block->get_turnout_address()) { - if(!_block->has_track(*t_iter)) - throw LogicError("Block traversal strayed out of the block"); - + /* The endpoints of a turnout block exactly correspond to the endpoints + of the track. */ + TrackIter t_iter = track_iter(); unsigned path = (route ? route->get_path(*t_iter) : t_iter->get_active_path()); - TrackIter t_exit = t_iter.reverse(path); - - for(unsigned i=0; i