-/* $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 <sigc++/trackable.h>
-#include <msp/datafile/objectloader.h>
-#include <msp/time/timestamp.h>
-
-namespace Marklin {
-
-class Block;
-class Train;
-
-class Timetable: public sigc::trackable
-{
-public:
- class Loader: public Msp::DataFile::ObjectLoader<Timetable>
- {
- public:
- Loader(Timetable &);
- private:
- void arrive();
- void go_to(const std::string &);
- void route(const std::string &);
- void reverse();
- void speed(unsigned);
- void travel(const std::string &);
- void wait(unsigned);
- void wait_train(unsigned, const std::string &);
- };
-
- enum RowType
- {
- GOTO,
- TRAVEL,
- WAIT_TIME,
- WAIT_TRAIN,
- ARRIVE,
- SPEED,
- REVERSE,
- ROUTE
- };
-
- struct Row
- {
- RowType type;
- std::vector<Msp::Variant> params;
-
- Row(RowType);
-
- template<typename T>
- Row(RowType, const T &);
-
- template<typename T>
- const T &get_param(unsigned) const;
-
- std::string str() const;
-
- Msp::DataFile::Statement save() const;
-
- static Row parse(const std::string &);
- };
-
-private:
- Train &train;
- bool enabled;
- std::vector<Row> rows;
- unsigned current_row;
- bool executing;
- Block *pending_block;
- Train *pending_train;
- Msp::Time::TimeStamp wait_timeout;
-
-public:
- Timetable(Train &);
-
- void set_enabled(bool);
- bool is_enabled() const { return enabled; }
- void reset();
-
- void clear();
- void append(const Row &);
- void insert(unsigned, const Row &);
- unsigned get_n_rows() const { return rows.size(); }
- const Row &get_row(unsigned) const;
-
- 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