00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #ifndef SO_REF_H
00025 #define SO_REF_H
00026 
00027 #include <Inventor/misc/SoAutoRef.h>
00028 
00088 template <typename T>
00089 class SoRef : public SoAutoRef
00090 {
00091 public:
00093   SoRef()
00094   {};
00095 
00097   SoRef(const SoRef<T>& that)
00098   :SoAutoRef(that)
00099   {
00100   }
00101 
00103   SoRef(T* pIn)
00104   :SoAutoRef(dynamic_cast<T*>(pIn))
00105   {
00106   }
00107 
00109   template<typename Y>
00110   SoRef(const SoRef<Y>& that)
00111   {
00112     m_pointer = that.ptr();
00113     if (m_pointer)
00114       m_pointer->ref();
00115   }
00116 
00118   virtual ~SoRef()
00119   {};
00120 
00122   inline T* releaseNoDelete()
00123   {
00124     T* p = dynamic_cast<T*>(m_pointer);
00125     if (m_pointer)
00126     {
00127       m_pointer->unrefNoDelete();
00128       m_pointer = NULL;
00129     }
00130     return p;
00131   }
00132 
00133 
00135   SoRef<T>& operator=(const SoRef<T>& that)
00136   {
00137     (*this) = (T*)(that.m_pointer);
00138     return *this;
00139   }
00140 
00142   template<typename Y>
00143   SoRef<T>& operator=(const SoRef<Y>& that)
00144   {
00145     (*this) = dynamic_cast<T*>(that.ptr());
00146     return *this;
00147   }
00148 
00150   SoRef<T>& operator=(T* ptr)
00151   {
00152     if (m_pointer != ptr) {
00153       if (m_pointer)
00154         m_pointer->unref();
00155       m_pointer = ptr;
00156       if (m_pointer)
00157         m_pointer->ref();
00158     }
00159     return *this;
00160   }
00161 
00163   T& operator*() const
00164   { return *((T*)m_pointer); }
00165 
00167   T* operator->() const
00168   { return ((T*)(m_pointer)); }
00169 
00171   T* ptr() const 
00172   { return ((T*)(m_pointer)); }
00173 
00174 };
00175 
00176 #endif // SO_REF_H
00177 
00178 
00179