Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

deep_ptr.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 #ifndef AKAXISO2_UTIL_DEEP_PTR_H__
00003 #define AKAXISO2_UTIL_DEEP_PTR_H__
00004 
00011 namespace aka2 {
00012 
00018   template <class T>
00019   class deep_ptr {
00020   public:
00021     typedef T value_type;
00022 
00027     explicit deep_ptr(T* ptr = 0) : ptr_(ptr) {}
00028     ~deep_ptr() {
00029       delete ptr_;
00030     }
00031 
00038     deep_ptr(const deep_ptr &rhs) {
00039       if (rhs.ptr_ == 0)
00040         ptr_ = 0;
00041       else
00042         ptr_ = new T(*rhs.ptr_);
00043     }
00044 
00049     void reset(T* ptr = 0) {
00050       delete ptr_;
00051       ptr_ = ptr;
00052     }
00053 
00059     const deep_ptr<T>& operator=(const deep_ptr<T> &rhs) {
00060       delete ptr_;
00061       if (rhs.ptr_ == 0)
00062         ptr_ = 0;
00063       else
00064         ptr_ = new T(*rhs.ptr_);
00065       return *this;
00066     }
00067 
00073     bool operator ==(const deep_ptr<T> &rhs) {
00074       return ptr_ == rhs.ptr_;
00075     }
00076 
00081     T* get() const { return ptr_; }
00082 
00087     T& operator*() const { return *ptr_; }
00092     T* operator->() const { return ptr_; }
00093 
00094   private:  
00095     T* ptr_;
00096   };
00097 
00098 } // namespace aka2
00099 
00100 #endif

Generated on Sun Dec 19 22:58:57 2004 for akaxiso2 by doxygen1.2.18