/** release smart pointer (and decrement ref count) if not null */ inline void Release() { if (m_pT != NULL) { Tcls *pT = m_pT; m_pT = NULL; pT->Release(); } }
FORCEINLINE void CCountedPtr<Tcls_>::Assign(Tcls *pT) { /* if they are the same, we do nothing */ if (pT != m_pT) { if (pT) pT->AddRef(); // AddRef new pointer if any Tcls *pTold = m_pT; // save original ptr m_pT = pT; // update m_pT to new value if (pTold) pTold->Release(); // release old ptr if any } }
inline SQInteger DefSQConstructorCallback(HSQUIRRELVM vm) { /* Find the amount of params we got */ int nparam = sq_gettop(vm); try { /* Create the real instance */ Tcls *instance = HelperT<Tmethod>::SQConstruct((Tcls *)NULL, (Tmethod)NULL, vm); sq_setinstanceup(vm, -Tnparam, instance); sq_setreleasehook(vm, -Tnparam, DefSQDestructorCallback<Tcls>); instance->AddRef(); return 0; } catch (SQInteger e) { sq_pop(vm, nparam); return e; } }
/** release smart pointer (and decrement ref count) if not null */ FORCEINLINE void Release() {if (m_pT != NULL) {Tcls *pT = m_pT; m_pT = NULL; pT->Release();}}
/** add one ref to the underlaying object */ FORCEINLINE void AddRef() {if (m_pT != NULL) m_pT->AddRef();}
/** add one ref to the underlaying object */ inline void AddRef() { if (m_pT != NULL) m_pT->AddRef(); }