aboutsummaryrefslogtreecommitdiff
path: root/examples/inheritance/position.hxx
blob: 9be93a19a425107b011e88cd621e9d0645b2c995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// file      : examples/inheritance/position.hxx
// copyright : not copyrighted - public domain

#ifndef POSITION_HXX
#define POSITION_HXX

#include <string>
#include <vector>
#include <iosfwd>

#include <xml/forward.hxx> // xml::{parser,serializer} forward declarations.

class position
{
public:
  position (float lat = 0, float lon = 0): lat_ (lat), lon_ (lon) {}

  float
  lat () const {return lat_;}

  float
  lon () const {return lon_;}

  // XML persistence.
  //
public:
  position (xml::parser&);

  void
  serialize (xml::serializer&) const;

private:
  float lat_;
  float lon_;
};

class object
{
public:
  object (const std::string& name, unsigned int id): name_ (name), id_ (id) {}

  const std::string&
  name () const {return name_;}

  unsigned int
  id () const {return id_;}

  typedef std::vector<position> positions_type;

  positions_type&
  positions () {return positions_;}

  const positions_type&
  positions () const {return positions_;}

  // XML persistence.
  //
public:
  object (xml::parser&);

  void
  serialize_attributes (xml::serializer&) const;

  void
  serialize_content (xml::serializer&) const;

  void
  serialize (xml::serializer& s) const
  {
    serialize_attributes (s);
    serialize_content (s);
  }

private:
  std::string name_;
  unsigned int id_;
  positions_type positions_;
};

class elevation
{
public:
  elevation (float value = 0): value_ (value) {}

  float
  value () const {return value_;}

  // XML persistence.
  //
public:
  elevation (xml::parser&);

  void
  serialize (xml::serializer&) const;

private:
  float value_;
};

class elevated_object: public object
{
public:
  elevated_object (const std::string& name,
                   const std::string& units,
                   unsigned int id)
      : object (name, id), units_ (units) {}

  const std::string&
  units () const {return units_;}

  typedef std::vector<elevation> elevations_type;

  elevations_type&
  elevations () {return elevations_;}

  const elevations_type&
  elevations () const {return elevations_;}

  // XML persistence.
  //
public:
  elevated_object (xml::parser&);

  void
  serialize_attributes (xml::serializer&) const;

  void
  serialize_content (xml::serializer&) const;

  void
  serialize (xml::serializer& s) const
  {
    serialize_attributes (s);
    serialize_content (s);
  }

private:
  std::string units_;
  elevations_type elevations_;
};

class objects
{
public:
  typedef std::vector<object> simple_objects_type;
  typedef std::vector<elevated_object> elevated_objects_type;

  simple_objects_type&
  simple_objects () {return simple_objects_;}

  const simple_objects_type&
  simple_objects () const {return simple_objects_;}

  elevated_objects_type&
  elevated_objects () {return elevated_objects_;}

  const elevated_objects_type&
  elevated_objects () const {return elevated_objects_;}

  // XML persistence.
  //
public:
  objects (xml::parser&);

  void
  serialize (xml::serializer&) const;

private:
  simple_objects_type simple_objects_;
  elevated_objects_type elevated_objects_;
};

#endif // POSITION_HXX