CppCMS
hold_ptr.h
1 //
2 // Copyright (c) 2010 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_LOCALE_HOLD_PTR_H
9 #define BOOSTER_LOCALE_HOLD_PTR_H
10 
11 namespace booster {
12 namespace locale {
17  template<typename T>
18  class hold_ptr {
19  hold_ptr(hold_ptr const &other); // non copyable
20  hold_ptr const &operator=(hold_ptr const &other); // non assignable
21  public:
25  hold_ptr() : ptr_(0) {}
29  explicit hold_ptr(T *v) : ptr_(v) {}
30 
35  {
36  delete ptr_;
37  }
38 
42  T const *get() const { return ptr_; }
46  T *get() { return ptr_; }
47 
51  T const &operator *() const { return *ptr_; }
55  T &operator *() { return *ptr_; }
59  T const *operator->() const { return ptr_; }
63  T *operator->() { return ptr_; }
64 
68  T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
69 
73  void reset(T *p=0)
74  {
75  if(ptr_) delete ptr_;
76  ptr_=p;
77  }
79  void swap(hold_ptr &other)
80  {
81  T *tmp=other.ptr_;
82  other.ptr_=ptr_;
83  ptr_=tmp;
84  }
85  private:
86  T *ptr_;
87  };
88 
89 } // locale
90 } // boost
91 
92 #endif
93 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
void reset(T *p=0)
Definition: hold_ptr.h:73
hold_ptr(T *v)
Definition: hold_ptr.h:29
T * release()
Definition: hold_ptr.h:68
a smart pointer similar to std::auto_ptr but it is non-copyable and the underlying object has the sam...
Definition: hold_ptr.h:18
void swap(hold_ptr &other)
Swap two pointers.
Definition: hold_ptr.h:79
T * operator->()
Definition: hold_ptr.h:63
This is the main namespace that encloses all localization classes.
Definition: locale_fwd.h:14
T const & operator*() const
Definition: hold_ptr.h:51
T const * operator->() const
Definition: hold_ptr.h:59
Booster library namespace. The library that implements Boost Like API in ABI backward compatible way...
Definition: application.h:23
hold_ptr()
Definition: hold_ptr.h:25
~hold_ptr()
Definition: hold_ptr.h:34