GEOS 3.9.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#ifndef GEOS_INDEX_STRTREE_ABSTRACTNODE_H
16#define GEOS_INDEX_STRTREE_ABSTRACTNODE_H
17
18#include <cassert>
19#include <cstddef>
20#include <geos/export.h>
21#include <geos/index/strtree/Boundable.h> // for inheritance
22
23#include <vector>
24
25#ifdef _MSC_VER
26#pragma warning(push)
27#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
28#endif
29
30namespace geos {
31namespace index { // geos::index
32namespace strtree { // geos::index::strtree
33
44class GEOS_DLL AbstractNode: public Boundable {
45private:
46 std::vector<Boundable*> childBoundables;
47 int level;
48public:
49
50 /*
51 * Constructs an AbstractNode at the given level in the tree
52 * @param level 0 if this node is a leaf, 1 if a parent of a leaf, and so on;
53 * the root node will have the highest level
54 */
55 AbstractNode(int newLevel, size_t capacity = 10) : level(newLevel), bounds(nullptr) {
56 childBoundables.reserve(capacity);
57 }
58
59 ~AbstractNode() override = default;
60
61 // TODO: change signature to return by ref,
62 // document ownership of the return
63 inline std::vector<Boundable*>*
64 getChildBoundables()
65 {
66 return &childBoundables;
67 }
68
69 // TODO: change signature to return by ref,
70 // document ownership of the return
71 inline const std::vector<Boundable*>*
72 getChildBoundables() const
73 {
74 return &childBoundables;
75 }
76
89 const void* getBounds() const override {
90 if(bounds == nullptr) {
91 bounds = computeBounds();
92 }
93 return bounds;
94 }
95
100 int getLevel() {
101 return level;
102 }
103
108 void addChildBoundable(Boundable* childBoundable) {
109 assert(bounds == nullptr);
110 childBoundables.push_back(childBoundable);
111 }
112
113 bool isLeaf() const override {
114 return false;
115 }
116
117protected:
118
119 virtual void* computeBounds() const = 0;
120
121 mutable void* bounds;
122};
123
124
125} // namespace geos::index::strtree
126} // namespace geos::index
127} // namespace geos
128
129#ifdef _MSC_VER
130#pragma warning(pop)
131#endif
132
133#endif // GEOS_INDEX_STRTREE_ABSTRACTNODE_H
A node of the STR tree.
Definition: AbstractNode.h:44
int getLevel()
Definition: AbstractNode.h:100
void addChildBoundable(Boundable *childBoundable)
Definition: AbstractNode.h:108
const void * getBounds() const override
Definition: AbstractNode.h:89
A spatial object in an AbstractSTRtree.
Definition: Boundable.h:25
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26