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