]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/timetable.h
39cff5ee6b2b14a077445521783ac2039630acd9
[r2c2.git] / source / libmarklin / timetable.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_TIMETABLE_H_
9 #define LIBMARKLIN_TIMETABLE_H_
10
11 #include <string>
12 #include <vector>
13 #include <msp/datafile/objectloader.h>
14 #include <msp/time/timestamp.h>
15
16 namespace Marklin {
17
18 class Block;
19 class Train;
20
21 class Timetable
22 {
23 public:
24         class Loader: public Msp::DataFile::ObjectLoader<Timetable>
25         {
26         public:
27                 Loader(Timetable &);
28         private:
29                 void go_to(const std::string &);
30                 void route(const std::string &);
31                 void speed(int);
32                 void travel(const std::string &);
33                 void wait(unsigned);
34         };
35
36         enum RowType
37         {
38                 GOTO,
39                 TRAVEL,
40                 WAIT,
41                 SPEED,
42                 ROUTE
43         };
44
45         struct Row
46         {
47                 RowType type;
48                 int intparam;
49                 std::string strparam;
50
51                 Row(RowType, int);
52                 Row(RowType, const std::string &);
53         };
54
55 private:
56         Train &train;
57         std::vector<Row> rows;
58         unsigned current_row;
59         bool executing;
60         Block *pending_block;
61         Msp::Time::TimeStamp wait_timeout;
62
63 public:
64         Timetable(Train &);
65
66         void tick(const Msp::Time::TimeStamp &);
67         void save(std::list<Msp::DataFile::Statement> &) const;
68 private:
69         Block &parse_location(const std::string &);
70         void sensor_event(unsigned, bool);
71         void train_arrived();
72 };
73
74 } // namespace Marklin
75
76 #endif