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