GEOS 3.11.1
AbstractNode.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2006 Refractions Research Inc.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <cassert>
18#include <cstddef>
19#include <geos/export.h>
20#include <geos/index/strtree/Boundable.h> // for inheritance
21
22#include <vector>
23
24#ifdef _MSC_VER
25#pragma warning(push)
26#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
27#endif
28
29namespace geos {
30namespace index { // geos::index
31namespace strtree { // geos::index::strtree
32
43class GEOS_DLL AbstractNode: public Boundable {
44private:
45 std::vector<Boundable*> childBoundables;
46 int level;
47public:
48
49 /*
50 * Constructs an AbstractNode at the given level in the tree
51 * @param level 0 if this node is a leaf, 1 if a parent of a leaf, and so on;
52 * the root node will have the highest level
53 */
54 AbstractNode(int newLevel, std::size_t capacity = 10) : level(newLevel), bounds(nullptr) {
55 childBoundables.reserve(capacity);
56 }
57
58 ~AbstractNode() override = default;
59
60 // TODO: change signature to return by ref,
61 // document ownership of the return
62 inline std::vector<Boundable*>*
63 getChildBoundables()
64 {
65 return &childBoundables;
66 }
67
68 // TODO: change signature to return by ref,
69 // document ownership of the return
70 inline const std::vector<Boundable*>*
71 getChildBoundables() const
72 {
73 return &childBoundables;
74 }
75
88 const void* getBounds() const override {
89 if(bounds == nullptr) {
90 bounds = computeBounds();
91 }
92 return bounds;
93 }
94
99 int getLevel() {
100 return level;
101 }
102
107 void addChildBoundable(Boundable* childBoundable) {
108 assert(bounds == nullptr);
109 childBoundables.push_back(childBoundable);
110 }
111
112 bool isLeaf() const override {
113 return false;
114 }
115
116protected:
117
118 virtual void* computeBounds() const = 0;
119
120 mutable void* bounds;
121};
122
123
124} // namespace geos::index::strtree
125} // namespace geos::index
126} // namespace geos
127
128#ifdef _MSC_VER
129#pragma warning(pop)
130#endif
131
A node of the STR tree.
Definition: AbstractNode.h:43
int getLevel()
Definition: AbstractNode.h:99
void addChildBoundable(Boundable *childBoundable)
Definition: AbstractNode.h:107
const void * getBounds() const override
Definition: AbstractNode.h:88
A spatial object in an AbstractSTRtree.
Definition: Boundable.h:24
Basic namespace for all GEOS functionalities.
Definition: geos.h:39