Implemented patch 2893162 to allow dynamic-casting with SmartPtr and StrongPtr.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1052 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rich_sposato 2009-11-10 19:22:16 +00:00
parent d54996dbba
commit 9e3a736929
3 changed files with 242 additions and 36 deletions

View file

@ -57,6 +57,24 @@ TwoRefCounts::TwoRefCounts( const void * p, bool strong )
// ----------------------------------------------------------------------------
TwoRefCounts::TwoRefCounts( const TwoRefCounts & rhs, bool isNull, bool strong )
: m_counts( ( isNull ) ? NULL : rhs.m_counts )
{
if ( isNull )
{
void * temp = SmallObject<>::operator new(
sizeof(Loki::Private::TwoRefCountInfo) );
assert( temp != 0 );
m_counts = new ( temp ) Loki::Private::TwoRefCountInfo( strong );
}
else
{
Increment( strong );
}
}
// ----------------------------------------------------------------------------
void TwoRefCounts::Increment( bool strong )
{
if ( strong )
@ -147,6 +165,35 @@ TwoRefLinks::TwoRefLinks( const TwoRefLinks & rhs, bool strong )
// ----------------------------------------------------------------------------
TwoRefLinks::TwoRefLinks( const TwoRefLinks & rhs, bool isNull, bool strong )
: m_pointer( ( isNull ) ? 0 : rhs.m_pointer )
, m_prev( ( isNull ) ? 0 : const_cast< TwoRefLinks * >( &rhs ) )
, m_next( ( isNull ) ? 0 : rhs.m_next )
, m_strong( strong )
{
if ( isNull )
{
m_prev = m_next = this;
}
else
{
m_prev->m_next = this;
m_next->m_prev = this;
#ifdef DO_EXTRA_LOKI_TESTS
assert( m_prev->HasPrevNode( this ) );
assert( m_next->HasNextNode( this ) );
assert( rhs.m_next->HasNextNode( this ) );
assert( rhs.m_prev->HasPrevNode( this ) );
assert( CountPrevCycle( this ) == CountNextCycle( this ) );
assert( CountPrevCycle( this ) == CountNextCycle( &rhs ) );
assert( AllNodesHaveSamePointer() );
#endif
}
}
// ----------------------------------------------------------------------------
void TwoRefLinks::SetPointer( void * p )
{
TwoRefLinks * node = m_prev;