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

int $ArgChecking::VerifyNotZero($CI_REF,PCWSTR argumentVarName,int value)
{
   if ( !value )
      $FatalError::RaiseZeroValueArgument($$CI, argumentVarName );
   return value;
}
unsigned int $ArgChecking::VerifyNotZero($CI_REF,PCWSTR argumentVarName,unsigned int value)
{
   if ( !value )
      $FatalError::RaiseZeroValueArgument($$CI, argumentVarName );
   return value;
}
DWORD $ArgChecking::VerifyNotZero($CI_REF,PCWSTR argumentVarName,DWORD value)
{
   if ( !value )
      $FatalError::RaiseZeroValueArgument($$CI, argumentVarName );
   return value;
}
SIZE_T $ArgChecking::VerifyNotZero_Size($CI_REF,PCWSTR argumentVarName,SIZE_T value)
{
   if ( !value )
      $FatalError::RaiseZeroValueArgument($$CI, argumentVarName );
   return value;
}
int $ArgChecking::VerifyNotNegative($CI_REF,PCWSTR argumentVarName,int value)
{
   if ( value < 0 )
      $FatalError::RaiseNegativeValueArgument($$CI, argumentVarName );
   return value;
}
int $ArgChecking::VerifyPositive($CI_REF,PCWSTR argumentVarName,int value)
{
   if ( value <= 0 )
      $FatalError::RaiseNotPozitiveValueArgument($$CI, argumentVarName );
   return value;
}

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

$PCVoid $ArgChecking::VerifyPointer($CI_REF, PCWSTR argumentVarName, $PCVoid pointer )
{
   if ( !argumentVarName )
      $$VERIFY_POINTER_ARG( argumentVarName );
   if ( !pointer )
      $FatalError::RaiseNullPointerArgument($$CI, argumentVarName );
   return pointer;
}

HANDLE $ArgChecking::VerifyHandle($CI_REF, PCWSTR argumentVarName, HANDLE handle )
{
   return VerifyHandle($ci, argumentVarName, handle, false );
}
HANDLE $ArgChecking::VerifyHandle($CI_REF, PCWSTR argumentVarName, HANDLE handle,
                                           BOOL isOfInvalidHandleValueCategory )
{
   if ( !argumentVarName )
      $$VERIFY_POINTER_ARG( argumentVarName );
   if ( isOfInvalidHandleValueCategory )
   {
      if ( handle == INVALID_HANDLE_VALUE )
         $FatalError::RaiseInvalidHandleValueArgument($$CI, argumentVarName );
   }
   else
      if ( !handle )
         $FatalError::RaiseNullHandleArgument($$CI, argumentVarName );
   return handle;
}

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

void $ArgChecking::VerifyDisposable($CI_REF, PCWSTR argumentVarName,
                                             const $Disposable& disposable )
{
   if ( !argumentVarName )
      $$VERIFY_POINTER_ARG( argumentVarName );
   if ( !disposable.IsValidDisposable )
      $FatalError::RaiseInvalidDisposableArgument($$CI, argumentVarName );
}

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