]> git.tdb.fi Git - r2c2.git/blob - libr2c2/route.h
Don't crash if a train has no router
[r2c2.git] / libr2c2 / route.h
1 #ifndef LIBR2C2_ROUTE_H_
2 #define LIBR2C2_ROUTE_H_
3
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <sigc++/trackable.h>
8 #include <msp/datafile/objectloader.h>
9 #include "trackchain.h"
10
11 namespace R2C2 {
12
13 class Layout;
14 class Object;
15 class Track;
16 class TrackIter;
17 class Zone;
18
19
20 class Route: public TrackChain
21 {
22 public:
23         typedef std::map<unsigned, int> TurnoutMap;
24
25         class Loader: public Msp::DataFile::ObjectLoader<Route>
26         {
27         private:
28                 TurnoutMap turnouts;
29
30         public:
31                 Loader(Route &);
32         private:
33                 virtual void finish();
34                 void turnout(unsigned, unsigned);
35         };
36
37         sigc::signal<void, const std::string &> signal_name_changed;
38
39 private:
40         std::string name;
41         bool temporary;
42         TurnoutMap turnouts;
43
44 public:
45         Route(Layout &);
46         ~Route();
47
48         void set_name(const std::string &);
49         const std::string &get_name() const { return name; }
50         void set_temporary(bool);
51         bool is_temporary() const { return temporary; }
52         void update_turnouts();
53 private:
54         void update_turnout(Track &);
55 public:
56         int get_turnout(unsigned) const;
57         unsigned get_path(Track &) const;
58         const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
59 private:
60         void add_turnout(Track &, unsigned);
61         virtual void on_track_added(Track &);
62
63 public:
64         void save(std::list<Msp::DataFile::Statement> &) const;
65
66         static Route *find(const TrackIter &, Track &);
67         static Route *find(const TrackIter &, const Route &);
68         static Route *find(const TrackIter &, const Zone &);
69         static Route *find(const TrackIter &, const std::set<Track *> &);
70 };
71
72 } // namespace R2C2
73
74 #endif