GEOS 3.12.0
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 <memory>
26#include <vector>
27#include <string>
28
29#include <geos/geom/Coordinate.h> // for CoordinateLessThan
30#include <geos/geomgraph/Node.h> // for testInvariant
31
32
33#ifdef _MSC_VER
34#pragma warning(push)
35#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36#endif
37
38// Forward declarations
39namespace geos {
40namespace geomgraph {
41class Node;
42class EdgeEnd;
43class NodeFactory;
44}
45}
46
47namespace geos {
48namespace geomgraph { // geos.geomgraph
49
50class GEOS_DLL NodeMap {
51public:
52
53 typedef std::map<geom::Coordinate*, std::unique_ptr<Node>, geom::CoordinateLessThan> container;
54
55 typedef container::iterator iterator;
56
57 typedef container::const_iterator const_iterator;
58
59 container nodeMap;
60
61 const NodeFactory& nodeFact;
62
66 NodeMap(const NodeFactory& newNodeFact);
67
68 virtual ~NodeMap();
69
70 Node* addNode(const geom::Coordinate& coord);
71
72 Node* addNode(Node* n);
73
81 void add(EdgeEnd* e);
82
83 void add(std::unique_ptr<EdgeEnd>&& e);
84
85 Node* find(const geom::Coordinate& coord) const;
86
87 const_iterator
88 begin() const
89 {
90 return nodeMap.begin();
91 }
92
93 const_iterator
94 end() const
95 {
96 return nodeMap.end();
97 }
98
99 iterator
100 begin()
101 {
102 return nodeMap.begin();
103 }
104
105 iterator
106 end()
107 {
108 return nodeMap.end();
109 }
110
111 void getBoundaryNodes(uint8_t geomIndex,
112 std::vector<Node*>& bdyNodes) const;
113
114 std::string print() const;
115
116 void
117 testInvariant()
118 {
119#ifndef NDEBUG
120 // Each Coordinate key is a pointer inside the Node value
121 for(const auto& nodeIt: nodeMap) {
122 const auto* n = nodeIt.second.get();
123 geom::Coordinate* c = const_cast<geom::Coordinate*>(
124 &(n->getCoordinate())
125 );
126 assert(nodeIt.first == c);
127 (void)c;
128 }
129#endif
130 }
131
132private:
133
134 // Declare type as noncopyable
135 NodeMap(const NodeMap& other) = delete;
136 NodeMap& operator=(const NodeMap& rhs) = delete;
137};
138
139} // namespace geos.geomgraph
140} // namespace geos
141
142#ifdef _MSC_VER
143#pragma warning(pop)
144#endif
145
Basic namespace for all GEOS functionalities.
Definition geos.h:39