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