]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/timetable.h
Implement flush() for ArduControl
[r2c2.git] / source / libr2c2 / timetable.h
1 #ifndef LIBR2C2_TIMETABLE_H_
2 #define LIBR2C2_TIMETABLE_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "trainai.h"
6
7 namespace R2C2 {
8
9 class Layout;
10 class TrackChain;
11
12 class Timetable: public TrainAI
13 {
14 public:
15         class Loader: public Msp::DataFile::ObjectLoader<Timetable>
16         {
17         private:
18                 Layout &layout;
19
20         public:
21                 Loader(Timetable &, Layout &);
22
23         private:
24                 void row();
25         };
26
27         enum RowType
28         {
29                 ARRIVE = 1,
30                 DEPART,
31                 THROUGH
32         };
33
34         struct Row
35         {
36                 class Loader: public Msp::DataFile::ObjectLoader<Row>
37                 {
38                 private:
39                         Layout &layout;
40
41                 public:
42                         Loader(Row &, Layout &);
43
44                 private:
45                         void block(unsigned);
46                         void time(Msp::Time::RawTime);
47                         void zone(const std::string &, unsigned);
48                 };
49
50                 RowType type;
51                 TrackChain *target;
52                 Msp::Time::TimeDelta time;
53
54                 Row();
55
56                 void save(std::list<Msp::DataFile::Statement> &) const;
57         };
58
59         sigc::signal<void, unsigned, const Row &> signal_row_added;
60         sigc::signal<void, unsigned, const Row &> signal_row_modified;
61         sigc::signal<void, unsigned> signal_row_removed;
62
63 private:
64         std::list<Row> rows;
65         std::list<Row>::iterator current_row;
66         bool update_pending;
67
68 public:
69         Timetable(Train &);
70
71         void append_row(const Row &);
72         void insert_row(unsigned, const Row &);
73         void modify_row(unsigned, const Row &);
74         void remove_row(unsigned);
75
76         unsigned get_length() const { return rows.size(); }
77         const Row &get_row(unsigned) const;
78
79         virtual void tick(const Msp::Time::TimeDelta &);
80
81         void save(std::list<Msp::DataFile::Statement> &) const;
82
83 private:
84         void check_update(std::list<Row>::const_iterator);
85         void update_route();
86         void event(TrainAI &, const Message &);
87         void record_time();
88 };
89
90 } // namespace R2C2
91
92 #endif