]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/block.h
Store routing information in TrainRoutePlanner to avoid threading problems
[r2c2.git] / source / libr2c2 / block.h
1 #ifndef LIBR2C2_BLOCK_H_
2 #define LIBR2C2_BLOCK_H_
3
4 #include <list>
5 #include <set>
6 #include "track.h"
7 #include "trackchain.h"
8
9 namespace R2C2 {
10
11 class Layout;
12 class Route;
13 class TrackCircuit;
14 class TrackIter;
15 class Train;
16
17 class Block: public TrackChain
18 {
19 public:
20         struct Endpoint
21         {
22                 Track *track;
23                 unsigned track_ep;
24                 Block *link;
25
26                 Endpoint(Track *, unsigned);
27
28                 TrackIter track_iter() const;
29         };
30
31         sigc::signal<void, Train *> signal_reserved;
32
33 private:
34         unsigned id;
35         unsigned sensor_addr;
36         unsigned turnout_addr;
37         bool conflict;
38         TrackCircuit *sensor;
39         std::vector<Endpoint> endpoints;
40         Train *train;
41
42 public:
43         Block(Layout &, Track &);
44         ~Block();
45
46         virtual void set_name(const std::string &);
47
48 private:
49         virtual void on_track_added(Track &);
50         virtual Validity check_validity(Track &) const;
51
52 public:
53         unsigned get_id() const { return id; }
54         unsigned get_sensor_address() const { return sensor_addr; }
55         unsigned get_turnout_address() const { return turnout_addr; }
56         TrackCircuit *get_sensor() const { return sensor; }
57         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
58         const Endpoint &get_endpoint(unsigned) const;
59         int get_endpoint_by_link(Block &) const;
60         float get_path_length(unsigned, const Route * = 0) const;
61         void check_link(Block &);
62         void break_link(Block &);
63         Block *get_link(unsigned) const;
64         bool reserve(Train *);
65         Train *get_train() const { return train; }
66 private:
67         void determine_id();
68
69 public:
70         virtual Msp::DataFile::Statement save_reference() const;
71 };
72
73 } // namespace R2C2
74
75 #endif