]> git.tdb.fi Git - r2c2.git/blob - source/libr2c2/tracktype.h
Get rid of some obsolete #includes
[r2c2.git] / source / libr2c2 / tracktype.h
1 #ifndef LIBR2C2_TRACKTYPE_H_
2 #define LIBR2C2_TRACKTYPE_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "geometry.h"
6 #include "objecttype.h"
7 #include "trackpart.h"
8
9 namespace R2C2 {
10
11 class TrackAppearance;
12
13 class TrackType: public ObjectType
14 {
15 public:
16         struct Endpoint
17         {
18                 Vector pos;
19                 Angle dir;  // Direction outwards from the endpoint
20                 unsigned paths;
21
22                 Endpoint(float, float, const Angle &, unsigned);
23
24                 bool has_path(unsigned p) const { return paths&(1<<p); }
25                 bool has_common_paths(const Endpoint &e) const { return paths&e.paths; }
26         };
27
28         class Loader: public Msp::DataFile::DerivedObjectLoader<TrackType, ObjectType::Loader>
29         {
30         public:
31                 typedef Msp::DataFile::Collection Collection;
32
33         private:
34                 Collection &coll;
35                 bool state_bits_set;
36
37         public:
38                 Loader(TrackType &, Collection &);
39
40                 virtual Collection &get_collection() const { return coll; }
41         private:
42                 virtual void finish();
43                 void appearance(const std::string &);
44                 void part();
45                 void state_bits(unsigned);
46         };
47
48 private:
49         const TrackAppearance *appearance;
50         std::vector<TrackPart> parts;
51         std::vector<Endpoint> endpoints;
52         unsigned state_bits;
53         unsigned autofit_preference;
54         std::string object;
55
56 public:
57         TrackType();
58
59         const TrackAppearance &get_appearance() const;
60         float get_gauge() const;
61         float get_total_length() const;
62         float get_path_length(int) const;
63         unsigned get_paths() const;
64         unsigned get_n_paths() const;
65         unsigned coerce_path(unsigned, unsigned) const;
66         unsigned get_state_bits() const { return state_bits; }
67         bool is_turnout() const;
68         bool is_dead_end() const;
69         unsigned get_autofit_preference() const { return autofit_preference; }
70         const std::string &get_object() const { return object; }
71         const std::vector<TrackPart> &get_parts() const { return parts; }
72         const std::vector<Endpoint> &get_endpoints() const { return endpoints; }
73         const Endpoint &get_endpoint(unsigned) const;
74         OrientedPoint get_point(unsigned, unsigned, float) const;
75         OrientedPoint get_nearest_point(const Vector &) const;
76
77 private:
78         void collect_endpoints();
79 };
80
81 } // namespace R2C2
82
83 #endif