source: subversion/applications/lib/libosm/Components.h @ 34393

Last change on this file since 34393 was 11750, checked in by nienhueser, 11 years ago

Less accessors alter instance state, add const to reflect this.

File size: 4.8 KB
Line 
1/*
2 Copyright (C) 2005 Nick Whitelegg, Hogweed Software, nick@hogweed.org
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
17
18 */
19
20#ifndef FREEMAP_COMPONENT_H
21#define FREEMAP_COMPONENT_H
22
23#include "Node.h"
24#include "Way.h"
25#include "FeatureClassification.h"
26
27#include <map>
28#include <set>
29#include <utility>
30#include <vector>
31
32namespace OSM
33{
34
35/**
36 * Core components of OSM -- nodes, ways and relations
37 */
38class Components
39{
40public:
41        /** Constructor */
42        Components();
43
44        /** Destructor */
45        ~Components();
46
47        /**
48         * Toggle destructor behaviour regarding freeing memory
49         * @param enabled If true, nodes and ways will be deleted in the destructor.
50         * Otherwise the destructor frees nothing.
51         */
52        void setDestroyComponents(bool enabled);
53
54        /**
55         * Free memory consumed by nodes and ways
56         */
57        void destroy();
58
59        /**
60         * Add a new node to this Components instance
61         * @param node The node to add
62         * @return Node id after adding it. If the node passed in has an id of 0,
63         * a negative ID will be assigned and returned. Otherwise the original
64         * ID of the given node will be returned.
65         */
66        int addNode(Node *node);
67
68        /**
69         * Add a new way to this Components instance
70         * @param way The way to add
71         * @return Way id after adding it. If the way passed in has an id of 0,
72         * a negative ID will be assigned and returned. Otherwise the original
73         * ID of the given way will be returned.
74         */
75        int addWay(Way *w);
76
77        /**
78         * Accessor for the node with the given ID
79         * @param id Node id to search for
80         * @return The node with the given ID if existing in this Components instance, NULL otherwise
81         */
82        Node *getNode(int id) const;
83
84        /**
85         * Accessor for the way with the given ID
86         * @param id Way id to search for
87         * @return The way with the given ID if existing in this Components instance, NULL otherwise
88         */
89        Way *getWay(int id) const;
90
91        /**
92         * Accessor for the next node
93         * @return The next (as per ID) node, or NULL if at the end
94         */
95        Node *nextNode();
96
97        /**
98         * Accessor for the next way
99         * @return The next (as per ID) way, or NULL if at the end
100         */
101        Way *nextWay();
102
103        /**
104         * Set the node iterator to the beginning such that #nextNode will
105         * return the first node, if any.
106         */
107        void rewindNodes();
108
109        /**
110         * Set the way iterator to the beginning such that #nextWay will
111         * return the first way, if any.
112         */
113        void rewindWays();
114
115        /**
116         * @return True if the node iterator is not at the end
117         * @see rewindNodes
118         * @see nextNode
119         */
120        bool hasMoreNodes() const;
121
122        /**
123         * @return True if the way iterator is not at the end
124         * @see rewindWays
125         * @see nextWay
126         */
127        bool hasMoreWays() const;
128
129        /**
130         * Return a vector of the coordinates of all the points making up a way,
131         * in lon-lat order.
132         * @param id Way id to search for
133         * @return An empty vector if no way with the given ID is part of this
134         * Components instance, or a vector of size 2*n for a way of n nodes
135         * containing the lon/lat coordinates of all way nodes
136         */
137        std::vector<double> getWayCoords(int id) const;
138
139        /**
140         * Return a vector of all node IDs for the given way
141         * @param id Way ID
142         * @return A vector of all node IDs for the given way. The vector will be empty
143         * if the given way does not exist in this Components instance or has no
144         * nodes assigned to it
145         */
146        std::vector<int> getWayNodes(int id) const;
147
148        /**
149         * Returns the ID of the first way found containing the given node key
150         * @param id ID of the node to search for
151         * @return The ID of the first way found containing a node with the given key,
152         * or 0 if no such way can be found
153         */
154        int getParentWayOfNode(int id) const;
155
156        std::set<std::string> getWayTags(FeatureClassification* classification =
157                        NULL, bool doArea = false) const;
158
159        std::set<std::string> getNodeTags() const;
160
161        void toXML(std::ostream &strm);
162
163        void toOSGB();
164
165        bool makeShp(const std::string& nodes, const std::string& ways,
166                        const std::string&, const std::string&);
167
168        bool makeNodeShp(const std::string& shpname);
169
170        bool makeWayShp(const std::string &shpname, FeatureClassification*, bool =
171                        false);
172
173private:
174        std::map<int, Node*> nodes;
175        std::map<int, Way*> ways;
176        int nextNodeId, nextSegmentId, nextWayId;
177        bool destroyComponents;
178
179        std::map<int, Node*>::iterator nodeIterator;
180        std::map<int, Way*>::iterator wayIterator;
181};
182
183}
184
185#endif // FREEMAP_COMPONENT_H
Note: See TracBrowser for help on using the repository browser.