Boost.Locale
boost/locale/hold_ptr.hpp
00001 //
00002 //  Copyright (c) 2010 Artyom Beilis (Tonkikh)
00003 //
00004 //  Distributed under the Boost Software License, Version 1.0. (See
00005 //  accompanying file LICENSE_1_0.txt or copy at
00006 //  http://www.boost.org/LICENSE_1_0.txt)
00007 //
00008 #ifndef BOOST_LOCALE_HOLD_PTR_H
00009 #define BOOST_LOCALE_HOLD_PTR_H
00010 
00011 namespace boost { 
00012 namespace locale {
00017     template<typename T>
00018     class hold_ptr {
00019         hold_ptr(hold_ptr const &other); // non copyable 
00020         hold_ptr const &operator=(hold_ptr const &other); // non assignable
00021     public:
00025         hold_ptr() : ptr_(0) {}
00029         explicit hold_ptr(T *v) : ptr_(v) {}
00030 
00034         ~hold_ptr() 
00035         {
00036             delete ptr_;
00037         }
00038 
00042         T const *get() const { return ptr_; }
00046         T *get() { return ptr_; }
00047 
00051         T const &operator *() const { return *ptr_; }
00055         T &operator *() { return *ptr_; }
00059         T const *operator->() const { return ptr_; }
00063         T *operator->() { return ptr_; }
00064 
00068         T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
00069 
00073         void reset(T *p=0)
00074         {
00075             if(ptr_) delete ptr_;
00076             ptr_=p;
00077         }
00079         void swap(hold_ptr &other)
00080         {
00081             T *tmp=other.ptr_;
00082             other.ptr_=ptr_;
00083             ptr_=tmp;
00084         }
00085     private:
00086         T *ptr_;
00087     };
00088 
00089 } // locale
00090 } // boost
00091 
00092 #endif
00093 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4