]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/block.h
Add Block::has_track and Route::has_track methods
[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         bool has_track(Track &) const;
52         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
53         int get_endpoint_by_link(Block &) const;
54         unsigned traverse(unsigned, float * =0) const;
55         unsigned traverse(unsigned, const Route *, float * =0) const;
56         void check_link(Block &);
57         void break_link(Block &);
58         Block *get_link(unsigned) const;
59         bool reserve(Train *);
60         Train *get_train() const { return train; }
61         void print_debug();
62 private:
63         void find_paths(Track &, unsigned, unsigned, std::set<Track *> &);
64         void determine_id();
65 };
66
67 } // namespace Marklin
68
69 #endif