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

$WithFinally::$WithFinally($A, const $ActionFunc& body,
                               const $ActionFunc& finally )
{
   if ( !body )
      $FatalError::RaiseNullTargetOfArgument($$CI, $NAME_OF( body ) );
   if ( !finally )
      $FatalError::RaiseNullTargetOfArgument($$CI, $NAME_OF( finally ) );
   _BodyFuncPtr_ = &body;
   _FinallyFuncPtr_ = &finally;
}

$WithFinally::~$WithFinally()
{
   (*_FinallyFuncPtr_)();
}

//--------------------------------------------------------------------------------------------------

void $WithFinally::Do($O) const
{
   if ( !_BodyFuncPtr_ )
      $INVALID_OPERATION();
   (*_BodyFuncPtr_)();
}

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