GEOS  3.13.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 <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
39 namespace geos {
40 namespace geomgraph {
41 class Node;
42 class EdgeEnd;
43 class NodeFactory;
44 }
45 }
46 
47 namespace geos {
48 namespace geomgraph { // geos.geomgraph
49 
50 class GEOS_DLL NodeMap final {
51 public:
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  Node* addNode(const geom::Coordinate& coord);
69 
70  Node* addNode(Node* n);
71 
79  void add(EdgeEnd* e);
80 
81  void add(std::unique_ptr<EdgeEnd>&& e);
82 
83  Node* find(const geom::Coordinate& coord) const;
84 
85  const_iterator
86  begin() const
87  {
88  return nodeMap.begin();
89  }
90 
91  const_iterator
92  end() const
93  {
94  return nodeMap.end();
95  }
96 
97  iterator
98  begin()
99  {
100  return nodeMap.begin();
101  }
102 
103  iterator
104  end()
105  {
106  return nodeMap.end();
107  }
108 
109  void getBoundaryNodes(uint8_t geomIndex,
110  std::vector<Node*>& bdyNodes) const;
111 
112  std::string print() const;
113 
114  void
115  testInvariant()
116  {
117 #ifndef NDEBUG
118  // Each Coordinate key is a pointer inside the Node value
119  for(const auto& nodeIt: nodeMap) {
120  const auto* n = nodeIt.second.get();
121  geom::Coordinate* c = const_cast<geom::Coordinate*>(
122  &(n->getCoordinate())
123  );
124  assert(nodeIt.first == c);
125  (void)c;
126  }
127 #endif
128  }
129 
130 private:
131 
132  // Declare type as noncopyable
133  NodeMap(const NodeMap& other) = delete;
134  NodeMap& operator=(const NodeMap& rhs) = delete;
135 };
136 
137 } // namespace geos.geomgraph
138 } // namespace geos
139 
140 #ifdef _MSC_VER
141 #pragma warning(pop)
142 #endif
143 
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25