1 // file : examples/persistence/position.hxx 2 // copyright : not copyrighted - public domain 3 4 #ifndef POSITION_HXX 5 #define POSITION_HXX 6 7 #include <string> 8 #include <vector> 9 #include <iosfwd> 10 11 #include <libstudxml/forward.hxx> // xml::{parser,serializer} forward declarations. 12 13 enum object_type {building, mountain}; 14 15 // XML parser and serializer will use these operators to convert 16 // object_type to/from a string representation unless we provide 17 // an xml::value_traits specialization. 18 // 19 std::ostream& 20 operator<< (std::ostream&, object_type); 21 22 std::istream& 23 operator>> (std::istream&, object_type&); 24 25 class position 26 { 27 public: 28 // Constructors as well as accessor and modifiers not shown. 29 30 // XML persistence. 31 // 32 public: 33 position (xml::parser&); 34 35 void 36 serialize (xml::serializer&) const; 37 38 private: 39 float lat_; 40 float lon_; 41 }; 42 43 class object 44 { 45 public: 46 typedef std::vector<position> positions_type; 47 48 // Constructors as well as accessor and modifiers not shown. 49 50 // XML persistence. 51 // 52 public: 53 object (xml::parser&); 54 55 void 56 serialize (xml::serializer&) const; 57 58 private: 59 std::string name_; 60 object_type type_; 61 unsigned int id_; 62 positions_type positions_; 63 }; 64 65 #endif // POSITION_HXX 66