]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/signal.h
Add basic support for signals
[r2c2.git] / source / libr2c2 / signal.h
1 #ifndef LIBR2C2_SIGNAL_H_
2 #define LIBR2C2_SIGNAL_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include <msp/time/timedelta.h>
6 #include "geometry.h"
7
8 namespace R2C2 {
9
10 class Block;
11 class Layout;
12 class SignalType;
13 class Track;
14 class Train;
15
16 class Signal
17 {
18 public:
19         class Loader: public Msp::DataFile::ObjectLoader<Signal>
20         {
21         public:
22                 Loader(Signal &);
23
24         private:
25                 void address(unsigned);
26                 void direction(float);
27                 void position(float, float, float);
28         };
29
30 private:
31         Layout &layout;
32         const SignalType &type;
33         unsigned address;
34         Vector position;
35         float direction;
36         Track *track;
37         Block *block;
38         unsigned entry;
39         Train *train;
40         bool check_train_direction;
41         sigc::connection train_conn;
42         bool check_allocated_blocks;
43         bool passing;
44
45 public:
46         Signal(Layout &, const SignalType &);
47         ~Signal();
48
49         const SignalType &get_type() const { return type; }
50
51         void set_address(unsigned);
52         void set_position(const Vector &);
53         void set_direction(float);
54 private:
55         void normalize_location();
56 public:
57         const Vector &get_position() const { return position; }
58         float get_direction() const { return direction; }
59
60         void tick(const Msp::Time::TimeDelta &);
61
62 private:
63         void block_reserved(const Block &, Train *);
64         void train_advanced(Block &);
65         void reset();
66
67 public:
68         void save(std::list<Msp::DataFile::Statement> &) const;
69 };
70 } // namespace R2C2
71
72
73 #endif