]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/route.cpp
Support more complex article numbers
[r2c2.git] / source / libmarklin / route.cpp
index 6dc7ae51e13350efe01269c06c199fde829675f8..daa044f9b9b4054b774421df3e6ada5168f76c43 100644 (file)
@@ -89,7 +89,7 @@ list<Track *> dijkstra(Track &from, unsigned ep, const Pred &goal)
                }
 
                const TrackType &type = lowest.track->get_type();
-               const vector<Endpoint> &eps = type.get_endpoints();
+               const vector<TrackType::Endpoint> &eps = type.get_endpoints();
                const vector<Track *> &links = lowest.track->get_links();
                for(unsigned i=0; i<eps.size(); ++i)
                {
@@ -110,9 +110,6 @@ list<Track *> dijkstra(Track &from, unsigned ep, const Pred &goal)
                }
        }
 
-       if(!final)
-               throw InvalidParameterValue("Could not find a route");
-
        list<Track *> result;
        for(Node *node=final; node; node=node->prev)
                result.push_front(node->track);
@@ -125,6 +122,9 @@ Route *create_route(Track &from, unsigned ep, const Pred &goal)
 {
        list<Track *> tracks = dijkstra(from, ep, goal);
 
+       if(tracks.empty())
+               return 0;
+
        Route *route = new Route(from.get_layout());
        for(list<Track *>::iterator i=tracks.begin(); i!=tracks.end(); ++i)
                route->add_track(**i);
@@ -184,7 +184,7 @@ void Route::update_turnouts()
                {
                        found.insert(tid);
 
-                       const vector<Endpoint> &endpoints = (*i)->get_type().get_endpoints();
+                       const vector<TrackType::Endpoint> &endpoints = (*i)->get_type().get_endpoints();
                        const vector<Track *> &links = (*i)->get_links();
 
                        // Build a combined path mask from linked endpoints
@@ -196,7 +196,7 @@ void Route::update_turnouts()
 
                                if(unsigned tid2 = links[j]->get_turnout_id())
                                {
-                                       const Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
+                                       const TrackType::Endpoint &ep = links[j]->get_type().get_endpoints()[links[j]->get_endpoint_by_link(**i)];
                                        int p = get_turnout(tid2);
                                        if(p>=0 && !(ep.paths&(1<<p)))
                                        {
@@ -333,7 +333,7 @@ unsigned Route::check_validity(Track &trk) const
                {
                        // Linked to an existing track - good
                        result |= 1;
-                       const vector<Endpoint> &endpoints = (*i)->get_type().get_endpoints();
+                       const vector<TrackType::Endpoint> &endpoints = (*i)->get_type().get_endpoints();
                        if(unsigned tid=(*i)->get_turnout_id())
                        {
                                int r = get_turnout(tid);
@@ -417,7 +417,7 @@ void Route::Loader::finish()
                        continue;
 
                unsigned path_mask = 1<<j->second;
-               const vector<Endpoint> &eps = (*i)->get_type().get_endpoints();
+               const vector<TrackType::Endpoint> &eps = (*i)->get_type().get_endpoints();
                for(unsigned k=0; k<eps.size(); ++k)
                        if(eps[k].paths&path_mask)
                        {