]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/block.h
Allow intercepting and denying turnout route and locomotive speed changes
[r2c2.git] / source / libmarklin / block.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2009  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         unsigned       turnout_id;
38         std::set<Track *>     tracks;
39         std::vector<Endpoint> endpoints;
40         const Train    *train;
41
42 public:
43         Block(TrafficManager &, Track &);
44
45         unsigned get_sensor_id() const { return sensor_id; }
46         unsigned get_turnout_id() const { return turnout_id; }
47         const std::set<Track *> &get_tracks() const { return tracks; }
48         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
49         int get_endpoint_by_link(const Block &) const;
50         int traverse(unsigned, float * =0) const;
51         void check_link(Block &);
52         Block *get_link(unsigned) const;
53         bool reserve(const Train *);
54         const Train *get_train() const { return train; }
55         void print_debug();
56 private:
57         void find_routes(Track &, unsigned, unsigned, std::set<Track *> &);
58
59         static unsigned next_id;
60 };
61
62 } // namespace Marklin
63
64 #endif