CppCMS

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

copy_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_UTIL_COPY_PTR_H
9 #define BOOSTER_UTIL_COPY_PTR_H
10
11 namespace booster {
12
21 template<typename T>
22 class copy_ptr {
23 T *ptr_;
24 public:
25 copy_ptr() : ptr_(0) {}
26 explicit copy_ptr(T *v) : ptr_(v) {}
27 copy_ptr(copy_ptr const &other) :
28 ptr_(other.ptr_ ? new T(*other.ptr_) : 0)
29 {
30 }
31 copy_ptr const &operator=(copy_ptr const &other)
32 {
33 if(this != &other) {
34 copy_ptr tmp(other);
35 swap(tmp);
36 }
37 return *this;
38 }
39 ~copy_ptr() {
40 if(ptr_) delete ptr_;
41 }
42
43 T const *get() const { return ptr_; }
44 T *get() { return ptr_; }
45
46 T const &operator *() const { return *ptr_; }
47 T &operator *() { return *ptr_; }
48 T const *operator->() const { return ptr_; }
49 T *operator->() { return ptr_; }
50 T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
51 void reset(T *p=0)
52 {
53 if(ptr_) delete ptr_;
54 ptr_=p;
55 }
56 void swap(copy_ptr &other)
57 {
58 T *tmp=other.ptr_;
59 other.ptr_=ptr_;
60 ptr_=tmp;
61 }
62 };
63
64 } // booster
65
66 #endif
booster::copy_ptr
a smart pointer similar to std::auto_ptr but it copies underlying object on pointer copy instead of m...
Definition: copy_ptr.h:22
booster
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23