1 #ifndef LIBR2C2_LAYOUT_H_
2 #define LIBR2C2_LAYOUT_H_
6 #include <sigc++/sigc++.h>
7 #include <msp/datafile/objectloader.h>
8 #include <msp/time/timestamp.h>
32 class Loader: public Msp::DataFile::ObjectLoader<Layout>
40 void signal(const std::string &);
41 void terrain(const std::string &);
42 void track(const std::string &);
43 void train(const std::string &, unsigned, const std::string &);
44 void turnout(unsigned);
45 void turnout2(unsigned, unsigned);
55 mutable std::list<Msp::Variant> caches;
63 const std::set<B *> &get() const { return base; }
66 const std::set<T *> &get() const;
72 struct BlockReservation
77 BlockReservation(Block &, Train *);
81 typedef std::vector<Zone *> ZoneArray;
83 sigc::signal<void, Object &> signal_object_added;
84 sigc::signal<void, Object &> signal_object_removed;
85 sigc::signal<void, TrackChain &> signal_track_chain_added;
86 sigc::signal<void, TrackChain &> signal_track_chain_removed;
87 sigc::signal<void, Train &> signal_train_added;
88 sigc::signal<void, Train &> signal_train_removed;
89 sigc::signal<void, Block &, Train *> signal_block_reserved;
90 sigc::signal<void, Sensor &, Sensor::State> signal_sensor_state_changed;
91 sigc::signal<void, Block *, const std::string &> signal_emergency;
98 Storage<Object> objects;
99 Storage<TrackChain> track_chains;
100 Storage<Sensor> sensors;
101 std::map<unsigned, Train *> trains;
102 Msp::Time::TimeStamp last_tick;
103 unsigned next_turnout_addr;
104 bool emitting_block_reserved;
105 std::deque<BlockReservation> block_reserve_queue;
108 Layout(Catalogue &, Driver * = 0);
111 Catalogue &get_catalogue() const { return catalogue; }
112 bool has_driver() const { return driver; }
113 Driver &get_driver() const;
114 Clock &get_clock() { return clock; }
115 const std::string &get_base() const { return base; }
119 void add(TrackChain &);
122 void add(BeamGate &);
125 const std::set<T *> &get_all() const;
128 T *pick(const Ray &);
130 void remove(Object &);
131 void remove(Track &);
132 void remove(TrackChain &);
133 void remove(Sensor &);
134 void remove(BeamGate &);
136 unsigned allocate_turnout_address();
138 Block &get_block(unsigned) const;
139 void create_blocks();
140 void create_blocks(Track &);
142 Route &get_route(const std::string &) const;
143 void update_routes();
145 ZoneArray get_zones(const std::string &) const;
146 Zone &get_zone(const std::string &, unsigned) const;
148 void add_train(Train &);
149 Train &get_train(unsigned) const;
150 const std::map<unsigned, Train *> &get_trains() const { return trains; }
151 void remove_train(Train &);
154 void emergency(Block *, const std::string &);
156 void save(const std::string &) const;
157 void save_dynamic(const std::string &) const;
159 void sensor_state_changed(Sensor &, Sensor::State);
160 void block_reserved(Block &, Train *);