X-Git-Url: http://git.tdb.fi/?p=r2c2.git;a=blobdiff_plain;f=source%2Flibr2c2%2Ftimetable.h;h=3d7622aeb918c8ac35462df46e28cdc105548964;hp=84a39cd9c92d04de396638baa84c0f9bc999fe07;hb=d990c03a06a494ce3596862ce61e2a5684dea7e1;hpb=1c072afdb1866ba397ee8e6155f5f68c6c7ab4da diff --git a/source/libr2c2/timetable.h b/source/libr2c2/timetable.h index 84a39cd..3d7622a 100644 --- a/source/libr2c2/timetable.h +++ b/source/libr2c2/timetable.h @@ -1,109 +1,103 @@ #ifndef LIBR2C2_TIMETABLE_H_ #define LIBR2C2_TIMETABLE_H_ -#include -#include -#include #include -#include "block.h" +#include "trackchain.h" #include "trainai.h" namespace R2C2 { -class Track; -class Train; -class Zone; +class Layout; -class Timetable: public TrainAI, public sigc::trackable +class Timetable: public TrainAI { public: class Loader: public Msp::DataFile::ObjectLoader { + private: + Layout &layout; + public: - Loader(Timetable &); + Loader(Timetable &, Layout &); + private: - void arrive(); - void goto_sensor(unsigned); - void goto_sensor_str(const std::string &); - void goto_zone(const std::string &); - void route(const std::string &); - void reverse(); - void speed(unsigned); - void travel_to(unsigned); - void travel_past(unsigned); - void wait(unsigned); - void wait_train(unsigned, unsigned); - void wait_until(unsigned, unsigned); + void row(); }; enum RowType { - GOTO_SENSOR, - GOTO_ZONE, - TRAVEL_TO, - TRAVEL_PAST, - WAIT_TIME, - WAIT_UNTIL, - WAIT_TRAIN, - ARRIVE, - SPEED, - REVERSE, - ROUTE + ARRIVE = 1, + DEPART, + THROUGH }; struct Row { - RowType type; - std::vector params; + class Loader: public Msp::DataFile::ObjectLoader + { + private: + Layout &layout; - Row(RowType); + public: + Loader(Row &, Layout &); - template - Row(RowType, const T &); + private: + void block(unsigned); + void time(Msp::Time::RawTime); + void zone(const std::string &); + void zone_numbered(const std::string &, unsigned); + }; - template - const T &get_param(unsigned) const; + RowType type; + TrackChain *target; + TrackChain::Direction direction; + Msp::Time::TimeDelta time; - std::string str() const; + Row(); - Msp::DataFile::Statement save() const; + void save(std::list &) const; + }; - static Row parse(const std::string &); + struct RowTypeMatch + { + RowType type; + + RowTypeMatch(RowType t): type(t) { } + + bool operator()(const Row &r) const { return r.type==type; } }; + sigc::signal signal_row_added; + sigc::signal signal_row_modified; + sigc::signal signal_row_removed; + private: - bool enabled; - std::vector rows; - unsigned current_row; - bool executing; - Block *pending_block; - Train *pending_train; - Msp::Time::TimeStamp wait_timeout; - bool arrived; + std::list rows; + std::list::iterator current_row; + bool update_pending; + bool sync_to_clock; public: Timetable(Train &); - void set_enabled(bool); - bool is_enabled() const { return enabled; } - void reset(); + void append_row(const Row &); + void insert_row(unsigned, const Row &); + void modify_row(unsigned, const Row &); + void remove_row(unsigned); - void clear(); - void append(const Row &); - void insert(unsigned, const Row &); - unsigned get_n_rows() const { return rows.size(); } + unsigned get_length() const { return rows.size(); } const Row &get_row(unsigned) const; - void tick(const Msp::Time::TimeStamp &, const Msp::Time::TimeDelta &); + virtual void tick(const Msp::Time::TimeDelta &); + void save(std::list &) const; + private: - Block &get_sensor(unsigned); - Track &get_turnout(unsigned); - Zone &get_zone(const std::string &); - void block_state_changed(Block &, Block::State); - void block_reserved(Block &, Train *); - void train_advanced(Block &); + void check_update(const std::list::const_iterator &); + std::list::iterator find_trip(const std::list::iterator &, std::list::iterator *); + void update_route(); void event(TrainAI &, const Message &); + void record_time(); }; } // namespace R2C2