X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Flibmarklin%2Fblock.cpp;h=d4a6878a68b1b6ba475b85fd17014fe490b6cceb;hb=e179208d1c8370f87ce6ec87f649e5e99eb5724f;hp=c562788811a05ec07bc4997a8df6d6b49cf14a16;hpb=38fb8d56efde037a71c46a58bda314655e68ab6c;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index c562788..d4a6878 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -5,7 +5,6 @@ Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ -#include #include "control.h" #include "block.h" #include "tracktype.h" @@ -52,10 +51,10 @@ Block::Block(TrafficManager &tm, Track &start): for(unsigned i=0; i visited; - find_routes(*endpoints[i].track, endpoints[i].track_ep, route, visited); + find_paths(*endpoints[i].track, endpoints[i].track_ep, path, visited); } } @@ -68,7 +67,7 @@ int Block::get_endpoint_by_link(const Block &other) const return -1; } -int Block::traverse(unsigned epi, float *len) const +unsigned Block::traverse(unsigned epi, float *len) const { if(epi>=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); @@ -82,28 +81,25 @@ int Block::traverse(unsigned epi, float *len) const while(1) { - unsigned cur_route = 0; + unsigned cur_path = 0; unsigned tid = track->get_turnout_id(); if(tid) { Turnout &turnout = trfc_mgr.get_control().get_turnout(tid); - cur_route = turnout.get_route(); + cur_path = turnout.get_path(); } if(len) - *len += track->get_type().get_route_length(cur_route); - - int other_ep = track->traverse(track_ep, cur_route); - if(other_ep<0) - return -1; + *len += track->get_type().get_path_length(cur_path); + unsigned other_ep = track->traverse(track_ep, cur_path); for(unsigned i=0; i(other_ep)) return i; Track *next = track->get_link(other_ep); - if(tracks.count(next)==0) - return -1; + if(!tracks.count(next)) + throw LogicError("Block traversal strayed out of the block"); track_ep = next->get_endpoint_by_link(*track); track = next; } @@ -144,24 +140,7 @@ bool Block::reserve(const Train *t) return false; } -void Block::print_debug() -{ - cout<<"Block "<get_sensor_id()) - cout<<", sensor="<<(*tracks.begin())->get_sensor_id(); - cout<<'\n'; - for(vector::iterator i=endpoints.begin(); i!=endpoints.end(); ++i) - { - cout<<" Endpoint, link="; - if(i->link) - cout<link->id; - else - cout<<"none"; - cout<<", routes="<routes<<'\n'; - } -} - -void Block::find_routes(Track &track, unsigned track_ep, unsigned route, set &visited) +void Block::find_paths(Track &track, unsigned track_ep, unsigned path, set &visited) { visited.insert(&track); @@ -172,15 +151,15 @@ void Block::find_routes(Track &track, unsigned track_ep, unsigned route, setget_endpoint_by_link(track), route, visited); + find_paths(*link, link->get_endpoint_by_link(track), path, visited); else { for(vector::iterator j=endpoints.begin(); j!=endpoints.end(); ++j) if(j->track==&track && j->track_ep==i) - j->routes |= route; + j->paths |= path; } } } @@ -190,7 +169,7 @@ Block::Endpoint::Endpoint(Track *t, unsigned e): track(t), track_ep(e), link(0), - routes(0) + paths(0) { } } // namespace Marklin