new impl for SetLongevity which looks more like c++ and circumvents the usage of the so called (ms) 'deprecated' function copy_backward
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@355 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
1c8bce4d43
commit
d45e0a1b08
2 changed files with 86 additions and 11 deletions
|
@ -13,20 +13,46 @@
|
|||
// without express or implied warranty.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Last update: June 20, 2001
|
||||
|
||||
#include "../include/loki/Singleton.h"
|
||||
|
||||
using namespace Loki::Private;
|
||||
|
||||
#ifdef LOKI_ENABLE_NEW_SETLONGLIVITY_HELPER_DATA_IMPL
|
||||
Loki::Private::TrackerArray* Loki::Private::pTrackerArray = 0;
|
||||
#else
|
||||
Loki::Private::TrackerArray Loki::Private::pTrackerArray = 0;
|
||||
unsigned int Loki::Private::elements = 0;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// function AtExitFn
|
||||
// Ensures proper destruction of objects with longevity
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef LOKI_ENABLE_NEW_SETLONGLIVITY_HELPER_DATA_IMPL
|
||||
|
||||
void LOKI_C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn()
|
||||
{
|
||||
assert(pTrackerArray!=0 && !pTrackerArray->empty());
|
||||
|
||||
// Pick the element at the top of the stack
|
||||
LifetimeTracker* pTop = pTrackerArray->back();
|
||||
|
||||
// Remove that object off the stack _before_ deleting pTop
|
||||
pTrackerArray->pop_back();
|
||||
|
||||
// Destroy the element
|
||||
delete pTop;
|
||||
|
||||
// Destroy stack when it's empty _after_ deleting pTop
|
||||
if(pTrackerArray->empty())
|
||||
{
|
||||
delete pTrackerArray;
|
||||
pTrackerArray = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void LOKI_C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn()
|
||||
{
|
||||
assert(elements > 0 && pTrackerArray != 0);
|
||||
|
@ -41,6 +67,8 @@ void LOKI_C_CALLING_CONVENTION_QUALIFIER Loki::Private::AtExitFn()
|
|||
delete pTop;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Change log:
|
||||
// June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue