2 // Copyright (c) 2010 Artyom Beilis (Tonkikh)
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)
8 #ifndef BOOST_LOCALE_HOLD_PTR_H
9 #define BOOST_LOCALE_HOLD_PTR_H
14 /// \brief a smart pointer similar to std::auto_ptr but it is non-copyable and the
15 /// underlying object has the same constness as the pointer itself (unlike an ordinary pointer).
19 hold_ptr(hold_ptr const &other); // non copyable
20 hold_ptr const &operator=(hold_ptr const &other); // non assignable
23 /// Create new empty pointer
25 hold_ptr() : ptr_(0) {}
27 /// Create a pointer that holds \a v, ownership is transferred to smart pointer
29 explicit hold_ptr(T *v) : ptr_(v) {}
32 /// Destroy smart pointer and the object it owns.
40 /// Get a const pointer to the object
42 T const *get() const { return ptr_; }
44 /// Get a mutable pointer to the object
46 T *get() { return ptr_; }
49 /// Get a const reference to the object
51 T const &operator *() const { return *ptr_; }
53 /// Get a mutable reference to the object
55 T &operator *() { return *ptr_; }
57 /// Get a const pointer to the object
59 T const *operator->() const { return ptr_; }
61 /// Get a mutable pointer to the object
63 T *operator->() { return ptr_; }
66 /// Transfer an ownership on the pointer to user
68 T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
71 /// Set new value to pointer, previous object is destroyed, ownership on new object is transferred
79 void swap(hold_ptr &other)
93 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4