--- /dev/null
+#ifndef LIBR2C2_TIMETABLE_H_
+#define LIBR2C2_TIMETABLE_H_
+
+#include <msp/datafile/objectloader.h>
+#include "trainai.h"
+
+namespace R2C2 {
+
+class Layout;
+class Zone;
+
+class Timetable: public TrainAI
+{
+public:
+ class Loader: public Msp::DataFile::ObjectLoader<Timetable>
+ {
+ private:
+ Layout &layout;
+
+ public:
+ Loader(Timetable &, Layout &);
+
+ private:
+ void row();
+ };
+
+ enum RowType
+ {
+ ARRIVE = 1,
+ DEPART
+ };
+
+ struct Row
+ {
+ class Loader: public Msp::DataFile::ObjectLoader<Row>
+ {
+ private:
+ Layout &layout;
+
+ public:
+ Loader(Row &, Layout &);
+
+ private:
+ void zone(const std::string &, unsigned);
+ void time(Msp::Time::RawTime);
+ };
+
+ RowType type;
+ Zone *zone;
+ Msp::Time::TimeDelta time;
+
+ Row();
+
+ void save(std::list<Msp::DataFile::Statement> &) const;
+ };
+
+ sigc::signal<void, unsigned, const Row &> signal_row_added;
+ sigc::signal<void, unsigned, const Row &> signal_row_modified;
+ sigc::signal<void, unsigned> signal_row_removed;
+
+private:
+ std::list<Row> rows;
+ std::list<Row>::iterator current_row;
+ bool update_pending;
+
+public:
+ Timetable(Train &);
+
+ void append_row(const Row &);
+ void insert_row(unsigned, const Row &);
+ void modify_row(unsigned, const Row &);
+ void remove_row(unsigned);
+
+ unsigned get_length() const { return rows.size(); }
+ const Row &get_row(unsigned) const;
+
+ virtual void tick(const Msp::Time::TimeDelta &);
+
+ void save(std::list<Msp::DataFile::Statement> &) const;
+
+private:
+ void check_update(std::list<Row>::const_iterator);
+ void update_route();
+ void event(TrainAI &, const Message &);
+};
+
+} // namespace R2C2
+
+#endif