//**************************************************************************************************
//
// DIFFERENT CHECKINGS — PREPROCESSOR:
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// RuntimeForStatic base library | C+- (SysRoutine) | Author: Sergei Y.Kitáev
#pragma once
#include "include_restrictions.h"

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//
// GENERAL VERIFICATIONS/FAILURES:
//
//==================================================================================================
// DISCARDABLE VERIFICATIONS:

#ifndef $EXCLUDE_VERIFICATION
   #define $VERIFY_NOT_ZERO( value ) \
      RuntimeForStatic::$Checking::VerifyNotZero($, (value) )
   #define $VERIFY_NOT_ZERO_SIZE( value ) \
      RuntimeForStatic::$Checking::VerifyNotZeroValue_Size($, (value) )
   #define $VERIFY_NOT_NEGATIVE_VALUE( value ) \
      RuntimeForStatic::$Checking::VerifyNotNegative($, (value) )
   #define $VERIFY_POSITIVE_VALUE( value ) \
      RuntimeForStatic::$Checking::VerifyPositive($, (value) )

   #define $VERIFY_POINTER( pointer ) \
      RuntimeForStatic::$Checking::VerifyPointer($, ($PCVoid)(pointer) )

   #define $VERIFY_HANDLE( handle ) \
      RuntimeForStatic::$Checking::VerifyHandle($, (handle) )
   #define $VERIFY_HANDLE_IV( handle ) \
      RuntimeForStatic::$Checking::VerifyHandle($, (handle), true )
   #define $VERIFY_HANDLE_EX( handle, isOfInvalidHandleValueCategory ) \
      RuntimeForStatic::$Checking::VerifyHandle($, \
         (handle), (isOfInvalidHandleValueCategory) )

   #define $VERIFY_DISPOSABLE( disposable ) \
      RuntimeForStatic::$Checking::VerifyDisposable($, (disposable) )
#else
   #define $VERIFY_NOT_ZERO( value )                                    $VOID_VALUE
   #define $VERIFY_NOT_ZERO_SIZE( value )                               $VOID_VALUE
   #define $VERIFY_NOT_NEGATIVE_VALUE( value )                          $VOID_VALUE
   #define $VERIFY_POSITIVE_VALUE( value )                              $VOID_VALUE

   #define $VERIFY_POINTER( pointer )                                   $VOID_VALUE

   #define $VERIFY_HANDLE( handle )                                     $VOID_VALUE
   #define $VERIFY_HANDLE_IV( handle )                                  $VOID_VALUE
   #define $VERIFY_HANDLE_EX( handle, isOfInvalidHandleValueCategory )  $VOID_VALUE

   #define $VERIFY_DISPOSABLE( disposable )                             $VOID_VALUE
#endif // $EXCLUDE_VERIFICATION

#ifndef $EXCLUDE_VERIFICATION
   #define $VERIFY_VALID_DISPOSABLE() \
      this->VerifyValidDisposable($ci)
#else
   #define $VERIFY_VALID_DISPOSABLE()  $VOID_VALUE
#endif // $EXCLUDE_VERIFICATION

#define $DEAD_CODE_BRANCH() \
   RuntimeForStatic::$FatalError::RaiseDeadCodeBranch($$)

#define $NOT_IMPLEMENTED_FAILURE() \
   RuntimeForStatic::$FatalError::RaiseNotImplemented($$)

//--------------------------------------------------------------------------------------------------
// NON-DISCARDABLE VERIFICATIONS:

#define $$VERIFY_NOT_ZERO( value ) \
   RuntimeForStatic::$Checking::VerifyNotZero($$, (value) )
#define $$VERIFY_NOT_ZERO_SIZE( value ) \
   RuntimeForStatic::$Checking::VerifyNotZeroValue_Size($$, (value) )
#define $$VERIFY_NOT_NEGATIVE_VALUE( value ) \
   RuntimeForStatic::$Checking::VerifyNotNegative($$, (value) )
#define $$VERIFY_POSITIVE_VALUE( value ) \
   RuntimeForStatic::$Checking::VerifyPositive($$, (value) )

#define $$VERIFY_POINTER( pointer ) \
   RuntimeForStatic::$Checking::VerifyPointer($$, ($PCVoid)(pointer) )

#define $$VERIFY_HANDLE( handle ) \
   RuntimeForStatic::$Checking::VerifyHandle($$, (handle) )
#define $$VERIFY_HANDLE_IV( handle ) \
   RuntimeForStatic::$Checking::VerifyHandle($$, (handle), true )
#define $$VERIFY_HANDLE_EX( handle, isOfInvalidHandleValueCategory ) \
   RuntimeForStatic::$Checking::VerifyHandle($$, \
      (handle), (isOfInvalidHandleValueCategory) )

#define $$VERIFY_DISPOSABLE( disposable ) \
   RuntimeForStatic::$Checking::VerifyDisposable($$, (disposable) )

#define $$VERIFY_VALID_DISPOSABLE() \
   this->VerifyValidDisposable($$CI)


//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//
// INVALID OPERATION RAISE:
//
//==================================================================================================

#define $INVALID_OPERATION() \
   RuntimeForStatic::$FatalError::RaiseInvalidOperation($$CI)

#define $INVALID_OPERATION_WITH_MESSAGE( message ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessage($$CI, (message) )
#define $INVALID_OPERATION_WITH_MESSAGE_1( messageFmt, a1 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1) )
#define $INVALID_OPERATION_WITH_MESSAGE_2( messageFmt, a1, a2 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2) )
#define $INVALID_OPERATION_WITH_MESSAGE_3( messageFmt, a1, a2, a3 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3) )
#define $INVALID_OPERATION_WITH_MESSAGE_4( messageFmt, a1, a2, a3, a4 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3), (a4) )
#define $INVALID_OPERATION_WITH_MESSAGE_5( messageFmt, a1, a2, a3, a4, a5 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5) )
#define $INVALID_OPERATION_WITH_MESSAGE_6( messageFmt, a1, a2, a3, a4, a5, a6 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6) )
#define $INVALID_OPERATION_WITH_MESSAGE_7( messageFmt, a1, a2, a3, a4, a5, a6, a7 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7) )
#define $INVALID_OPERATION_WITH_MESSAGE_8( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8) )
#define $INVALID_OPERATION_WITH_MESSAGE_9( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) \
   RuntimeForStatic::$FatalError::RaiseInvalidOperationWithMessageFmt($$CI, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9) )


//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//
// ASSERTION DEFS:
//
//==================================================================================================
// DISCARDABLE ASSERTS:

#ifndef $EXCLUDE_VERIFICATION
   #define $ASSERT( condition ) \
      RuntimeForStatic::$Checking::Assert($, (condition), $STRINGIZE(condition) )

   #define $ASSERTION_FAILURE() \
      RuntimeForStatic::$FatalError::RaiseAssertionFailure($)

   #define $ASSERTION_FAILURE_WITH_MESSAGE( message ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailure($, (message) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_1( messageFmt, a1 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_2( messageFmt, a1, a2 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_3( messageFmt, a1, a2, a3 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_4( messageFmt, a1, a2, a3, a4 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3), (a4) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_5( messageFmt, a1, a2, a3, a4, a5 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3), (a4), (a5) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_6( messageFmt, a1, a2, a3, a4, a5, a6 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_7( messageFmt, a1, a2, a3, a4, a5, a6, a7 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_8( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8) )
   #define $ASSERTION_FAILURE_WITH_MESSAGE_9( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) \
      RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($, \
         (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9) )
#else
   #define $ASSERT( condition )  $VOID_VALUE

   #define $ASSERTION_FAILURE()  $VOID_VALUE

   #define $ASSERTION_FAILURE_WITH_MESSAGE( message ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_1( messageFmt, a1 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_2( messageFmt, a1, a2 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_3( messageFmt, a1, a2, a3 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_4( messageFmt, a1, a2, a3, a4 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_5( messageFmt, a1, a2, a3, a4, a5 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_6( messageFmt, a1, a2, a3, a4, a5, a6 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_7( messageFmt, a1, a2, a3, a4, a5, a6, a7 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_8( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8 ) \
      $VOID_VALUE
   #define $ASSERTION_FAILURE_WITH_MESSAGE_9( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) \
      $VOID_VALUE
#endif // $EXCLUDE_VERIFICATION

//--------------------------------------------------------------------------------------------------
// NON-DISCARDABLE ASSERTS:

#define $$ASSERT( condition ) \
   RuntimeForStatic::$Checking::Assert($$, (condition), $STRINGIZE(condition) )

#define $$ASSERTION_FAILURE() \
   RuntimeForStatic::$FatalError::RaiseAssertionFailure($$)

#define $$ASSERTION_FAILURE_WITH_MESSAGE( message ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailure($$, (message) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_1( messageFmt, a1 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_2( messageFmt, a1, a2 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_3( messageFmt, a1, a2, a3 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_4( messageFmt, a1, a2, a3, a4 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3), (a4) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_5( messageFmt, a1, a2, a3, a4, a5 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_6( messageFmt, a1, a2, a3, a4, a5, a6 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_7( messageFmt, a1, a2, a3, a4, a5, a6, a7 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_8( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8) )
#define $$ASSERTION_FAILURE_WITH_MESSAGE_9( messageFmt, a1, a2, a3, a4, a5, a6, a7, a8, a9 ) \
   RuntimeForStatic::$FatalError::RaiseAssertionFailureFmt($$, \
      (messageFmt), (a1), (a2), (a3), (a4), (a5), (a6), (a7), (a8), (a9) )

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