]> git.tdb.fi Git - r2c2.git/blob - source/libmarklin/route.h
Don't leave removed tracks in routes
[r2c2.git] / source / libmarklin / route.h
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2007-2009  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBMARKLIN_ROUTE_H_
9 #define LIBMARKLIN_ROUTE_H_
10
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <msp/datafile/loader.h>
15
16 namespace Marklin {
17
18 class Layout;
19 class Track;
20 class Turnout;
21
22 class Route
23 {
24 public:
25         class Loader: public Msp::DataFile::BasicLoader<Route>
26         {
27         public:
28                 Loader(Route &);
29         private:
30                 void turnout(unsigned, unsigned);
31         };
32
33 private:
34         std::string name;
35         std::set<const Track *> tracks;
36         std::map<unsigned, int> turnouts;
37
38 public:
39         Route(Layout &, const std::string &);
40
41         const std::string &get_name() const { return name; }
42         int get_turnout(unsigned) const;
43         const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
44         void add_track(const Track &);
45         void add_tracks(const std::set<const Track *> &);
46         const std::set<const Track *> &get_tracks() const { return tracks; }
47         void save(std::list<Msp::DataFile::Statement> &) const;
48 private:
49         void update_turnouts();
50         unsigned check_validity(const Track &) const;
51         void track_removed(Track &);
52 };
53
54 } // namespace Marklin
55
56 #endif