Coverage Report

Created: 2026-02-14 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/geomgraph/NodeMap.h
Line
Count
Source
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
63
    /// \brief
64
    /// NodeMap will keep a reference to the NodeFactory,
65
    /// keep it alive for the whole NodeMap lifetime
66
    NodeMap(const NodeFactory& newNodeFact);
67
68
    Node* addNode(const geom::Coordinate& coord);
69
70
    Node* addNode(Node* n);
71
72
    /// \brief
73
    /// Adds a node for the start point of this EdgeEnd
74
    /// (if one does not already exist in this map).
75
    /// Adds the EdgeEnd to the (possibly new) node.
76
    ///
77
    /// If ownership of the EdgeEnd should be transferred
78
    /// to the Node, use the unique_ptr overload instead.
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
0
    {
88
0
        return nodeMap.begin();
89
0
    }
90
91
    const_iterator
92
    end() const
93
0
    {
94
0
        return nodeMap.end();
95
0
    }
96
97
    iterator
98
    begin()
99
0
    {
100
0
        return nodeMap.begin();
101
0
    }
102
103
    iterator
104
    end()
105
0
    {
106
0
        return nodeMap.end();
107
0
    }
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
0
    {
117
0
#ifndef NDEBUG
118
0
        // Each Coordinate key is a pointer inside the Node value
119
0
        for(const auto& nodeIt: nodeMap) {
120
0
            const auto* n = nodeIt.second.get();
121
0
            geom::Coordinate* c = const_cast<geom::Coordinate*>(
122
0
                                      &(n->getCoordinate())
123
0
                                  );
124
0
            assert(nodeIt.first == c);
125
0
            (void)c;
126
0
        }
127
0
#endif
128
0
    }
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