GEOS  3.9.1dev
AbstractNode.h
Go to the documentation of this file.
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 
30 namespace geos {
31 namespace index { // geos::index
32 namespace strtree { // geos::index::strtree
33 
45 private:
46  std::vector<Boundable*> childBoundables;
47  int level;
48 public:
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*>*
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*>*
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 
117 protected:
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
#define GEOS_DLL
Definition: export.h:28
std::vector< Boundable * > childBoundables
Definition: AbstractNode.h:46
const void * getBounds() const override
Definition: AbstractNode.h:89
void addChildBoundable(Boundable *childBoundable)
Definition: AbstractNode.h:108
std::vector< Boundable * > * getChildBoundables()
Definition: AbstractNode.h:64
bool isLeaf() const override
Definition: AbstractNode.h:113
AbstractNode(int newLevel, size_t capacity=10)
Definition: AbstractNode.h:55
Basic namespace for all GEOS functionalities.
A node of the STR tree.
Definition: AbstractNode.h:44
A spatial object in an AbstractSTRtree.
Definition: Boundable.h:25
const std::vector< Boundable * > * getChildBoundables() const
Definition: AbstractNode.h:72