]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/timetable.h
New timetable system, which works like an actual timetable
[r2c2.git] / source / libr2c2 / timetable.h
diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h
new file mode 100644 (file)
index 0000000..b67e5fb
--- /dev/null
@@ -0,0 +1,89 @@
+#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