00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BOOSTER_LOCALE_HOLD_PTR_H
00009 #define BOOSTER_LOCALE_HOLD_PTR_H
00010
00011 namespace booster {
00012 namespace locale {
00017 template<typename T>
00018 class hold_ptr {
00019 hold_ptr(hold_ptr const &other);
00020 hold_ptr const &operator=(hold_ptr const &other);
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 }
00090 }
00091
00092 #endif
00093