3 This file is part of R²C²
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #ifndef LIBR2C2_LAYOUT_H_
9 #define LIBR2C2_LAYOUT_H_
12 #include <sigc++/sigc++.h>
13 #include <msp/datafile/loader.h>
14 #include <msp/time/timestamp.h>
31 class Loader: public Msp::DataFile::BasicLoader<Layout>
39 virtual void finish();
41 void route(const std::string &);
43 void track(ArticleNumber);
44 void train(unsigned, unsigned, const std::string &);
45 void train(ArticleNumber, unsigned, const std::string &);
49 typedef std::set<Zone *> ZoneSet;
50 typedef std::vector<Zone *> ZoneArray;
52 sigc::signal<void, Track &> signal_track_added;
53 sigc::signal<void, Track &> signal_track_removed;
54 sigc::signal<void, Route &> signal_route_added;
55 sigc::signal<void, Route &> signal_route_removed;
56 sigc::signal<void, Zone &> signal_zone_added;
57 sigc::signal<void, Zone &> signal_zone_removed;
58 sigc::signal<void, Train &> signal_train_added;
59 sigc::signal<void, Train &> signal_train_removed;
60 sigc::signal<void, Vehicle &> signal_vehicle_added;
61 sigc::signal<void, Vehicle &> signal_vehicle_removed;
62 sigc::signal<void, Block &, Train *> signal_block_reserved;
63 sigc::signal<void, const std::string &> signal_emergency;
69 std::set<Track *> tracks;
70 std::set<Route *> routes;
72 std::set<Block *> blocks;
73 std::map<unsigned, Train *> trains;
74 std::set<Vehicle *> vehicles;
75 Msp::Time::TimeStamp last_tick;
76 unsigned next_turnout_id;
79 Layout(Catalogue &, Driver * = 0);
82 Catalogue &get_catalogue() const { return catalogue; }
83 bool has_driver() const { return driver; }
84 Driver &get_driver() const;
85 const std::string &get_base() const { return base; }
87 void add_track(Track &);
88 const std::set<Track *> &get_tracks() const { return tracks; }
89 void remove_track(Track &);
90 unsigned allocate_turnout_id(bool);
92 void add_block(Block &);
93 Block &get_block(unsigned) const;
94 const std::set<Block *> &get_blocks() const { return blocks; }
96 void create_blocks(Track &);
97 void remove_block(Block &);
99 void add_route(Route &);
100 const std::set<Route *> &get_routes() const { return routes; }
101 Route &get_route(const std::string &) const;
102 void update_routes();
103 void remove_route(Route &);
105 void add_zone(Zone &);
106 const ZoneSet &get_zones() const { return zones; }
107 ZoneArray get_zones(const std::string &) const;
108 Zone &get_zone(const std::string &, unsigned) const;
109 void remove_zone(Zone &);
111 void add_train(Train &);
112 Train &get_train(unsigned) const;
113 const std::map<unsigned, Train *> &get_trains() const { return trains; }
114 void remove_train(Train &);
116 void add_vehicle(Vehicle &);
117 void remove_vehicle(Vehicle &);
120 void emergency(const std::string &);
122 void save(const std::string &) const;
123 void save_trains(const std::string &) const;
125 void sensor_event(unsigned, bool);