]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/train.h
Initial revision
[r2c2.git] / source / libmarklin / train.h
1 #ifndef LIBMARKLIN_TRAIN_H_
2 #define LIBMARKLIN_TRAIN_H_
3
4 #include <sigc++/trackable.h>
5 #include "section.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(Section *, const Section::Endpoint *);
19         bool free_section(Section *);
20         void tick();
21 private:
22         struct SectionRef
23         {
24                 Section *section;
25                 const Section::Endpoint *entry;
26
27                 SectionRef(Section *s, const Section::Endpoint *e): section(s), entry(e) { }
28         };
29         typedef std::list<SectionRef> SectRefSeq;
30
31         TrafficManager &trfc_mgr;
32         std::string name;
33         Locomotive &loco;
34         SectRefSeq cur_sections;
35         SectRefSeq rsv_sections;
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