]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/timetable.h
Allow zones with no qualifier or no number
[r2c2.git] / source / libr2c2 / timetable.h
index cbbb49b3d9e3d357fa9e24780f834c752ee69123..3d7622aeb918c8ac35462df46e28cdc105548964 100644 (file)
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #ifndef LIBR2C2_TIMETABLE_H_
 #define LIBR2C2_TIMETABLE_H_
 
-#include <string>
-#include <vector>
-#include <sigc++/trackable.h>
 #include <msp/datafile/objectloader.h>
-#include <msp/time/timestamp.h>
+#include "trackchain.h"
+#include "trainai.h"
 
 namespace R2C2 {
 
-class Block;
-class Track;
-class Train;
-class Zone;
+class Layout;
 
-class Timetable: public sigc::trackable
+class Timetable: public TrainAI
 {
 public:
        class Loader: public Msp::DataFile::ObjectLoader<Timetable>
        {
+       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<Msp::Variant> params;
+               class Loader: public Msp::DataFile::ObjectLoader<Row>
+               {
+               private:
+                       Layout &layout;
 
-               Row(RowType);
+               public:
+                       Loader(Row &, Layout &);
 
-               template<typename T>
-               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<typename T>
-               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<Msp::DataFile::Statement> &) 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<void, unsigned, const Row &> signal_row_added;
+       sigc::signal<void, unsigned, const Row &> signal_row_modified;
+       sigc::signal<void, unsigned> signal_row_removed;
+
 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;
-       bool arrived;
+       std::list<Row> rows;
+       std::list<Row>::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 &);
+       virtual void tick(const Msp::Time::TimeDelta &);
+
        void save(std::list<Msp::DataFile::Statement> &) const;
+
 private:
-       Track &get_sensor(unsigned);
-       Track &get_turnout(unsigned);
-       Zone &get_zone(const std::string &);
-       void sensor_event(unsigned, bool);
-       void block_reserved(Block &, Train *);
-       void train_advanced(Block &);
-       void train_arrived();
+       void check_update(const std::list<Row>::const_iterator &);
+       std::list<Row>::iterator find_trip(const std::list<Row>::iterator &, std::list<Row>::iterator *);
+       void update_route();
+       void event(TrainAI &, const Message &);
+       void record_time();
 };
 
 } // namespace R2C2