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