namespace Marklin {
+unsigned Block::next_id = 1;
+
Block::Block(TrafficManager &tm, Track &start):
trfc_mgr(tm),
id(next_id++),
while(!queue.empty())
{
- Track *track=queue.front();
+ Track *track = queue.front();
queue.erase(queue.begin());
- const vector<Track *> &links=track->get_links();
+ const vector<Track *> &links = track->get_links();
for(unsigned i=0; i<links.size(); ++i)
if(links[i] && !tracks.count(links[i]))
{
for(unsigned i=0; i<endpoints.size(); ++i)
{
- unsigned route=1<<i;
- endpoints[i].routes|=route;
+ unsigned route = 1<<i;
+ endpoints[i].routes |= route;
set<Track *> visited;
find_routes(*endpoints[i].track, endpoints[i].track_ep, route, visited);
}
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;
if(endpoints[i].track==track && endpoints[i].track_ep==static_cast<unsigned>(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;
}
}
for(vector<Endpoint>::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;
}
}
}
{
if(!t || !train)
{
- train=t;
+ train = t;
trfc_mgr.signal_block_reserved.emit(*this, train);
return true;
}
{
visited.insert(&track);
- const vector<Marklin::Endpoint> &eps=track.get_type().get_endpoints();
+ const vector<Marklin::Endpoint> &eps = track.get_type().get_endpoints();
for(unsigned i=0; i<eps.size(); ++i)
{
if(i==track_ep) continue;
- Track *link=track.get_link(i);
+ Track *link = track.get_link(i);
if(!link) continue;
if(visited.count(link)) continue;
if(!(eps[i].routes&eps[track_ep].routes)) continue;
{
for(vector<Endpoint>::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),