]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/block.h
Major architecture rework
[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 Train;
19
20 class Block
21 {
22 public:
23         struct Endpoint
24         {
25                 Track *track;
26                 unsigned track_ep;
27                 Block *link;
28                 unsigned paths;
29
30                 Endpoint(Track *, unsigned);
31         };
32
33 private:
34         Layout &layout;
35         unsigned id;
36         unsigned sensor_id;
37         unsigned turnout_id;
38         std::set<Track *> tracks;
39         std::vector<Endpoint> endpoints;
40         Train *train;
41
42 public:
43         Block(Layout &, Track &);
44         ~Block();
45
46         unsigned get_id() const { return id; }
47         unsigned get_sensor_id() const { return sensor_id; }
48         unsigned get_turnout_id() const { return turnout_id; }
49         const std::set<Track *> &get_tracks() const { return tracks; }
50         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
51         int get_endpoint_by_link(const Block &) const;
52         unsigned traverse(unsigned, float * =0) const;
53         void check_link(Block &);
54         void break_link(Block &);
55         Block *get_link(unsigned) const;
56         bool reserve(Train *);
57         Train *get_train() const { return train; }
58         void print_debug();
59 private:
60         void find_paths(Track &, unsigned, unsigned, std::set<Track *> &);
61         void determine_id();
62 };
63
64 } // namespace Marklin
65
66 #endif