]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/tracktype.cpp
Major architecture rework
[r2c2.git] / source / libmarklin / tracktype.cpp
index 692b5625f1335c59fbc594ae11b1816520916b0d..5bbd40a411e07632e161dbb9d1a44a099dfeb41e 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of the MSP Märklin suite
-Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -18,14 +18,14 @@ TrackType::TrackType(unsigned a):
 
 float TrackType::get_total_length() const
 {
-       return get_route_length(-1);
+       return get_path_length(-1);
 }
 
-float TrackType::get_route_length(int r) const
+float TrackType::get_path_length(int p) const
 {
        float len = 0;
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
-               if(r<0 || i->route==static_cast<unsigned>(r))
+               if(p<0 || i->path==static_cast<unsigned>(p))
                {
                        float l = i->length;
                        if(i->radius)
@@ -35,15 +35,32 @@ float TrackType::get_route_length(int r) const
        return len;
 }
 
-unsigned TrackType::get_n_routes() const
+unsigned TrackType::get_paths() const
 {
-       unsigned n = 1;
+       unsigned mask = 0;
        for(vector<TrackPart>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
-               if(i->route>=n)
-                       n = i->route+1;
+               mask |= 1<<i->path;
+       return mask;
+}
+
+unsigned TrackType::get_n_paths() const
+{
+       unsigned n = 0;
+       for(unsigned mask = get_paths(); mask; ++n)
+               mask &= mask-1;
        return n;
 }
 
+bool TrackType::is_turnout() const
+{
+       return endpoints.size()>2;
+}
+
+bool TrackType::is_double_address() const
+{
+       return get_n_paths()>2;
+}
+
 void TrackType::collect_endpoints()
 {
        endpoints.clear();
@@ -67,7 +84,7 @@ void TrackType::collect_endpoints()
                                        da -= M_PI*2;
                                if(da<-3.1 || da>3.1)
                                        rm = true;
-                               i->routes |= j->routes;
+                               i->paths |= j->paths;
                                j = endpoints.erase(j);
                        }
                        else