source: subversion/applications/lib/libosm/Object.h @ 11745

Revision 11745, 2.6 KB checked in by nienhueser, 5 years ago (diff)

Encapsulate Object::tags and add more documentation

Line 
1#ifndef OSMOBJECT_H
2#define OSMOBJECT_H
3
4/*
5 Copyright (C) 2006 Nick Whitelegg, Hogweed Software, nick@hogweed.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
20
21 */
22
23#include <vector>
24#include <map>
25#include <string>
26
27// based on osmeditor2 code - changed qt stuff to std::b stuff
28
29namespace OSM
30{
31
32/**
33 * Superclass for OSM objects -- nodes, ways, relations. Provides a unique ID,
34 * a name and the ability to attach tags.
35 */
36class Object
37{
38protected:
39
40public:
41        /**
42         * Constructor
43         * @param id Object identifier, default is 0.
44         */
45        Object(int id = 0);
46
47        /**
48         * @return Object ID
49         */
50        int id() const;
51
52        /**
53         * Set a new object ID
54         * @param id New ID to store
55         */
56        void setId(int id);
57
58        /**
59         * Object name mutator
60         * @param name New object name
61         */
62        void setName(const std::string& name);
63
64        /**
65         * Object name accessor
66         * @return Name of the object
67         */
68        std::string getName();
69
70        /**
71         * @return True iff the ID is positive
72         * @todo FIXME: this method looks like a hack
73         */
74        bool isFromOSM();
75
76        /**
77         * Add a tag to the object
78         * @param key Tag key
79         * @param value Tag value
80         */
81        void addTag(std::string key, std::string value);
82
83        /**
84         * Accessor for the value of the tag with the given key
85         * @param key Tag key of the tag to query
86         * @return Value of the tag with the given key
87         */
88        std::string getTag(const std::string& key);
89
90        /**
91         * @return All tag keys attached to this object
92         */
93        std::vector<std::string> getTags();
94
95        /**
96         * @return True if this object contains at least one tag
97         */
98        bool hasTags() const;
99
100        /**
101         * Writes an OSM xml representation of all tags attached to this object
102         * to the given stream
103         * @param strm Stream to write xml representation of the tags to
104         */
105        void tagsToXML(std::ostream &strm);
106
107        /**
108         * @return All key/value pairs of the tags attached to this object
109         */
110        std::map<std::string, std::string> const &tags() const;
111
112private:
113        /** Object ID */
114        int m_id;
115
116        /** Tags attached to this object */
117        std::map<std::string, std::string> m_tags;
118};
119
120}
121
122#endif
Note: See TracBrowser for help on using the repository browser.