GEOS 3.11.1
geomgraph/NodeMap.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: geomgraph/NodeMap.java rev. 1.3 (JTS-1.10)
17 *
18 **********************************************************************/
19
20
21#pragma once
22
23#include <geos/export.h>
24#include <map>
25#include <vector>
26#include <string>
27
28#include <geos/geom/Coordinate.h> // for CoordinateLessThen
29#include <geos/geomgraph/Node.h> // for testInvariant
30
31
32#ifdef _MSC_VER
33#pragma warning(push)
34#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35#endif
36
37// Forward declarations
38namespace geos {
39namespace geomgraph {
40class Node;
41class EdgeEnd;
42class NodeFactory;
43}
44}
45
46namespace geos {
47namespace geomgraph { // geos.geomgraph
48
49class GEOS_DLL NodeMap {
50public:
51
52 typedef std::map<geom::Coordinate*, Node*, geom::CoordinateLessThen> container;
53
54 typedef container::iterator iterator;
55
56 typedef container::const_iterator const_iterator;
57
58 typedef std::pair<geom::Coordinate*, Node*> pair;
59
60 container nodeMap;
61
62 const NodeFactory& nodeFact;
63
67 NodeMap(const NodeFactory& newNodeFact);
68
69 virtual ~NodeMap();
70
71 Node* addNode(const geom::Coordinate& coord);
72
73 Node* addNode(Node* n);
74
75 void add(EdgeEnd* e);
76
77 Node* find(const geom::Coordinate& coord) const;
78
79 const_iterator
80 begin() const
81 {
82 return nodeMap.begin();
83 }
84
85 const_iterator
86 end() const
87 {
88 return nodeMap.end();
89 }
90
91 iterator
92 begin()
93 {
94 return nodeMap.begin();
95 }
96
97 iterator
98 end()
99 {
100 return nodeMap.end();
101 }
102
103 void getBoundaryNodes(uint8_t geomIndex,
104 std::vector<Node*>& bdyNodes) const;
105
106 std::string print() const;
107
108 void
109 testInvariant()
110 {
111#ifndef NDEBUG
112 // Each Coordinate key is a pointer inside the Node value
113 for(iterator it = begin(), itEnd = end(); it != itEnd; ++it) {
114 pair p = *it;
115 geomgraph::Node* n = p.second;
116 geom::Coordinate* c = const_cast<geom::Coordinate*>(
117 &(n->getCoordinate())
118 );
119 assert(p.first == c);
120 }
121#endif
122 }
123
124private:
125
126 // Declare type as noncopyable
127 NodeMap(const NodeMap& other) = delete;
128 NodeMap& operator=(const NodeMap& rhs) = delete;
129};
130
131} // namespace geos.geomgraph
132} // namespace geos
133
134#ifdef _MSC_VER
135#pragma warning(pop)
136#endif
137
Basic namespace for all GEOS functionalities.
Definition: geos.h:39