GEOS  3.6.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 #ifndef GEOS_GEOMGRAPH_NODEMAP_H
22 #define GEOS_GEOMGRAPH_NODEMAP_H
23 
24 #include <geos/export.h>
25 #include <map>
26 #include <vector>
27 #include <string>
28 
29 #include <geos/geom/Coordinate.h> // for CoordinateLessThen
30 #include <geos/geomgraph/Node.h> // for testInvariant
31 
32 #include <geos/inline.h>
33 
34 #ifdef _MSC_VER
35 #pragma warning(push)
36 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
37 #endif
38 
39 // Forward declarations
40 namespace geos {
41  namespace geomgraph {
42  class Node;
43  class EdgeEnd;
44  class NodeFactory;
45  }
46 }
47 
48 namespace geos {
49 namespace geomgraph { // geos.geomgraph
50 
51 class GEOS_DLL NodeMap{
52 public:
53 
54  typedef std::map<geom::Coordinate*,Node*,geom::CoordinateLessThen> container;
55 
56  typedef container::iterator iterator;
57 
58  typedef container::const_iterator const_iterator;
59 
60  typedef std::pair<geom::Coordinate*,Node*> pair;
61 
62  container nodeMap;
63 
64  const NodeFactory &nodeFact;
65 
69  NodeMap(const NodeFactory &newNodeFact);
70 
71  virtual ~NodeMap();
72 
73  Node* addNode(const geom::Coordinate& coord);
74 
75  Node* addNode(Node *n);
76 
77  void add(EdgeEnd *e);
78 
79  Node *find(const geom::Coordinate& coord) const;
80 
81  const_iterator begin() const { return nodeMap.begin(); }
82 
83  const_iterator end() const { return nodeMap.end(); }
84 
85  iterator begin() { return nodeMap.begin(); }
86 
87  iterator end() { return nodeMap.end(); }
88 
89  void getBoundaryNodes(int geomIndex,
90  std::vector<Node*>&bdyNodes) const;
91 
92  std::string print() const;
93 
94  void testInvariant()
95  {
96 #ifndef NDEBUG
97  // Each Coordinate key is a pointer inside the Node value
98  for (iterator it=begin(), itEnd=end(); it != itEnd; ++it)
99  {
100  pair p = *it;
101  geomgraph::Node* n = p.second;
102  geom::Coordinate* c = const_cast<geom::Coordinate*>(
103  &(n->getCoordinate())
104  );
105  assert(p.first == c);
106  }
107 #endif
108  }
109 
110 private:
111 
112  // Declare type as noncopyable
113  NodeMap(const NodeMap& other);
114  NodeMap& operator=(const NodeMap& rhs);
115 };
116 
117 } // namespace geos.geomgraph
118 } // namespace geos
119 
120 #ifdef _MSC_VER
121 #pragma warning(pop)
122 #endif
123 
124 #endif // ifndef GEOS_GEOMGRAPH_NODEMAP_H
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25