QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
PoolPointer.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) 2004, 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 "
PointerPool.h
"
31
32
namespace
Tools
33
{
34
template
<
class
X>
class
PointerPool;
35
36
template
<
class
X>
class
PoolPointer
37
{
38
public
:
39
explicit
PoolPointer
(X* p = 0) :
m_pointer
(p),
m_pPool
(0) {
m_prev
=
m_next
=
this
; }
40
explicit
PoolPointer
(X* p,
PointerPool<X>
* pPool)
throw
() :
m_pointer
(p),
m_pPool
(pPool) {
m_prev
=
m_next
=
this
; }
41
~PoolPointer
() {
release
(); }
42
PoolPointer
(
const
PoolPointer
& p)
throw
() {
acquire
(p); }
43
PoolPointer
&
operator=
(
const
PoolPointer
& p)
44
{
45
if
(
this
!= &p)
46
{
47
release
();
48
acquire
(p);
49
}
50
return
*
this
;
51
}
52
53
X&
operator*
()
const
throw() {
return
*
m_pointer
; }
54
X*
operator->
()
const
throw() {
return
m_pointer
; }
55
X*
get
()
const
throw() {
return
m_pointer
; }
56
bool
unique
()
const
throw() {
return
m_prev
?
m_prev
== this :
true
; }
57
void
relinquish
() throw()
58
{
59
m_pPool
= 0;
60
m_pointer
= 0;
61
release
();
62
}
63
64
private
:
65
X*
m_pointer
;
66
mutable
const
PoolPointer
*
m_prev
;
67
mutable
const
PoolPointer
*
m_next
;
68
PointerPool<X>
*
m_pPool
;
69
70
void
acquire
(
const
PoolPointer
& p)
throw
()
71
{
72
m_pPool
= p.m_pPool;
73
m_pointer
= p.m_pointer;
74
m_next
= p.
m_next
;
75
m_next
->
m_prev
=
this
;
76
m_prev
= &p;
77
#ifndef mutable
78
p.
m_next
=
this
;
79
#else
80
(
const_cast<
linked_ptr<X>*
>
(&p))->
m_next
=
this
;
81
#endif
82
}
83
84
void
release
()
85
{
86
if
(
unique
())
87
{
88
if
(
m_pPool
!= 0)
m_pPool
->release(
m_pointer
);
89
else
delete
m_pointer
;
90
}
91
else
92
{
93
m_prev
->
m_next
=
m_next
;
94
m_next
->
m_prev
=
m_prev
;
95
m_prev
=
m_next
= 0;
96
}
97
m_pointer
= 0;
98
m_pPool
= 0;
99
}
100
};
101
}
102
PointerPool.h
Tools::PointerPool
Definition
PointerPool.h:35
Tools::PoolPointer
Definition
PoolPointer.h:37
Tools::PoolPointer::operator->
X * operator->() const
Definition
PoolPointer.h:54
Tools::PoolPointer::relinquish
void relinquish()
Definition
PoolPointer.h:57
Tools::PoolPointer::operator=
PoolPointer & operator=(const PoolPointer &p)
Definition
PoolPointer.h:43
Tools::PoolPointer::m_pPool
PointerPool< X > * m_pPool
Definition
PoolPointer.h:68
Tools::PoolPointer::unique
bool unique() const
Definition
PoolPointer.h:56
Tools::PoolPointer::release
void release()
Definition
PoolPointer.h:84
Tools::PoolPointer::m_pointer
X * m_pointer
Definition
PoolPointer.h:65
Tools::PoolPointer::PoolPointer
PoolPointer(const PoolPointer &p)
Definition
PoolPointer.h:42
Tools::PoolPointer::get
X * get() const
Definition
PoolPointer.h:55
Tools::PoolPointer::m_prev
const PoolPointer * m_prev
Definition
PoolPointer.h:66
Tools::PoolPointer::~PoolPointer
~PoolPointer()
Definition
PoolPointer.h:41
Tools::PoolPointer::operator*
X & operator*() const
Definition
PoolPointer.h:53
Tools::PoolPointer::m_next
const PoolPointer * m_next
Definition
PoolPointer.h:67
Tools::PoolPointer::acquire
void acquire(const PoolPointer &p)
Definition
PoolPointer.h:70
Tools::PoolPointer::PoolPointer
PoolPointer(X *p=0)
Definition
PoolPointer.h:39
Tools::PoolPointer::PoolPointer
PoolPointer(X *p, PointerPool< X > *pPool)
Definition
PoolPointer.h:40
Tools
Definition
PointerPool.h:33
src
3rdparty
legacy
spatialindexnavel
include
spatialindex
tools
PoolPointer.h
Generated on Fri Jul 18 2025 09:41:50 for QCAD by
1.10.0