]> git.tdb.fi Git - r2c2.git/blob - layout.h
ecb801f0e07c5bc8d4c4af4f9edb300967fba6db
[r2c2.git] / layout.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_LAYOUT_H_
9 #define LIBR2C2_LAYOUT_H_
10
11 #include <set>
12 #include <sigc++/sigc++.h>
13 #include <msp/datafile/loader.h>
14 #include <msp/time/timestamp.h>
15
16 namespace R2C2 {
17
18 class ArticleNumber;
19 class Block;
20 class Catalogue;
21 class Driver;
22 class Route;
23 class Track;
24 class Train;
25 class Vehicle;
26 class Zone;
27
28 class Layout
29 {
30 public:
31         class Loader: public Msp::DataFile::BasicLoader<Layout>
32         {
33         private:
34                 bool new_tracks;
35
36         public:
37                 Loader(Layout &);
38         private:
39                 virtual void finish();
40                 void route();
41                 void route(const std::string &);
42                 void track(unsigned);
43                 void track(ArticleNumber);
44                 void train(unsigned, unsigned, const std::string &);
45                 void train(ArticleNumber, unsigned, const std::string &);
46                 void zone();
47         };
48
49         typedef std::set<Zone *> ZoneSet;
50         typedef std::vector<Zone *> ZoneArray;
51
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;
64
65 private:
66         Catalogue &catalogue;
67         Driver *driver;
68         std::string base;
69         std::set<Track *> tracks;
70         std::set<Route *> routes;
71         ZoneSet zones;
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;
77
78 public:
79         Layout(Catalogue &, Driver * = 0);
80         ~Layout();
81
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; }
86
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);
91
92         void add_block(Block &);
93         Block &get_block(unsigned) const;
94         const std::set<Block *> &get_blocks() const { return blocks; }
95         void create_blocks();
96         void create_blocks(Track &);
97         void remove_block(Block &);
98
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 &);
104
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 &);
110
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 &);
115
116         void add_vehicle(Vehicle &);
117         void remove_vehicle(Vehicle &);
118
119         void tick();
120         void emergency(const std::string &);
121
122         void save(const std::string &) const;
123         void save_trains(const std::string &) const;
124 private:
125         void sensor_event(unsigned, bool);
126 };
127
128 } // namespace R2C2
129
130 #endif
131