]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/timetable.h
Plug memory leaks
[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 <sigc++/trackable.h>
14 #include <msp/datafile/objectloader.h>
15 #include <msp/time/timestamp.h>
16
17 namespace Marklin {
18
19 class Block;
20 class Train;
21
22 class Timetable: public sigc::trackable
23 {
24 public:
25         class Loader: public Msp::DataFile::ObjectLoader<Timetable>
26         {
27         public:
28                 Loader(Timetable &);
29         private:
30                 void go_to(const std::string &);
31                 void route(const std::string &);
32                 void speed(int);
33                 void travel(const std::string &);
34                 void wait(unsigned);
35         };
36
37         enum RowType
38         {
39                 GOTO,
40                 TRAVEL,
41                 WAIT,
42                 SPEED,
43                 ROUTE
44         };
45
46         struct Row
47         {
48                 RowType type;
49                 int intparam;
50                 std::string strparam;
51
52                 Row(RowType, int);
53                 Row(RowType, const std::string &);
54         };
55
56 private:
57         Train &train;
58         std::vector<Row> rows;
59         unsigned current_row;
60         bool executing;
61         Block *pending_block;
62         Msp::Time::TimeStamp wait_timeout;
63
64 public:
65         Timetable(Train &);
66
67         void tick(const Msp::Time::TimeStamp &);
68         void save(std::list<Msp::DataFile::Statement> &) const;
69 private:
70         Block &parse_location(const std::string &);
71         void sensor_event(unsigned, bool);
72         void train_arrived();
73 };
74
75 } // namespace Marklin
76
77 #endif