]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/train.cpp
Add Block::has_track and Route::has_track methods
[r2c2.git] / source / libmarklin / train.cpp
index 6b6b89ed8d2d4af8485a2cc1f704762b007518ca..5bc50d85ff23ee5011535e34e5e6142f6b08fccc 100644 (file)
@@ -219,13 +219,13 @@ void Train::set_route(const Route *r)
                BlockRef next = last.next();
                const Block::Endpoint &first_ep = first.block->get_endpoints()[first.entry];
                const Block::Endpoint &next_ep = next.block->get_endpoints()[next.entry];
-               if(!r->get_tracks().count(next_ep.track))
+               if(!r->has_track(*next_ep.track))
                {
                        Route *lead = Route::find(*next_ep.track, next_ep.track_ep, *r);
                        create_lead_route(lead, lead);
                        routes.push_front(lead);
                }
-               else if(!r->get_tracks().count(first_ep.track))
+               else if(!r->has_track(*first_ep.track))
                        routes.push_front(create_lead_route(0, r));
        }
 
@@ -237,7 +237,7 @@ void Train::set_route(const Route *r)
 void Train::go_to(Track &to)
 {
        for(list<BlockRef>::const_iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
-               if(i->block->get_tracks().count(&to))
+               if(i->block->has_track(to))
                {
                        signal_arrived.emit();
                        set_route(0);
@@ -348,12 +348,12 @@ bool Train::divert(Track &from)
                Track *next = track->get_link(track->traverse(ep, path));
 
                for(list<RouteRef>::iterator i=route; (end==routes.end() && i!=routes.end()); ++i)
-                       if(i->route->get_tracks().count(next))
+                       if(i->route->has_track(*next))
                                end = i;
 
                if(end!=routes.end())
                        break;
-               else if(!diversion->get_tracks().count(next))
+               else if(!diversion->has_track(*next))
                        throw Exception("Pathfinder returned a bad route");
 
                ep = next->get_endpoint_by_link(*track);
@@ -472,7 +472,7 @@ void Train::free_noncritical_blocks()
        Track *track = veh.get_track();
        list<BlockRef>::iterator block = cur_blocks.begin();
        bool in_rsv = false;
-       while(block!=rsv_blocks.end() && !block->block->get_tracks().count(track))
+       while(block!=rsv_blocks.end() && !block->block->has_track(*track))
        {
                ++block;
                if(block==cur_blocks.end())
@@ -497,7 +497,7 @@ void Train::free_noncritical_blocks()
                entry = next->get_endpoint_by_link(*track);
                track = next;
 
-               if(!block->block->get_tracks().count(track))
+               if(!block->block->has_track(*track))
                {
                        ++block;
                        if(block==cur_blocks.end())
@@ -588,7 +588,7 @@ void Train::tick(const Time::TimeStamp &t, const Time::TimeDelta &dt)
 
                bool ok = false;
                for(list<BlockRef>::const_iterator i=cur_blocks.begin(); (!ok && i!=cur_blocks.end()); ++i)
-                       ok = i->block->get_tracks().count(track);
+                       ok = i->block->has_track(*track);
 
                float d = get_real_speed(current_speed)*(dt/Time::sec);
                if(ok)
@@ -793,7 +793,7 @@ void Train::sensor_event(unsigned addr, bool state)
                list<BlockRef>::iterator end = cur_blocks.begin();
                for(list<BlockRef>::iterator i=cur_blocks.begin(); i!=cur_blocks.end(); ++i)
                {
-                       if(i->block->get_tracks().count(veh.get_track()))
+                       if(i->block->has_track(*veh.get_track()))
                                break;
                        if(i->block->get_sensor_id())
                        {
@@ -925,7 +925,7 @@ unsigned Train::reserve_more()
                                break;
                        }
                }
-               else if(!routes.empty() && routes.front().route->get_tracks().count(entry_ep.track))
+               else if(!routes.empty() && routes.front().route->has_track(*entry_ep.track))
                        cur_route = routes.begin();
 
                if(link->get_endpoints().size()<2)
@@ -1117,7 +1117,7 @@ float Train::get_reserved_distance_until(const Block *until_block, bool back) co
                return 0;
 
        list<BlockRef>::const_iterator block = cur_blocks.begin();
-       while(block!=rsv_blocks.end() && !block->block->get_tracks().count(track))
+       while(block!=rsv_blocks.end() && !block->block->has_track(*track))
        {
                ++block;
                if(block==cur_blocks.end())
@@ -1146,7 +1146,7 @@ float Train::get_reserved_distance_until(const Block *until_block, bool back) co
 
                Track *next = track->get_link(track->traverse(entry));
 
-               if(!block->block->get_tracks().count(next))
+               if(!block->block->has_track(*next))
                {
                        if(back)
                        {
@@ -1276,14 +1276,14 @@ void Train::reverse_blocks(list<BlockRef> &blocks) const
 
 bool Train::advance_route(list<RouteRef>::iterator &iter, Track &track)
 {
-       while(iter!=routes.end() && !iter->route->get_tracks().count(&track))
+       while(iter!=routes.end() && !iter->route->has_track(track))
                ++iter;
        if(iter==routes.end())
                return false;
 
        list<RouteRef>::iterator next = iter;
        ++next;
-       if(next!=routes.end() && next->diversion && next->route->get_tracks().count(&track))
+       if(next!=routes.end() && next->diversion && next->route->has_track(track))
                iter = next;
 
        return true;
@@ -1303,7 +1303,7 @@ Route *Train::create_lead_route(Route *lead, const Route *target)
        {
                const set<Track *> &btracks = i->block->get_tracks();
                for(set<Track *>::const_iterator j=btracks.begin(); j!=btracks.end(); ++j)
-                       if(!target || !target->get_tracks().count(*j))
+                       if(!target || !target->has_track(**j))
                                tracks.insert(*j);
 
                if(++i==cur_blocks.end())
@@ -1320,7 +1320,7 @@ bool Train::is_valid_diversion(const Route &diversion, Track &from, unsigned fro
        float diversion_len = 0;
        Track *track = &from;
        unsigned ep = from_ep;
-       while(diversion.get_tracks().count(track))
+       while(diversion.has_track(*track))
        {
                unsigned path = 0;
                if(track->get_turnout_id())
@@ -1350,7 +1350,7 @@ bool Train::is_valid_diversion(const Route &diversion, Track &from, unsigned fro
                        path = route->route->get_turnout(track->get_turnout_id());
                route_len += track->get_type().get_path_length(path);
 
-               if(track!=&from && diversion.get_tracks().count(track))
+               if(track!=&from && diversion.has_track(*track))
                        break;
 
                if(visited.count(track))