]> 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 name(const std::string &);
35                 void turnout(unsigned, unsigned);
36         };
37
38 private:
39         bool temporary;
40         TurnoutMap turnouts;
41
42 public:
43         Route(Layout &);
44         ~Route();
45
46         void set_temporary(bool);
47         bool is_temporary() const { return temporary; }
48         void update_turnouts();
49 private:
50         void update_turnout(Track &);
51 public:
52         int get_turnout(unsigned) const;
53         unsigned get_path(Track &) const;
54         const std::map<unsigned, int> &get_turnouts() const { return turnouts; }
55 private:
56         void add_turnout(Track &, unsigned);
57         virtual void on_track_added(Track &);
58
59 public:
60         void save(std::list<Msp::DataFile::Statement> &) const;
61
62         static Route *find(const TrackIter &, Track &);
63         static Route *find(const TrackIter &, const Route &);
64         static Route *find(const TrackIter &, const Zone &);
65         static Route *find(const TrackIter &, const std::set<Track *> &);
66 };
67
68 } // namespace R2C2
69
70 #endif