// RuntimeForStatic base library | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#include "Precompiled.h"
#include "SharedIncludes.h"
namespace RuntimeForStatic {
//==================================================================================================

$AutoFree::$AutoFree($A, PVOID volatile* pPointer $p_optional )
: $AutoFree($ci, nullptr, pPointer )
{}
$AutoFree::$AutoFree($A, $MemFreeRoutine specialFreeRoutine $optional,
                         PVOID volatile* pPointer $p_optional )
{
   $$VERIFY_POINTER_ARG( pPointer );
   _PPointer_ = pPointer;
   _SpecialFreeRoutine_ = specialFreeRoutine;
   ValidateDisposable($$);
}

//==================================================================================================

void $AutoFree::DoDispose($CI_REF)
{
   Free($ci);
}

void $AutoFree::ResetSuperstructure()
{
   _PPointer_ = nullptr;
   _SpecialFreeRoutine_ = nullptr;
}

void $AutoFree::Neutralize()
{
   InvalidateDisposable();
}

//==================================================================================================

void $AutoFree::Free($O)
{
   if ( IsValidDisposable )
   {
      $Memory::FreeByPtr($, _PPointer_, _SpecialFreeRoutine_ );
      ResetSuperstructure();
      InvalidateDisposable();
   }
}

//==================================================================================================
} // RuntimeForStatic
