X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Flibmarklin%2Fblock.cpp;h=c562788811a05ec07bc4997a8df6d6b49cf14a16;hb=38fb8d56efde037a71c46a58bda314655e68ab6c;hp=ee0a48cb950498474e0fe7d2b8bc602a5ac77987;hpb=449fb5de95ddb2ac9da4bd72a1c12150505d5549;p=r2c2.git diff --git a/source/libmarklin/block.cpp b/source/libmarklin/block.cpp index ee0a48c..c562788 100644 --- a/source/libmarklin/block.cpp +++ b/source/libmarklin/block.cpp @@ -17,6 +17,8 @@ using namespace Msp; namespace Marklin { +unsigned Block::next_id = 1; + Block::Block(TrafficManager &tm, Track &start): trfc_mgr(tm), id(next_id++), @@ -31,10 +33,10 @@ Block::Block(TrafficManager &tm, Track &start): while(!queue.empty()) { - Track *track=queue.front(); + Track *track = queue.front(); queue.erase(queue.begin()); - const vector &links=track->get_links(); + const vector &links = track->get_links(); for(unsigned i=0; i visited; find_routes(*endpoints[i].track, endpoints[i].track_ep, route, visited); } @@ -71,27 +73,27 @@ int Block::traverse(unsigned epi, float *len) const if(epi>=endpoints.size()) throw InvalidParameterValue("Endpoint index out of range"); - const Endpoint &ep=endpoints[epi]; - Track *track=ep.track; - unsigned track_ep=ep.track_ep; + const Endpoint &ep = endpoints[epi]; + Track *track = ep.track; + unsigned track_ep = ep.track_ep; if(len) - *len=0; + *len = 0; while(1) { - unsigned cur_route=0; - unsigned tid=track->get_turnout_id(); + unsigned cur_route = 0; + unsigned tid = track->get_turnout_id(); if(tid) { - Turnout &turnout=trfc_mgr.get_control().get_turnout(tid); - cur_route=turnout.get_route(); + Turnout &turnout = trfc_mgr.get_control().get_turnout(tid); + cur_route = turnout.get_route(); } if(len) - *len+=track->get_type().get_route_length(cur_route); + *len += track->get_type().get_route_length(cur_route); - int other_ep=track->traverse(track_ep, cur_route); + int other_ep = track->traverse(track_ep, cur_route); if(other_ep<0) return -1; @@ -99,11 +101,11 @@ int Block::traverse(unsigned epi, float *len) const if(endpoints[i].track==track && endpoints[i].track_ep==static_cast(other_ep)) return i; - Track *next=track->get_link(other_ep); + Track *next = track->get_link(other_ep); if(tracks.count(next)==0) return -1; - track_ep=next->get_endpoint_by_link(*track); - track=next; + track_ep = next->get_endpoint_by_link(*track); + track = next; } } @@ -117,8 +119,8 @@ void Block::check_link(Block &other) for(vector::iterator j=other.endpoints.begin(); j!=other.endpoints.end(); ++j) if(j->track==i->track->get_link(i->track_ep) && j->track->get_link(j->track_ep)==i->track && !j->link) { - i->link=&other; - j->link=this; + i->link = &other; + j->link = this; } } } @@ -134,7 +136,7 @@ bool Block::reserve(const Train *t) { if(!t || !train) { - train=t; + train = t; trfc_mgr.signal_block_reserved.emit(*this, train); return true; } @@ -163,11 +165,11 @@ void Block::find_routes(Track &track, unsigned track_ep, unsigned route, set &eps=track.get_type().get_endpoints(); + const vector &eps = track.get_type().get_endpoints(); for(unsigned i=0; i::iterator j=endpoints.begin(); j!=endpoints.end(); ++j) if(j->track==&track && j->track_ep==i) - j->routes|=route; + j->routes |= route; } } } -unsigned Block::next_id=1; - Block::Endpoint::Endpoint(Track *t, unsigned e): track(t),