18 #ifndef __itkAutoPointer_h
19 #define __itkAutoPointer_h
45 template<
class TObjectType >
68 m_Pointer(p), m_IsOwner(takeOwnership)
74 if ( m_IsOwner && m_Pointer )
84 ObjectType * operator->()
const
91 if ( m_IsOwner && m_Pointer )
101 void TakeOwnership(
void)
102 { m_IsOwner =
true; }
105 void TakeOwnership(ObjectType *objectptr)
107 if ( m_IsOwner && m_Pointer )
111 m_Pointer = objectptr;
117 void TakeNoOwnership(ObjectType *objectptr)
119 if ( m_IsOwner && m_Pointer )
123 m_Pointer = objectptr;
129 bool IsOwner(
void)
const
130 {
return m_IsOwner; }
144 ObjectType * ReleaseOwnership(
void)
152 ObjectType * GetPointer()
const
153 {
return m_Pointer; }
157 {
return (
void *)m_Pointer == (
void *)r.
m_Pointer; }
161 {
return (
void *)m_Pointer != (
void *)r.
m_Pointer; }
165 {
return (
void *)m_Pointer < (
void *)r.
m_Pointer; }
169 {
return (
void *)m_Pointer > (
void *)r.
m_Pointer; }
173 {
return (
void *)m_Pointer <= (
void *)r.
m_Pointer; }
177 {
return (
void *)m_Pointer >= (
void *)r.
m_Pointer; }
189 operator bool()
const
190 {
return ( m_Pointer !=
NULL ); }
209 ObjectType *temp = m_Pointer;
211 m_Pointer = r.m_Pointer;
220 template<
typename T >
221 std::ostream & operator<<(std::ostream & os, AutoPointer< T > p)
224 os <<
"Owner: " << p.IsOwner() << std::endl;
230 template<
typename TAutoPo
interBase,
typename TAutoPo
interDerived >
235 pa.TakeNoOwnership( pb.GetPointer() );
239 pb.ReleaseOwnership();