]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/train.h
Rename Section to Block for a closer match with real railway terminology
[r2c2.git] / source / libmarklin / train.h
1 #ifndef LIBMARKLIN_TRAIN_H_
2 #define LIBMARKLIN_TRAIN_H_
3
4 #include <sigc++/trackable.h>
5 #include "block.h"
6
7 namespace Marklin {
8
9 class Locomotive;
10 class TrafficManager;
11
12 class Train: public sigc::trackable
13 {
14 public:
15         Train(TrafficManager &, Locomotive &);
16         const std::string &get_name() const { return name; }
17         void set_speed(unsigned);
18         void place(Block *, const Block::Endpoint *);
19         bool free_block(Block *);
20         void tick();
21 private:
22         struct BlockRef
23         {
24                 Block *block;
25                 const Block::Endpoint *entry;
26
27                 BlockRef(Block *s, const Block::Endpoint *e): block(s), entry(e) { }
28         };
29         typedef std::list<BlockRef> BlockRefSeq;
30
31         TrafficManager &trfc_mgr;
32         std::string name;
33         Locomotive &loco;
34         BlockRefSeq cur_blocks;
35         BlockRefSeq rsv_blocks;
36         unsigned target_speed;
37
38         void sensor_event(unsigned, bool);
39         bool reserve_more();
40 };
41 typedef std::list<Train *> TrainSeq;
42
43 } // namespace Marklin
44
45 #endif