+/* $Id$
+
+This file is part of the MSP Märklin suite
+Copyright © 2010 Mikkosoft Productions, Mikko Rasa
+Distributed under the GPL
+*/
+
+#ifndef LIBMARKLIN_TIMETABLE_H_
+#define LIBMARKLIN_TIMETABLE_H_
+
+#include <string>
+#include <vector>
+#include <msp/datafile/objectloader.h>
+#include <msp/time/timestamp.h>
+
+namespace Marklin {
+
+class Block;
+class Train;
+
+class Timetable
+{
+public:
+ class Loader: public Msp::DataFile::ObjectLoader<Timetable>
+ {
+ public:
+ Loader(Timetable &);
+ private:
+ void go_to(const std::string &);
+ void route(const std::string &);
+ void speed(int);
+ void travel(const std::string &);
+ void wait(unsigned);
+ };
+
+ enum RowType
+ {
+ GOTO,
+ TRAVEL,
+ WAIT,
+ SPEED,
+ ROUTE
+ };
+
+ struct Row
+ {
+ RowType type;
+ int intparam;
+ std::string strparam;
+
+ Row(RowType, int);
+ Row(RowType, const std::string &);
+ };
+
+private:
+ Train &train;
+ std::vector<Row> rows;
+ unsigned current_row;
+ bool executing;
+ Block *pending_block;
+ Msp::Time::TimeStamp wait_timeout;
+
+public:
+ Timetable(Train &);
+
+ void tick(const Msp::Time::TimeStamp &);
+ void save(std::list<Msp::DataFile::Statement> &) const;
+private:
+ Block &parse_location(const std::string &);
+ void sensor_event(unsigned, bool);
+ void train_arrived();
+};
+
+} // namespace Marklin
+
+#endif