]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/trainai.h
Strip Id tags and copyright notices from files
[r2c2.git] / source / libr2c2 / trainai.h
1 #ifndef LIBR2C2_TRAINAI_H_
2 #define LIBR2C2_TRAINAI_H_
3
4 #include <string>
5 #include <sigc++/signal.h>
6 #include <msp/core/variant.h>
7 #include <msp/time/timedelta.h>
8 #include <msp/time/timestamp.h>
9
10 namespace R2C2 {
11
12 class Train;
13
14 /**
15 Base class for train AIs.
16
17 AIs can help the user in various ways, ranging from automatically stopping the
18 train at the end of allocated track to autonomously running a train.
19
20 XXX The timestamp should be removed from tick, but Timetable depends on it
21 */
22 class TrainAI
23 {
24 public:
25         struct Message
26         {
27                 std::string type;
28                 Msp::Variant value;
29
30                 Message(const std::string &t): type(t) { }
31
32                 template<typename T>
33                 Message(const std::string &t, const T &v): type(t), value(v) { }
34         };
35
36         sigc::signal<void, const Message &> signal_event;
37
38 protected:
39         Train &train;
40         std::string tag;
41
42         TrainAI(Train &);
43 public:
44         virtual ~TrainAI();
45
46         void set_tag(const std::string &);
47         const std::string &get_tag() const { return tag; }
48
49         virtual void message(const Message &) { }
50         virtual void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &) { }
51 };
52
53 } // namespace R2C2
54
55 #endif