QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
PointerPoolNode.h
Go to the documentation of this file.
1/******************************************************************************
2 * Project: libspatialindex - A C++ library for spatial indexing
3 * Author: Marios Hadjieleftheriou, [email protected]
4 ******************************************************************************
5 * Copyright (c) 2002, Marios Hadjieleftheriou
6 *
7 * All rights reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26******************************************************************************/
27
28#pragma once
29
30#include "Node.h"
31
32namespace Tools
33{
35 {
36 public:
37 explicit PointerPool(uint32_t capacity) : m_capacity(capacity)
38 {
39 #ifndef NDEBUG
40 m_hits = 0;
41 m_misses = 0;
43 #endif
44 }
45
47 {
48 assert(m_pool.size() <= m_capacity);
49
50 while (! m_pool.empty())
51 {
53 #ifndef NDEBUG
55 #endif
56 delete x;
57 }
58
59 #ifndef NDEBUG
60 std::cerr << "Lost pointers: " << m_pointerCount << std::endl;
61 #endif
62 }
63
65 {
66 if (! m_pool.empty())
67 {
69 #ifndef NDEBUG
70 ++m_hits;
71 #endif
72
74 }
75 #ifndef NDEBUG
76 else
77 {
78 // fixme: well sort of...
80 ++m_misses;
81 }
82 #endif
83
85 }
86
88 {
89 if (p != 0)
90 {
91 if (m_pool.size() < m_capacity)
92 {
93 if (p->m_pData != 0)
94 {
95 for (uint32_t cChild = 0; cChild < p->m_children; ++cChild)
96 {
97 if (p->m_pData[cChild] != 0) delete[] p->m_pData[cChild];
98 }
99 }
100
101 p->m_level = 0;
102 p->m_identifier = -1;
103 p->m_children = 0;
104 p->m_totalDataLength = 0;
105
106 m_pool.push(p);
107 }
108 else
109 {
110 #ifndef NDEBUG
112 #endif
113 delete p;
114 }
115
116 assert(m_pool.size() <= m_capacity);
117 }
118 }
119
120 uint32_t getCapacity() const { return m_capacity; }
121 void setCapacity(uint32_t c)
122 {
123 assert (c >= 0);
124 m_capacity = c;
125 }
126
127 protected:
128 uint32_t m_capacity;
129 std::stack<SpatialIndex::MVRTree::Node*> m_pool;
130
131 #ifndef NDEBUG
132 public:
133 uint64_t m_hits;
134 uint64_t m_misses;
136 #endif
137 };
138}
139
Definition Node.h:42
id_type m_identifier
Definition Node.h:114
uint32_t m_children
Definition Node.h:117
byte ** m_pData
Definition Node.h:126
uint32_t m_level
Definition Node.h:110
uint32_t m_totalDataLength
Definition Node.h:137
PointerPool(uint32_t capacity)
Definition PointerPoolNode.h:37
uint32_t m_capacity
Definition PointerPoolNode.h:128
PoolPointer< SpatialIndex::MVRTree::Node > acquire()
Definition PointerPoolNode.h:64
uint64_t m_pointerCount
Definition PointerPoolNode.h:135
void setCapacity(uint32_t c)
Definition PointerPoolNode.h:121
uint64_t m_misses
Definition PointerPoolNode.h:134
~PointerPool()
Definition PointerPoolNode.h:46
std::stack< SpatialIndex::MVRTree::Node * > m_pool
Definition PointerPoolNode.h:129
uint64_t m_hits
Definition PointerPoolNode.h:133
void release(SpatialIndex::MVRTree::Node *p)
Definition PointerPoolNode.h:87
uint32_t getCapacity() const
Definition PointerPoolNode.h:120
Definition PointerPool.h:35
uint32_t m_capacity
Definition PointerPool.h:112
uint64_t m_hits
Definition PointerPool.h:117
uint64_t m_pointerCount
Definition PointerPool.h:119
std::stack< X * > m_pool
Definition PointerPool.h:113
uint64_t m_misses
Definition PointerPool.h:118
Definition PoolPointer.h:37
Definition CustomStorage.h:34
Definition PointerPool.h:33