src
Main Page
Namespaces
Classes
Files
File List
File Members
util
smart_ptr.h
Go to the documentation of this file.
1
#ifndef _RE2C_UTIL_SMART_PTR_
2
#define _RE2C_UTIL_SMART_PTR_
3
4
namespace
re2c
5
{
6
7
template
<
class
T>
8
class
smart_ptr
9
{
10
private
:
11
T* ptr;
12
long
* count;
// shared number of owners
13
14
public
:
15
explicit
smart_ptr
(T* p=0)
16
: ptr(p), count(new long(1)) {}
17
18
smart_ptr
(
const
smart_ptr<T>
& p)
throw
()
19
: ptr(p.ptr), count(p.count)
20
{
21
++*count;
22
}
23
24
~smart_ptr
()
25
{
26
dispose();
27
}
28
29
smart_ptr<T>
&
operator=
(
const
smart_ptr<T>
& p)
30
{
31
if
(
this
!= &p)
32
{
33
dispose();
34
ptr = p.ptr;
35
count = p.count;
36
++*count;
37
}
38
return
*
this
;
39
}
40
41
T&
operator*
()
const
42
{
43
return
*ptr;
44
}
45
46
T*
operator->
()
const
47
{
48
return
ptr;
49
}
50
51
private
:
52
void
dispose()
53
{
54
if
(--*count == 0)
55
{
56
delete
count;
57
delete
ptr;
58
}
59
}
60
};
61
62
template
<
typename
T>
63
smart_ptr<T>
make_smart_ptr
(T* p)
64
{
65
return
smart_ptr<T>
(p);
66
}
67
}
68
69
#endif // _RE2C_UTIL_SMART_PTR_
re2c::smart_ptr
Definition:
smart_ptr.h:8
re2c::make_smart_ptr
smart_ptr< T > make_smart_ptr(T *p)
Definition:
smart_ptr.h:63
re2c::smart_ptr::operator=
smart_ptr< T > & operator=(const smart_ptr< T > &p)
Definition:
smart_ptr.h:29
re2c::smart_ptr::operator->
T * operator->() const
Definition:
smart_ptr.h:46
re2c::smart_ptr::operator*
T & operator*() const
Definition:
smart_ptr.h:41
re2c::smart_ptr::smart_ptr
smart_ptr(const smart_ptr< T > &p)
Definition:
smart_ptr.h:18
re2c::smart_ptr::smart_ptr
smart_ptr(T *p=0)
Definition:
smart_ptr.h:15
re2c
Definition:
bitmap.cc:10
re2c::smart_ptr::~smart_ptr
~smart_ptr()
Definition:
smart_ptr.h:24
Generated by
1.8.10