CppCMS
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
booster
hold_ptr.h
1
//
2
// Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
3
//
4
// Distributed under the Boost Software License, Version 1.0. (See
5
// accompanying file LICENSE_1_0.txt or copy at
6
// http://www.boost.org/LICENSE_1_0.txt)
7
//
8
#ifndef BOOSTER_HOLD_PTR_H
9
#define BOOSTER_HOLD_PTR_H
10
11
namespace
booster {
12
17
template
<
typename
T>
18
class
hold_ptr
{
19
T *ptr_;
20
hold_ptr
(
hold_ptr
const
&other);
// non copyable
21
hold_ptr
const
&operator=(
hold_ptr
const
&other);
// non assignable
22
public
:
23
hold_ptr
() : ptr_(0) {}
24
explicit
hold_ptr
(T *v) : ptr_(v) {}
25
~
hold_ptr
()
26
{
27
if
(ptr_)
delete
ptr_;
28
}
29
30
T
const
*
get
()
const
{
return
ptr_; }
31
T *
get
() {
return
ptr_; }
32
33
T
const
&operator *()
const
{
return
*ptr_; }
34
T &operator *() {
return
*ptr_; }
35
T
const
*operator->()
const
{
return
ptr_; }
36
T *operator->() {
return
ptr_; }
37
T *release() { T *tmp=ptr_; ptr_=0;
return
tmp; }
38
void
reset(T *p=0)
39
{
40
if
(ptr_)
delete
ptr_;
41
ptr_=p;
42
}
43
void
swap(
hold_ptr
&other)
44
{
45
T *tmp=other.ptr_;
46
other.ptr_=ptr_;
47
ptr_=tmp;
48
}
49
};
50
}
// booster
51
52
#endif
booster::hold_ptr
a smart pointer similar to std::auto_ptr but it is non-copyable and underlying object has same constn...
Definition:
hold_ptr.h:18
Generated on Thu Oct 30 2014 14:31:44 for CppCMS by
1.8.6