]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/layout.h
Fix a segfault in removing vehicles when creating a new train
[r2c2.git] / source / libmarklin / layout.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_LAYOUT_H_
9 #define LIBMARKLIN_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 Marklin {
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
27 class Layout
28 {
29 public:
30         class Loader: public Msp::DataFile::BasicLoader<Layout>
31         {
32         private:
33                 bool new_tracks;
34
35         public:
36                 Loader(Layout &);
37         private:
38                 virtual void finish();
39                 void route();
40                 void route(const std::string &);
41                 void track(unsigned);
42                 void track(ArticleNumber);
43                 void train(unsigned, unsigned, const std::string &);
44                 void train(ArticleNumber, unsigned, const std::string &);
45         };
46
47 public:
48         sigc::signal<void, Track &> signal_track_added;
49         sigc::signal<void, Track &> signal_track_removed;
50         sigc::signal<void, Route &> signal_route_added;
51         sigc::signal<void, Route &> signal_route_removed;
52         sigc::signal<void, Train &> signal_train_added;
53         sigc::signal<void, Train &> signal_train_removed;
54         sigc::signal<void, Vehicle &> signal_vehicle_added;
55         sigc::signal<void, Vehicle &> signal_vehicle_removed;
56         sigc::signal<void, Block &, Train *> signal_block_reserved;
57         sigc::signal<void, const std::string &> signal_emergency;
58
59 private:
60         Catalogue &catalogue;
61         Driver *driver;
62         std::string base;
63         std::set<Track *> tracks;
64         std::set<Route *> routes;
65         std::set<Block *> blocks;
66         std::map<unsigned, Train *> trains;
67         std::set<Vehicle *> vehicles;
68         Msp::Time::TimeStamp last_tick;
69         unsigned next_turnout_id;
70
71 public:
72         Layout(Catalogue &, Driver * = 0);
73         ~Layout();
74
75         Catalogue &get_catalogue() const { return catalogue; }
76         bool has_driver() const { return driver; }
77         Driver &get_driver() const;
78         const std::string &get_base() const { return base; }
79
80         void add_track(Track &);
81         const std::set<Track *> &get_tracks() const { return tracks; }
82         void remove_track(Track &);
83         unsigned allocate_turnout_id(bool);
84
85         void add_block(Block &);
86         Block &get_block(unsigned) const;
87         const std::set<Block *> &get_blocks() const { return blocks; }
88         void create_blocks();
89         void create_blocks(Track &);
90         void remove_block(Block &);
91
92         void add_route(Route &);
93         const std::set<Route *> &get_routes() const { return routes; }
94         Route &get_route(const std::string &) const;
95         void update_routes();
96         void remove_route(Route &);
97
98         void add_train(Train &);
99         Train &get_train(unsigned) const;
100         const std::map<unsigned, Train *> &get_trains() const { return trains; }
101         void remove_train(Train &);
102
103         void add_vehicle(Vehicle &);
104         void remove_vehicle(Vehicle &);
105
106         void tick();
107         void emergency(const std::string &);
108
109         void save(const std::string &);
110         void save_trains(const std::string &);
111 private:
112         void sensor_event(unsigned, bool);
113 };
114
115 } // namespace Marklin
116
117 #endif
118