Main Page
Namespaces
Classes
Files
File List
File Members
include
gmapping
utils
autoptr.h
Go to the documentation of this file.
1
#ifndef AUTOPTR_H
2
#define AUTOPTR_H
3
#include <assert.h>
4
5
namespace
GMapping
{
6
7
template
<
class
X>
8
class
autoptr
{
9
protected
:
10
11
public
:
12
struct
reference
{
13
X*
data
;
14
unsigned
int
shares
;
15
};
16
inline
autoptr
(X* p=(X*)(0));
17
inline
autoptr
(
const
autoptr<X>
& ap);
18
inline
autoptr
&
operator=
(
const
autoptr<X>
& ap);
19
inline
~autoptr
();
20
inline
operator
int()
const
;
21
inline
X&
operator*
();
22
inline
const
X&
operator*
()
const
;
23
//p
24
reference *
m_reference
;
25
protected
:
26
};
27
28
template
<
class
X>
29
autoptr<X>::autoptr
(X* p){
30
m_reference
=0;
31
if
(p){
32
m_reference
=
new
reference
;
33
m_reference
->
data
=p;
34
m_reference
->
shares
=1;
35
}
36
}
37
38
template
<
class
X>
39
autoptr<X>::autoptr
(
const
autoptr<X>
& ap){
40
m_reference
=0;
41
reference
* ref=ap.
m_reference
;
42
if
(ap.
m_reference
){
43
m_reference
=ref;
44
m_reference
->
shares
++;
45
}
46
}
47
48
template
<
class
X>
49
autoptr<X>
&
autoptr<X>::operator=
(
const
autoptr<X>
& ap){
50
reference
* ref=ap.
m_reference
;
51
if
(
m_reference
==ref){
52
return
*
this
;
53
}
54
if
(
m_reference
&& !(--
m_reference
->
shares
)){
55
delete
m_reference
->
data
;
56
delete
m_reference
;
57
m_reference
=0;
58
}
59
if
(ref){
60
m_reference
=ref;
61
m_reference
->
shares
++;
62
}
63
//20050802 nasty changes begin
64
else
65
m_reference
=0;
66
//20050802 nasty changes end
67
return
*
this
;
68
}
69
70
template
<
class
X>
71
autoptr<X>::~autoptr
(){
72
if
(
m_reference
&& !(--
m_reference
->
shares
)){
73
delete
m_reference
->
data
;
74
delete
m_reference
;
75
m_reference
=0;
76
}
77
}
78
79
template
<
class
X>
80
autoptr<X>::operator
int()
const
{
81
return
m_reference
&&
m_reference
->
shares
&&
m_reference
->
data
;
82
}
83
84
template
<
class
X>
85
X&
autoptr<X>::operator*
(){
86
assert(
m_reference
&&
m_reference
->
shares
&&
m_reference
->
data
);
87
return
*(
m_reference
->
data
);
88
}
89
90
template
<
class
X>
91
const
X&
autoptr<X>::operator*
()
const
{
92
assert(
m_reference
&&
m_reference
->
shares
&&
m_reference
->
data
);
93
return
*(
m_reference
->
data
);
94
}
95
96
};
97
#endif
GMapping::autoptr::m_reference
reference * m_reference
Definition:
autoptr.h:24
GMapping::autoptr::~autoptr
~autoptr()
Definition:
autoptr.h:71
GMapping::autoptr::operator=
autoptr & operator=(const autoptr< X > &ap)
Definition:
autoptr.h:49
GMapping::autoptr::reference::shares
unsigned int shares
Definition:
autoptr.h:14
GMapping::autoptr::autoptr
autoptr(X *p=(X *)(0))
Definition:
autoptr.h:29
GMapping
Definition:
carmenwrapper.h:40
GMapping::autoptr
Definition:
autoptr.h:8
GMapping::autoptr::reference::data
X * data
Definition:
autoptr.h:13
GMapping::autoptr::reference
Definition:
autoptr.h:12
GMapping::autoptr::operator*
X & operator*()
Definition:
autoptr.h:85
openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Mon Jun 10 2019 14:04:22