aboutsummaryrefslogtreecommitdiff
path: root/examples/inheritance/position.hxx
blob: d86995dceeb67f896979e9094e8768fec7ad58bd (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
// 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:
  // Constructors as well as accessor and modifiers not shown.

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

  void
  serialize (xml::serializer&) const;

private:
  float lat_;
  float lon_;
};

class object
{
public:
  typedef std::vector<position> positions_type;

  // Constructors as well as accessor and modifiers not shown.

  // 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:
  // Constructors as well as accessor and modifiers not shown.

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

  void
  serialize (xml::serializer&) const;

private:
  float value_;
};

class elevated_object: public object
{
public:
  typedef std::vector<elevation> elevations_type;

  // Constructors as well as accessor and modifiers not shown.

  // 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;

  // Constructors as well as accessor and modifiers not shown.

  // 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