00001 /* -*- C++ -*- */ 00002 00003 /* COPYRIGHT 00004 * 00005 * This file is part of the Visual Effects Engine - VEE 00006 * 00007 * Read the "VEE-LICENSE" file for the license. 00008 * 00009 * Authors & Copyright: 00010 * 00011 * Tommi Ilmonen, Tuukka Heikura, Marko Myllymaa and 00012 * Janne Kontkanen 2001-2004 00013 * 00014 * Additional copyrights: Tekes 2003-2004 00015 * 00016 * firstname.lastname@hut.fi 00017 * 00018 */ 00019 00020 #ifndef VEE_CLONABLE_POINTER_H 00021 #define VEE_CLONABLE_POINTER_H 00022 00032 template <typename T> 00033 class VEE_ClonablePointer 00034 { 00035 public: 00037 VEE_ClonablePointer() : m_ptr(0) {} 00039 VEE_ClonablePointer(T *ptr) : m_ptr(ptr) {} 00041 VEE_ClonablePointer(const VEE_ClonablePointer &that) 00042 : m_ptr(that.m_ptr ? that.m_ptr->clone() : 0) {} 00043 00045 ~VEE_ClonablePointer() { delete m_ptr; } 00046 00048 VEE_ClonablePointer & operator = (const VEE_ClonablePointer &that) 00049 { 00050 if(this != &that) { 00051 delete m_ptr; 00052 m_ptr = that.m_ptr ? that.m_ptr->clone() : 0; 00053 } 00054 return *this; 00055 } 00056 00058 VEE_ClonablePointer & operator = (T * that) 00059 { delete m_ptr; m_ptr = that ; return *this; } 00060 00062 T * ptr() { return m_ptr; } 00063 00065 const T * ptr() const { return m_ptr; } 00066 00068 T * clone() const { return m_ptr ? m_ptr->clone() : 0; } 00069 00071 void forget() { m_ptr = 0; } 00072 00073 protected: 00074 T * m_ptr; 00075 }; 00076 00077 #endif