Main Page
Namespaces
Classes
Package Documentation
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
src
Utilities
General
interface
own_ptr.h
Go to the documentation of this file.
1
#ifndef UTILITIES_GENERAL_OWN_PTR_H
2
#define UTILITIES_GENERAL_OWN_PTR_H
3
//
4
// a pointer which "owns" the pointed object
5
// similar to std auto_ptr but does allow standard copy constructor
6
// that passes ownership when copied
7
// lost ownership = zero pointer (safer...)
8
//
9
10
//
11
// Version 1.0 V.I. 6/4/99
12
// Version 2.0 V.I. 23/4/2001
13
// Version 3.0 V.I. 29/1/2004
14
// policies introduced...
15
//
16
17
namespace
OwnerPolicy {
18
struct
Transfer
{
19
template
<
class
X>
static
X
*
copy
(
X
* &
p
) {
X
* it=
p
; p=0;
return
it;}
20
template
<
class
X>
static
void
remove
(
X
*
p
) {
delete
p
;}
21
};
22
struct
Copy
{
23
template
<
class
X>
static
X
*
copy
(
X
*
p
) {
return
(p) ?
new
X
(*p) : 0;}
24
template
<
class
X>
static
void
remove
(
X
*
p
) {
delete
p
;}
25
};
26
struct
Clone
{
27
template
<
class
X>
static
X
*
copy
(
X
*
p
) {
return
(p) ? (*p).clone() : 0;}
28
template
<
class
X>
static
void
remove
(
X
*
p
) {
delete
p
;}
29
};
30
struct
Replica
{
31
template
<
class
X>
static
X
*
copy
(
X
*
p
) {
return
(p) ? (*p).replica() : 0;}
32
template
<
class
X>
static
void
remove
(
X
*
p
) {
delete
p
;}
33
};
34
}
35
36
39
template
<
class
X,
typename
P=OwnerPolicy::Transfer>
class
own_ptr
{
40
private
:
41
X
*
ptr
;
42
public
:
43
typedef
X
element_type
;
45
explicit
own_ptr
(
X
*
p
= 0) :
ptr
(
p
) {}
46
48
own_ptr
(
const
own_ptr
&
a
) :
ptr
(a.
release
()) {}
49
50
#ifndef CMS_NO_TEMPLATE_MEMBERS
51
template
<
class
T,
typename
Q>
own_ptr
(
const
own_ptr<T,Q>
&
a
)
53
:
ptr
(a.
release
()) {}
54
#endif
55
own_ptr
&
operator=
(
const
own_ptr
&
a
) {
57
if
(a.
get
() !=
ptr
) {
58
P::remove
(
ptr
);
59
ptr
= a.
release
();
60
}
61
return
*
this
;
62
}
63
64
#ifndef CMS_NO_TEMPLATE_MEMBERS
65
template
<
class
T,
typename
Q>
own_ptr
&
operator=
(
const
own_ptr<T,Q>
& a) {
67
if
(a.
get
() !=
ptr
) {
68
P::remove
(
ptr
);
69
ptr
= a.
release
();
70
}
71
return
*
this
;
72
}
73
#endif
74
~own_ptr
() {
76
P::remove
(
ptr
);
77
}
79
X
&
operator*
()
const
{
return
*
ptr
; }
81
X
*
operator->
()
const
{
return
ptr
; }
83
X
*
get
()
const
{
return
ptr
; }
85
X
*
release
()
const
{
86
return
P::copy
(
const_cast<
own_ptr<X,P>
*
>
(
this
)->
ptr
);
87
}
88
90
void
reset
(
X
*
p
= 0) {
91
if
(
p
!=
ptr
) {
92
P::remove
(
ptr
);
93
ptr
=
p
;
94
}
95
}
96
};
97
98
#endif // UTILITIES_GENERAL_OWN_PTR_H
own_ptr::operator=
own_ptr & operator=(const own_ptr &a)
Definition:
own_ptr.h:56
own_ptr::get
X * get() const
Definition:
own_ptr.h:83
OwnerPolicy::Copy
Definition:
own_ptr.h:22
own_ptr::own_ptr
own_ptr(const own_ptr &a)
Definition:
own_ptr.h:48
own_ptr::release
X * release() const
Definition:
own_ptr.h:85
OwnerPolicy::Copy::copy
static X * copy(X *p)
Definition:
own_ptr.h:23
own_ptr::element_type
X element_type
Definition:
own_ptr.h:43
X
#define X(str)
Definition:
MuonsGrabber.cc:48
own_ptr::own_ptr
own_ptr(X *p=0)
Definition:
own_ptr.h:45
OwnerPolicy::Clone::copy
static X * copy(X *p)
Definition:
own_ptr.h:27
OwnerPolicy::Clone
Definition:
own_ptr.h:26
OwnerPolicy::Replica
Definition:
own_ptr.h:30
own_ptr
Definition:
own_ptr.h:39
own_ptr::~own_ptr
~own_ptr()
Definition:
own_ptr.h:75
filterCSVwithJSON.copy
tuple copy
Definition:
filterCSVwithJSON.py:35
own_ptr::reset
void reset(X *p=0)
Definition:
own_ptr.h:90
own_ptr::operator*
X & operator*() const
Definition:
own_ptr.h:79
OwnerPolicy::Replica::copy
static X * copy(X *p)
Definition:
own_ptr.h:31
AlCaHLTBitMon_ParallelJobs.p
tuple p
Definition:
AlCaHLTBitMon_ParallelJobs.py:152
a
double a
Definition:
hdecay.h:121
OwnerPolicy::Transfer::copy
static X * copy(X *&p)
Definition:
own_ptr.h:19
python.multivaluedict.remove
def remove
Definition:
multivaluedict.py:155
own_ptr::operator->
X * operator->() const
Definition:
own_ptr.h:81
OwnerPolicy::Transfer
Definition:
own_ptr.h:18
own_ptr::ptr
X * ptr
Definition:
own_ptr.h:41
Generated for CMSSW Reference Manual by
1.8.5