]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/block.h
Add Block::has_track and Route::has_track methods
[r2c2.git] / source / libmarklin / block.h
index f18ba8d6f49d52a53844045078aa17f5dd766a96..23a48c0ffbc40344ee3c98a04c5e6833a3173613 100644 (file)
@@ -1,5 +1,12 @@
-#ifndef MARKLIN_3D_BLOCK_H_
-#define MARKLIN_3D_BLOCK_H_
+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef LIBMARKLIN_BLOCK_H_
+#define LIBMARKLIN_BLOCK_H_
 
 #include <list>
 #include <set>
 
 namespace Marklin {
 
+class Layout;
+class Route;
 class Train;
-class TrafficManager;
 
 class Block
 {
 public:
        struct Endpoint
        {
-               Track    *track;
+               Track *track;
                unsigned track_ep;
-               Block    *link;
-               unsigned routes;
+               Block *link;
+               unsigned paths;
 
                Endpoint(Track *, unsigned);
        };
 
 private:
-       TrafficManager &trfc_mgr;
-       unsigned       id;
-       unsigned       sensor_id;
-       std::set<Track *>     tracks;
+       Layout &layout;
+       unsigned id;
+       unsigned sensor_id;
+       unsigned turnout_id;
+       std::set<Track *> tracks;
        std::vector<Endpoint> endpoints;
-       const Train    *train;
+       Train *train;
 
 public:
-       Block(TrafficManager &, Track &);
+       Block(Layout &, Track &);
+       ~Block();
+
+       unsigned get_id() const { return id; }
        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(const Block &) const;
-       int traverse(unsigned) const;
+       int get_endpoint_by_link(Block &) const;
+       unsigned traverse(unsigned, float * =0) const;
+       unsigned traverse(unsigned, const Route *, float * =0) const;
        void check_link(Block &);
+       void break_link(Block &);
        Block *get_link(unsigned) const;
-       bool reserve(const Train *);
+       bool reserve(Train *);
+       Train *get_train() const { return train; }
        void print_debug();
 private:
-       void find_routes(Track &, unsigned, unsigned, std::set<Track *> &);
-
-       static unsigned next_id;
+       void find_paths(Track &, unsigned, unsigned, std::set<Track *> &);
+       void determine_id();
 };
-typedef std::list<Block *> BlockSeq;
 
 } // namespace Marklin