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