]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/block.h
bdbcc3f3eb0ed2687a6d09e6e5d743782cef5ce9
[r2c2.git] / source / libmarklin / block.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef MARKLIN_3D_BLOCK_H_
9 #define MARKLIN_3D_BLOCK_H_
10
11 #include <list>
12 #include <set>
13 #include "track.h"
14
15 namespace Marklin {
16
17 class Train;
18 class TrafficManager;
19
20 class Block
21 {
22 public:
23         struct Endpoint
24         {
25                 Track    *track;
26                 unsigned track_ep;
27                 Block    *link;
28                 unsigned routes;
29
30                 Endpoint(Track *, unsigned);
31         };
32
33 private:
34         TrafficManager &trfc_mgr;
35         unsigned       id;
36         unsigned       sensor_id;
37         std::set<Track *>     tracks;
38         std::vector<Endpoint> endpoints;
39         const Train    *train;
40
41 public:
42         Block(TrafficManager &, Track &);
43
44         unsigned get_sensor_id() const { return sensor_id; }
45         const std::set<Track *> &get_tracks() const { return tracks; }
46         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
47         int get_endpoint_by_link(const Block &) const;
48         int traverse(unsigned, float * =0) const;
49         void check_link(Block &);
50         Block *get_link(unsigned) const;
51         bool reserve(const Train *);
52         const Train *get_train() const { return train; }
53         void print_debug();
54 private:
55         void find_routes(Track &, unsigned, unsigned, std::set<Track *> &);
56
57         static unsigned next_id;
58 };
59
60 } // namespace Marklin
61
62 #endif