From cd6a4f5864df32a6f8ae36d62bdb0ce8d036dab5 Mon Sep 17 00:00:00 2001 From: rich_sposato Date: Wed, 7 Sep 2011 22:51:17 +0000 Subject: [PATCH] Added code to support test of bug 3224518. git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1096 7ec92016-0320-0410-acc4-a06ded1c099a --- test/SmartPtr/base.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/test/SmartPtr/base.h b/test/SmartPtr/base.h index f5d3e59..ba3ae05 100644 --- a/test/SmartPtr/base.h +++ b/test/SmartPtr/base.h @@ -1,12 +1,12 @@ //////////////////////////////////////////////////////////////////////////////// // Test program for The Loki Library // Copyright (c) 2006 Richard Sposato -// Permission to use, copy, modify, distribute and sell this software for any -// purpose is hereby granted without fee, provided that the above copyright -// notice appear in all copies and that both that copyright notice and this +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this // permission notice appear in supporting documentation. -// The authors make no representations about the -// suitability of this software for any purpose. It is provided "as is" +// The authors make no representations about the +// suitability of this software for any purpose. It is provided "as is" // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// @@ -20,7 +20,7 @@ class BaseClass { public: - BaseClass( void ) + BaseClass( void ) : m_refCount( 1 ) { s_constructions++; } @@ -31,8 +31,14 @@ public: } // These 2 functions are so we can pretend we have a COM object. - void AddRef( void ) {} - void Release( void ) {} + void AddRef( void ) { ++m_refCount; } + void Release( void ) + { + assert( 0 < m_refCount ); + --m_refCount; + if ( 0 == m_refCount ) + delete this; + } // This function is used only for the DeepCopy policy. virtual BaseClass * Clone( void ) const @@ -75,6 +81,8 @@ private: static unsigned int s_constructions; static unsigned int s_destructions; + + unsigned int m_refCount; };