30 #ifndef __igtlSmartPointer_h
31 #define __igtlSmartPointer_h
55 template <
class TObjectType>
67 m_Pointer(p.m_Pointer)
84 ObjectType *operator -> ()
const
88 operator ObjectType * ()
const
93 {
return m_Pointer != 0; }
95 {
return m_Pointer == 0; }
100 bool operator == ( R r )
const
101 {
return (m_Pointer == static_cast<const ObjectType*>(r) ); }
103 template <
typename R>
104 bool operator != ( R r )
const
105 {
return (m_Pointer != static_cast<const ObjectType*>(r) ); }
109 {
return m_Pointer; }
113 {
return (
void*)m_Pointer < (
void*) r.m_Pointer; }
117 {
return (
void*)m_Pointer > (
void*) r.m_Pointer; }
121 {
return (
void*)m_Pointer <= (
void*) r.m_Pointer; }
125 {
return (
void*)m_Pointer >= (
void*) r.m_Pointer; }
136 ObjectType* tmp = m_Pointer;
139 if ( tmp ) { tmp->UnRegister(); }
146 ObjectType *
Print (std::ostream& os)
const
149 (*m_Pointer).Print(os);
156 ObjectType* m_Pointer;
160 if(m_Pointer) { m_Pointer->Register(); }
165 if(m_Pointer) { m_Pointer->UnRegister(); }
170 template <
typename T>
171 std::ostream& operator<< (std::ostream& os, SmartPointer<T> p)
ObjectType * Print(std::ostream &os) const
SmartPointer(const SmartPointer< ObjectType > &p)
Implements transparent reference counting.
ObjectType * GetPointer() const
SmartPointer(ObjectType *p)