|
/*
***************************************************************************
kis v 1 r 1
(c) 2002-2009, Florin DUMITRESCU
mailto: fdproxy@gmail.com
$Workfile: kis_SharedPtr.h $
***************************************************************************
*/
#ifndef _KIS_SHARED_PTR_H_
#define _KIS_SHARED_PTR_H_
KIS_BEG
//-------------------------------------------------------------------------
/** [To be supplied.] */
template < class T >
class C_SharedPtr
{
public:
explicit C_SharedPtr()
:
m_p( 0 )
{
// nop
}
explicit C_SharedPtr( T* a_p )
:
m_p( a_p )
{
_AddRef();
}
C_SharedPtr( const C_SharedPtr<T>& a_s )
:
m_p( a_s.m_p )
{
_AddRef();
}
~C_SharedPtr()
{
_Release();
}
T* operator->()
{
return m_p;
}
const T* operator->() const
{
return m_p;
}
C_SharedPtr<T>& operator=( const C_SharedPtr<T>& a_r )
{
if ( m_p != a_r.m_p )
{
_Release();
m_p = a_r.m_p;
_AddRef();
}
return *this;
}
operator bool() const
{
return m_p != 0;
}
protected:
T* m_p;
void _AddRef()
{
if ( m_p )
m_p->AddRef();
}
void _Release()
{
if ( m_p )
m_p->Release();
m_p = 0;
}
};
KIS_END
#endif _KIS_SHARED_PTR_H_
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.