ObjHolder & operator=(ObjHolder const & o) { if (&o == this) return *this; if (o.m_obj) { ::std::auto_ptr<T> newObj = copyer()(o.m_obj); deletor()(m_obj); m_obj = newObj.release(); } else { deletor()(m_obj); m_obj = 0; } return *this; }
int main() { lua_State *L = lua_open(); luaopen_base( L ); do_script( L, "test_coro.lua" ); /* for testing purpose only */ while( gTimerHandlers.size() != 0 ) { DWORD now = GetTickCount(); for( TimerHandlerList::iterator it = gTimerHandlers.begin(); it != gTimerHandlers.end(); ) { TimerHandler *h = *it; if( h->_start + h->_delay <= now ) { h->_fn( L ); free( h ); it = gTimerHandlers.erase( it ); continue; } ++ it; } Sleep( 1 ); } /* clear */ struct deletor { void operator()( TimerHandler *h ) { free( h ); } }; std::for_each( gTimerHandlers.begin(), gTimerHandlers.end(), deletor() ); lua_close( L ); return 0; }
~scoped_ptr() { D deletor; deletor(pointer); }
~id(){ deletor(held_id); }
ObjHolder & operator=(T const & o) { ::std::auto_ptr<T> newObj = copyer()(&o); deletor()(m_obj); m_obj = newObj.release(); return *this; }
~ObjHolder() throw() { try { deletor()(m_obj); } catch(...) {} }
void clear(void) { deletor()(m_obj); m_obj = 0; }