/*****************************************************************************
 * $LastChangedDate: 2010-05-25 21:26:05 -0400 (Tue, 25 May 2010) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Debug methods (implementation).
 * @remarks Documented at shptr_doc.hh.
 *//*
 * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

// -- (included by shptr_impl.hh even if DEBUG=0) --

#ifndef TEST_SHPTR_YIELD  // for stress testing
#define TEST_SHPTR_YIELD()
#define TEST_SHPTR_YIELD_IS_NOP 1  // tests internally check this
#endif

#if DEBUG

    // shptr itself never should be NULL but its mObj may be NULL.
    // Outside a method, shptr should have maintained refCount >= 1,
    // but inside, refCount can be become 0 momentarily.

    // Preferred (does two typesig checks).
    template<typename SHPTR>
    void SHPTR_CHECK( const SHPTR* const ps, const int minRefCount ) const
    {
        CHECK_TYPESIG(ps,TYPESIG_SHARED_PTR);
        IF_NOT_NULL_SHPTR( ps->mObj )
        {
            CHECK_TYPESIG(ps->mObj,TYPESIG_SHARED);
            ASSERT( (ps->mObj->mRefCount) >= minRefCount );
        }
    }

    void SHPTR_CHECK( const SHARED* const shared, const int minRefCount ) const
    {
        // SHARED initially has a 0 refCount (new SHARED).
        IF_NOT_NULL_SHPTR( shared )
        {
            CHECK_TYPESIG(shared,TYPESIG_SHARED);
            ASSERT( (shared->mRefCount) >= minRefCount );
        }
    }

#else // !DEBUG
#   undef  SHPTR_CHECK
#   define SHPTR_CHECK(NIL0,NIL2)
#endif  // DEBUG
