]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/block.h
Major code refactoring:
[r2c2.git] / source / libmarklin / block.h
1 #ifndef MARKLIN_3D_BLOCK_H_
2 #define MARKLIN_3D_BLOCK_H_
3
4 #include <list>
5 #include <set>
6 #include "track.h"
7
8 namespace Marklin {
9
10 class Train;
11 class TrafficManager;
12
13 class Block
14 {
15 public:
16         struct Endpoint
17         {
18                 Track    *track;
19                 unsigned track_ep;
20                 Block    *link;
21                 unsigned routes;
22
23                 Endpoint(Track *, unsigned);
24         };
25
26 private:
27         TrafficManager &trfc_mgr;
28         unsigned       id;
29         unsigned       sensor_id;
30         std::set<Track *>     tracks;
31         std::vector<Endpoint> endpoints;
32         const Train    *train;
33
34 public:
35         Block(TrafficManager &, Track &);
36         unsigned get_sensor_id() const { return sensor_id; }
37         const std::set<Track *> &get_tracks() const { return tracks; }
38         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
39         int get_endpoint_by_link(const Block &) const;
40         int traverse(unsigned) const;
41         void check_link(Block &);
42         Block *get_link(unsigned) const;
43         bool reserve(const Train *);
44         void print_debug();
45 private:
46         void find_routes(Track &, unsigned, unsigned, std::set<Track *> &);
47
48         static unsigned next_id;
49 };
50 typedef std::list<Block *> BlockSeq;
51
52 } // namespace Marklin
53
54 #endif