CppCMS
clone_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_CLONE_PTR_H
9 #define BOOSTER_CLONE_PTR_H
10 
11 namespace booster {
12 
17  template<typename T>
18  class clone_ptr {
19  T *ptr_;
20  public:
21  clone_ptr() : ptr_(0) {}
22  explicit clone_ptr(T *v) : ptr_(v) {}
23  clone_ptr(clone_ptr const &other) : ptr_(0)
24  {
25  if(other.ptr_)
26  ptr_=other.ptr_->clone();
27  }
28  clone_ptr const &operator=(clone_ptr const &other)
29  {
30  if(this != &other) {
31  clone_ptr tmp(other);
32  swap(tmp);
33  }
34  return *this;
35  }
36  ~clone_ptr() {
37  if(ptr_) delete ptr_;
38  }
39 
40  T *get() const { return ptr_; }
41  T &operator *() const { return *ptr_; }
42  T *operator->() const { return ptr_; }
43 
44  T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
45  void reset(T *p=0)
46  {
47  if(ptr_) delete ptr_;
48  ptr_=p;
49  }
50  void swap(clone_ptr &other)
51  {
52  T *tmp=other.ptr_;
53  other.ptr_=ptr_;
54  ptr_=tmp;
55  }
56  };
57 
58 } // booster
59 
60 #endif
a smart pointer similar to std::auto_ptr but it clones (by calling T::clone()) underlying object on c...
Definition: clone_ptr.h:18
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23