Added StrongPtr class to Loki along with tests for StrongPtr.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@623 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rich_sposato 2006-04-05 22:56:58 +00:00
parent 0201647cdc
commit d5f4f0f77f
7 changed files with 3294 additions and 52 deletions

View file

@ -12,6 +12,8 @@
// $Header$
#include <assert.h>
// ----------------------------------------------------------------------------
@ -38,6 +40,8 @@ public:
return new BaseClass();
}
void DoThat( void ) const {}
static inline bool AllDestroyed( void )
{
return ( s_constructions == s_destructions );
@ -82,7 +86,7 @@ public:
// This function is used only for the DeepCopy policy.
virtual BaseClass * Clone( void ) const
{
return new BaseClass;
return new PublicSubClass;
}
};
@ -94,13 +98,98 @@ public:
// This function is used only for the DeepCopy policy.
virtual BaseClass * Clone( void ) const
{
return new BaseClass;
return new PrivateSubClass;
}
};
// ----------------------------------------------------------------------------
/** @class MimicCOM Acts like a COM object by having an intrusive ref count.
*/
class MimicCOM
{
public:
MimicCOM( void )
: m_count( 0 )
, m_AddRefCount( 0 )
, m_ReleaseCount( 0 )
{
s_constructions++;
}
virtual ~MimicCOM( void )
{
s_destructions++;
}
void AddRef( void )
{
m_count++;
m_AddRefCount++;
}
void Release( void )
{
m_ReleaseCount++;
assert( 0 < m_count );
m_count--;
if ( 0 == m_count )
{
/** @note I consider "delete this;" to be very unsafe! I'm only
using it here for the purpose of testing.
*/
delete this;
}
}
void DoThat( void ) {}
static inline bool AllDestroyed( void )
{
return ( s_constructions == s_destructions );
}
static inline bool ExtraConstructions( void )
{
return ( s_constructions > s_destructions );
}
static inline bool ExtraDestructions( void )
{
return ( s_constructions < s_destructions );
}
static inline unsigned int GetCtorCount( void )
{
return s_constructions;
}
static inline unsigned int GetDtorCount( void )
{
return s_destructions;
}
private:
/// Not implemented.
MimicCOM( const MimicCOM & );
/// Not implemented.
MimicCOM & operator = ( const MimicCOM & );
static unsigned int s_constructions;
static unsigned int s_destructions;
unsigned int m_count;
unsigned int m_AddRefCount;
unsigned int m_ReleaseCount;
};
// ----------------------------------------------------------------------------
// $Log$
// Revision 1.2 2006/04/05 22:53:12 rich_sposato
// Added StrongPtr class to Loki along with tests for StrongPtr.
//
// Revision 1.1 2006/03/20 21:14:16 rich_sposato
// Adding base.h to CVS.
//