]> git.tdb.fi Git - r2c2.git/commitdiff
Add Block::has_track and Route::has_track methods
authorMikko Rasa <tdb@tdb.fi>
Fri, 22 Oct 2010 21:22:41 +0000 (21:22 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 22 Oct 2010 21:22:41 +0000 (21:22 +0000)
source/designer/designer.cpp
source/engineer/trainpanel.cpp
source/libmarklin/block.cpp
source/libmarklin/block.h
source/libmarklin/layout.cpp
source/libmarklin/route.cpp
source/libmarklin/route.h
source/libmarklin/train.cpp

index e5608331023d038d9146ccb53d375555dbf2dc4f..5ea589bcc22c5c292fb76962a1621c50fbe18dcc 100644 (file)
@@ -609,7 +609,7 @@ void Designer::show_route(const Route *route)
        for(set<Track *>::iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
        {
                Track3D &t3d = layout_3d->get_track(**i);
-               if(route && route->get_tracks().count(*i))
+               if(route && route->has_track(**i))
                {
                        t3d.get_path().set_color(GL::Color(0.5, 0.8, 1.0));
                        if((*i)->get_type().is_turnout())
index 922e3741e272183abad52382f4255ce08c6fbfe3..c1fc1d9cac6c74109b2a8393a85b6f82411adb5e 100644 (file)
@@ -282,7 +282,7 @@ void TrainPanel::place(Track *track, unsigned ep)
                        Track *next = track->get_links()[ep];
                        ep = next->traverse(next->get_endpoint_by_link(*track), 0);
                        track = next;
-                       if(!block.get_tracks().count(track))
+                       if(!block.has_track(*track))
                                break;
                }
        }
index e5dbb6dbef68bfd9594e833981a8d0792de7db5e..780ee1bbd293e75a9e442f6a83a80c8a38a28f26 100644 (file)
@@ -72,6 +72,11 @@ Block::~Block()
        layout.remove_block(*this);
 }
 
+bool Block::has_track(Track &t) const
+{
+       return tracks.count(&t);
+}
+
 int Block::get_endpoint_by_link(Block &other) const
 {
        for(unsigned i=0; i<endpoints.size(); ++i)
index deaf4c48170f3286d296f88b1fff8e5b5428fa3a..23a48c0ffbc40344ee3c98a04c5e6833a3173613 100644 (file)
@@ -48,6 +48,7 @@ public:
        unsigned get_sensor_id() const { return sensor_id; }
        unsigned get_turnout_id() const { return turnout_id; }
        const std::set<Track *> &get_tracks() const { return tracks; }
+       bool has_track(Track &) const;
        const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
        int get_endpoint_by_link(Block &) const;
        unsigned traverse(unsigned, float * =0) const;
index f89b78335d30f0f720778ccbcd4b3822fc8defb8..f8ad397f183992507ea2eb0140d1d2ae20bccf2c 100644 (file)
@@ -98,7 +98,7 @@ Block &Layout::get_block(unsigned id) const
 Block &Layout::get_block_by_track(Track &t) const
 {
        for(set<Block *>::const_iterator i=blocks.begin(); i!=blocks.end(); ++i)
-               if((*i)->get_tracks().count(&t))
+               if((*i)->has_track(t))
                        return **i;
 
        throw InvalidParameterValue("No block found for track");
@@ -131,9 +131,9 @@ void Layout::create_blocks(Track &track)
        const vector<Track *> &links = track.get_links();
        for(set<Block *>::iterator i=blocks.begin(); i!=blocks.end();)
        {
-               bool del = (*i)->get_tracks().count(&track);
+               bool del = (*i)->has_track(track);
                for(vector<Track *>::const_iterator j=links.begin(); (!del && j!=links.end()); ++j)
-                       del = (*i)->get_tracks().count(*j);
+                       del = (*i)->has_track(**j);
 
                if(del)
                        delete *i++;
index 926dd28dd3a903ac468ea9f25f953c56b38f5b13..d4fcf800d9c30d71af8f7318e70a98b9f58bb7be 100644 (file)
@@ -316,6 +316,11 @@ void Route::add_track_chain(Track &start, unsigned ep, const TurnoutMap &trnts)
        }
 }
 
+bool Route::has_track(Track &t) const
+{
+       return tracks.count(&t);
+}
+
 void Route::save(list<DataFile::Statement> &st) const
 {
        st.push_back((DataFile::Statement("name"), name));
index 901383a50d8e7727807fac14b0ed2727eee8fb08..75241d8b604bea37c278e30f45e9894f2f867476 100644 (file)
@@ -61,6 +61,7 @@ public:
        void add_tracks(const std::set<Track *> &);
        void add_track_chain(Track &, unsigned, const TurnoutMap &);
        const std::set<Track *> &get_tracks() const { return tracks; }
+       bool has_track(Track &) const;
        void save(std::list<Msp::DataFile::Statement> &) const;
 private:
        unsigned check_validity(Track &) const;
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))