]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/timetable.h
Also use TrackChains as target locations in Timetable
[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         };
32
33         struct Row
34         {
35                 class Loader: public Msp::DataFile::ObjectLoader<Row>
36                 {
37                 private:
38                         Layout &layout;
39
40                 public:
41                         Loader(Row &, Layout &);
42
43                 private:
44                         void block(unsigned);
45                         void time(Msp::Time::RawTime);
46                         void zone(const std::string &, unsigned);
47                 };
48
49                 RowType type;
50                 TrackChain *target;
51                 Msp::Time::TimeDelta time;
52
53                 Row();
54
55                 void save(std::list<Msp::DataFile::Statement> &) const;
56         };
57
58         sigc::signal<void, unsigned, const Row &> signal_row_added;
59         sigc::signal<void, unsigned, const Row &> signal_row_modified;
60         sigc::signal<void, unsigned> signal_row_removed;
61
62 private:
63         std::list<Row> rows;
64         std::list<Row>::iterator current_row;
65         bool update_pending;
66
67 public:
68         Timetable(Train &);
69
70         void append_row(const Row &);
71         void insert_row(unsigned, const Row &);
72         void modify_row(unsigned, const Row &);
73         void remove_row(unsigned);
74
75         unsigned get_length() const { return rows.size(); }
76         const Row &get_row(unsigned) const;
77
78         virtual void tick(const Msp::Time::TimeDelta &);
79
80         void save(std::list<Msp::DataFile::Statement> &) const;
81
82 private:
83         void check_update(std::list<Row>::const_iterator);
84         void update_route();
85         void event(TrainAI &, const Message &);
86 };
87
88 } // namespace R2C2
89
90 #endif