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

$AutoFreeArray::$AutoFreeArray($A, const std::initializer_list<PVOID volatile*>& ptrPointers
                                   $p_optional_list )
: $AutoFreeArray($ci, nullptr, ptrPointers )
{}
$AutoFreeArray::$AutoFreeArray($A, $MemFreeRoutine specialFreeRoutine $optional,
                                   const std::initializer_list<PVOID volatile*>& ptrPointers
                                   $p_optional_list )
{
   for (auto pPointer: ptrPointers)
      $$VERIFY_POINTER_ARG( pPointer );
   _PtrPointers_ = ptrPointers;
   _SpecialFreeRoutine_ = specialFreeRoutine;
   ValidateDisposable($$);
}

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

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

void $AutoFreeArray::ResetSuperstructure()
{
   _PtrPointers_ = std::initializer_list<PVOID volatile*>();
   _SpecialFreeRoutine_ = nullptr;
}

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

void $AutoFreeArray::Free($O)
{
   if ( IsValidDisposable )
   {
      $Memory::FreeByPointers($, _PtrPointers_, _SpecialFreeRoutine_ );
      ResetSuperstructure();
      InvalidateDisposable();
   }
}

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