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

inline bool $Checking::UseVerifications()
{
#ifndef $EXCLUDE_VERIFICATION
   return true;
#else // $EXCLUDE_VERIFICATION
   return false;
#endif // $EXCLUDE_VERIFICATION
}

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

int $Checking::VerifyNotZero($CI_REF,int value)
{
   if ( !value )
      $FatalError::RaiseZeroValue($$CI);
   return value;
}
unsigned int $Checking::VerifyNotZero($CI_REF,unsigned int value)
{
   if ( !value )
      $FatalError::RaiseZeroValue($$CI);
   return value;
}
DWORD $Checking::VerifyNotZero($CI_REF,DWORD value)
{
   if ( !value )
      $FatalError::RaiseZeroValue($$CI);
   return value;
}
SIZE_T $Checking::VerifyNotZero_Size($CI_REF,SIZE_T value)
{
   if ( !value )
      $FatalError::RaiseZeroValue($$CI);
   return value;
}
int $Checking::VerifyNotNegative($CI_REF,int value)
{
   if ( value < 0 )
      $FatalError::RaiseNegativeValue($$CI);
   return value;
}
int $Checking::VerifyPositiveValue($CI_REF,int value)
{
   if ( value <= 0 )
      $FatalError::RaiseNotPozitiveValue($$CI);
   return value;
}

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

$PCVoid $Checking::VerifyPointer($CI_REF,$PCVoid pointer)
{
   if ( !pointer )
      $FatalError::RaiseNullPointer($$CI);
   return pointer;
}

HANDLE $Checking::VerifyHandle($CI_REF,HANDLE handle)
{
   return VerifyHandle($ci, handle, false );
}
HANDLE $Checking::VerifyHandle($CI_REF,HANDLE handle,BOOL isOfInvalidHandleValueCategory)
{
   if ( isOfInvalidHandleValueCategory )
   {
      if ( handle == INVALID_HANDLE_VALUE )
         $FatalError::RaiseInvalidHandleValue($$CI);
   }
   else
      if ( !handle )
         $FatalError::RaiseNullHandle($$CI);
   return handle;
}

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

void $Checking::VerifyNotZeroValues($CI_REF,const std::initializer_list<int>& list)
{
   for (auto v: list)
      VerifyNotZero($ci, v );
}
void $Checking::VerifyNotZeroValues($CI_REF,const std::initializer_list<unsigned int>& list)
{
   for (auto v: list)
      VerifyNotZero($ci, v );
}
void $Checking::VerifyNotZeroValues($CI_REF,const std::initializer_list<DWORD>& list)
{
   for (auto v: list)
      VerifyNotZero($ci, v );
}
void $Checking::VerifyNotZeroValues_Size($CI_REF,const std::initializer_list<SIZE_T>& list)
{
   for (auto v: list)
      VerifyNotZero_Size($ci, v );
}

void $Checking::VerifyNotNegativeValues($CI_REF,const std::initializer_list<int>& list)
{
   for (auto v: list)
      VerifyNotNegative($ci, v );
}
void $Checking::VerifyPositiveValues($CI_REF,const std::initializer_list<int>& list)
{
   for (auto v: list)
      VerifyPositiveValue($ci, v );
}

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

void $Checking::VerifyPointers($CI_REF,const std::initializer_list<$PCVoid>& pointers)
{
   for (auto p: pointers)
      VerifyPointer($ci, p );
}

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

void $Checking::VerifyHandles( $CI_REF, const std::initializer_list<HANDLE>& handles )
{
   for (auto h: handles)
      VerifyHandle($ci, h );
}
void $Checking::VerifyHandles( $CI_REF, const std::initializer_list<HANDLE>& handles,
                                        BOOL isOfInvalidHandleValueCategory )
{
   for (auto h: handles)
      VerifyHandle($ci, h, isOfInvalidHandleValueCategory );
}

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

bool $Checking::Assert($CI_REF,bool condition) $ret_true
{
   return Assert($ci, condition, nullptr );
}

bool $Checking::Assert($CI_REF,bool condition,PCWSTR conditionExp $optional) $ret_true
{
   if ( !condition )
      $FatalError::RaiseAssertionFailure($$CI, conditionExp );
   return true;
}

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