hold_ptr.h
//
// Copyright (c) 2010 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOSTER_LOCALE_HOLD_PTR_H
#define BOOSTER_LOCALE_HOLD_PTR_H
namespace booster {
namespace locale {
template<typename T>
class hold_ptr {
hold_ptr(hold_ptr const &other); // non copyable
hold_ptr const &operator=(hold_ptr const &other); // non assignable
public:
hold_ptr() : ptr_(0) {}
explicit hold_ptr(T *v) : ptr_(v) {}
~hold_ptr()
{
delete ptr_;
}
T const *get() const { return ptr_; }
T *get() { return ptr_; }
T const &operator *() const { return *ptr_; }
T &operator *() { return *ptr_; }
T const *operator->() const { return ptr_; }
T *operator->() { return ptr_; }
T *release() { T *tmp=ptr_; ptr_=0; return tmp; }
void reset(T *p=0)
{
if(ptr_) delete ptr_;
ptr_=p;
}
void swap(hold_ptr &other)
{
T *tmp=other.ptr_;
other.ptr_=ptr_;
ptr_=tmp;
}
private:
T *ptr_;
};
} // locale
} // boost
#endif
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
booster::locale::hold_ptr::reset
void reset(T *p=0)
Definition: hold_ptr.h:73
booster::locale::hold_ptr::hold_ptr
hold_ptr(T *v)
Definition: hold_ptr.h:29
booster::locale::hold_ptr::release
T * release()
Definition: hold_ptr.h:68
booster::locale::hold_ptr
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
booster::locale::hold_ptr::swap
void swap(hold_ptr &other)
Swap two pointers.
Definition: hold_ptr.h:79
booster::locale::hold_ptr::operator->
T * operator->()
Definition: hold_ptr.h:63
booster::locale::hold_ptr::operator*
T const & operator*() const
Definition: hold_ptr.h:51
booster::locale::hold_ptr::operator->
T const * operator->() const
Definition: hold_ptr.h:59
booster::locale::hold_ptr::hold_ptr
hold_ptr()
Definition: hold_ptr.h:25
booster::locale::hold_ptr::~hold_ptr
~hold_ptr()
Definition: hold_ptr.h:34