]> git.tdb.fi Git - r2c2.git/blobdiff - source/libmarklin/timetable.h
Add timetable-based operation
[r2c2.git] / source / libmarklin / timetable.h
diff --git a/source/libmarklin/timetable.h b/source/libmarklin/timetable.h
new file mode 100644 (file)
index 0000000..39cff5e
--- /dev/null
@@ -0,0 +1,76 @@
+/* $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