]> git.tdb.fi Git - r2c2.git/blob - route.h
5c87971280300067ed055d5a6d15c3df31f0e576
[r2c2.git] / route.h
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2007-2010  Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #ifndef LIBR2C2_ROUTE_H_
9 #define LIBR2C2_ROUTE_H_
10
11 #include <map>
12 #include <set>
13 #include <string>
14 #include <sigc++/trackable.h>
15 #include <msp/datafile/loader.h>
16
17 namespace R2C2 {
18
19 class Layout;
20 class Track;
21 class TrackIter;
22 class Zone;
23
24 class Route: public sigc::trackable
25 {
26 public:
27         typedef std::map<unsigned, int> TurnoutMap;
28
29         class Loader: public Msp::DataFile::BasicLoader<Route>
30         {
31         private:
32                 TurnoutMap turnouts;
33
34         public:
35                 Loader(Route &);
36         private:
37                 virtual void finish();
38                 void turnout(unsigned, unsigned);
39         };
40
41         sigc::signal<void, const std::string &> signal_name_changed;
42
43 private:
44         Layout &layout;
45         std::string name;
46         bool temporary;
47         std::set<Track *> tracks;
48         TurnoutMap turnouts;
49
50 public:
51         Route(Layout &);
52         ~Route();
53
54         void set_name(const std::string &);
55         const std::string &get_name() const { return name; }
56         void set_temporary(bool);
57         bool is_temporary() const { return temporary; }
58         void set_turnout(unsigned, unsigned);
59         void update_turnouts();
60         int get_turnout(unsigned) const;
61         unsigned get_path(Track &) const;
62         const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
63         void add_track(Track &);
64         void add_tracks(const std::set<Track *> &);
65         void add_track_chain(Track &, unsigned, const TurnoutMap &);
66         const std::set<Track *> &get_tracks() const { return tracks; }
67         bool has_track(Track &) const;
68         void save(std::list<Msp::DataFile::Statement> &) const;
69 private:
70         unsigned check_validity(Track &) const;
71         void track_removed(Track &);
72
73 public:
74         static Route *find(const TrackIter &, Track &);
75         static Route *find(const TrackIter &, const Route &);
76         static Route *find(const TrackIter &, const Zone &);
77         static Route *find(const TrackIter &, const std::set<Track *> &);
78 };
79
80 } // namespace R2C2
81
82 #endif