1 #ifndef AWFUL_WEAKPOINTER_H_
2 #define AWFUL_WEAKPOINTER_H_
4 // TODO: make this shit work
8 template< class C
> class Pointer
;
9 template< class C
> class ConstPointer
;
11 template< class C
> class weakptrproxy
14 weakptrproxy( const C
* pObj_
) :
16 m_pObj( const_cast< C
* >( pObj_
) )
23 m_pObj
->m_pWeakPtrProxy
= 0;
27 unsigned long m_WeakRefCount
;
31 template< class C
, typename P
> class weakptr
33 template< class C_
, class P_
> friend class ptr
;
41 weakptr
& operator=( const weakptr
& wptr_
)
43 if( m_pProxy
== wptr_
.m_pProxy
)
49 m_pProxy
= wptr_
.m_pProxy
;
65 weakptr
& operator=( P pObj_
)
67 if( m_pProxy
== pObj_
.m_pProxy
)
80 ++m_pProxy
->m_WeakRefCount
;
88 if( !( --m_pProxy
->m_WeakRefCount
) )
95 void setObj( P pObj_
)
97 if( pObj_
->m_pWeakPtrProxy
)
99 m_pProxy
= pObj_
->m_pWeakPtrProxy
;
104 m_pProxy
= pObj_
->m_pWeakPtrProxy
= new weakptrproxy
< C
>( pObj_
);
110 if( m_pProxy
&& !m_pProxy
->m_pObj
)
119 return m_pProxy
->m_pObj
;
122 mutable weakptrproxy
< C
>* m_pProxy
;
125 template< class C
> class WeakPointer
: public weakptr
< C
, C
* >
133 WeakPointer( const WeakPointer
& Ptr_
) :
134 weakptr
< C
, C
* >( Ptr_
)
138 WeakPointer( const Pointer
< C
>& Ptr_
) :
139 weakptr
< C
, C
* >( Ptr_
)
144 template< class C
> class WeakConstPointer
: public weakptr
< C
, const C
* >
148 weakptr
< C
, const C
* >()
152 WeakConstPointer( const WeakConstPointer
& Ptr_
) :
153 weakptr
< C
, const C
* >( Ptr_
)
157 WeakConstPointer( const WeakPointer
< C
>& Ptr_
) :
158 weakptr
< C
, const C
* >( Ptr_
)
162 WeakConstPointer( const ConstPointer
< C
>& Ptr_
) :
163 weakptr
< C
, const C
* >( Ptr_
)
167 WeakConstPointer( const Pointer
< C
>& Ptr_
) :
168 weakptr
< C
, const C
* >( Ptr_
)