Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Base - Defines.h
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_BASE_DEFINES_H)
#define TGS_COMMON_BASE_DEFINES_H
#pragma once

#include "TgS COMMON/TgS Common - Base - Define - Configuration.h"

#if defined(TgCOMPILER_LVM)
    #include "TgS Common - Base - Compiler (LVM) - Configuration.h"

/*
    #if defined(TgCOMPILE_PLATFORM_W64)
        #pragma message ("Compiling MacOS X64 with LVM")
        #include "TgS Common - Base - Compiler (LVM-X64) - Configuration.h"
    #else
        #error "Unknown Platform - Unknown method to choose platform"
    #endif
*/
#elif defined (TgCOMPILER_ICL)
    #include "TgS Common - Base - Compiler (ICL) - Configuration.h"
#elif defined (TgCOMPILER_CLANG)
    #include "TgS Common - Base - Compiler (CLANG) - Configuration.h"
        #pragma message ("Compiling X64 with CLANG")
        #include "TgS Common - Base - Compiler (CLANG-X64) - Configuration.h"
#elif defined (TgCOMPILER_GCC)
    #include "TgS Common - Base - Compiler (GCC) - Configuration.h"
#elif defined (TgCOMPILER_MSVC)
    #include "TgS Common - Base - Compiler (MSVC) - Configuration.h"
    #if defined(TgCOMPILE_PLATFORM_W64)
        #pragma message ("Compiling W64 with MSVC")
        #define WIN32
        #include "TgS Common - Base - Compiler (MSVC-X64) - Configuration.h"
    #elif defined(TgCOMPILE_PLATFORM_W32)
        #pragma message ("Compiling W32 with MSVC")
        #define WIN32
    #else
        #error "Unknown Platform - Unknown method to choose platform"
    #endif
#else
    #error "Unknown Compiler - Need to add compiler configuration to engine."
#endif

#include "TgS COMMON/TgS Common - Base - Define - ANSI API.h"


/* == Common ============================================================================================================================================================ */

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Code Macros                                                                                                                                                           */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define TgERROR_NOT_IMPLEMENTED             TgCOMPILER_ASSERT_MSG(TgFALSE, "Not Implemented")
#define TgCOMPILE_PRINT_SIZE(A)             char( *__kaboom )[sizeof( A )] = 1

#if TgCOMPILE_LITTLE_ENDIAN
#define TgMAKE_4CC(A,B,C,D)                 (TgUINT32)(((D & 0XFF) << 24) | ((C & 0XFF) << 16) | ((B & 0XFF) << 8) | ((A & 0XFF) << 0))
#define TgCOLOUR_FROM_RGBA(R,G,B,A)         (TgUINT32)(((A & 0XFF) << 24) | ((B & 0XFF) << 16) | ((G & 0XFF) << 8) | ((R & 0XFF) << 0))
#define TgCOLOUR_A(COL_U32)                 ((COL_U32 >> 24) & 0xFF)
#define TgCOLOUR_B(COL_U32)                 ((COL_U32 >> 16) & 0xFF)
#define TgCOLOUR_G(COL_U32)                 ((COL_U32 >>  8) & 0xFF)
#define TgCOLOUR_R(COL_U32)                 ((COL_U32      ) & 0xFF)
#else
#error WTF
#endif

#define TFCN_TOQUOTE(A)                     #A

#if defined(TgCOMPILE_WIDE_CHAR)
    #define TFCN(B)                         TFCN_TOQUOTE(B##W)
#else
    #define TFCN(B)                         TFCN_TOQUOTE(B##A)
#endif


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Basic DEFINE routines                                                                                                                                                 */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define TgSAFE_RELEASE(p)                   { if ((p)) { (p)->Release(); (p)=nullptr; } };
#define TgSAFE_ASSIGN_REF( a, b )           { TgSAFE_RELEASE(a); if ( nullptr != (b) ) { (a) = (b); (a)->AddRef(); } };

#define TgPERM(A,B,C,D)                     ((D<<6) | (C<<4) | (B<<2) | A)

#define TgARRAY_COUNT(A)                    (sizeof(A) / sizeof(A[0]))

#ifdef __cplusplus
#define TgEXTN                              extern "C"
#else
#define TgEXTN                              extern
#endif


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Base Defines                                                                                                                                                          */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#if defined(_MSC_VER) && (_MSC_VER >= 1600) && defined(__cplusplus)
    #define TgCOMPILER_ASSERT(x,c)              static_assert(x,"")
#else
    #define TgCOMPILER_ASSERT_CONCAT_(a,b,c)    a_##b##_##c
    #define TgCOMPILER_ASSERT_CONCAT(a,b,c)     TgCOMPILER_ASSERT_CONCAT_(a,b,c)
    #ifdef __COUNTER__
        #define TgCOMPILER_ASSERT(e,c)          typedef UNUSED_TYPE char TgCOMPILER_ASSERT_CONCAT(COMPILER_ASSERT_,0,__COUNTER__)[(e) != 0]
    #else
        #define TgCOMPILER_ASSERT(e,c)          typedef UNUSED_TYPE char TgCOMPILER_ASSERT_CONCAT(COMPILER_ASSERT_,c,__LINE__)[(e) != 0]
    #endif
    #define nullptr                             nullptr
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__CRITICAL
    /* Critical validation is for things that would put the executable in an unstable and usable state.  These are important enough that they are left in the compilation
    even during a final build (one used for certification).  This will cause a break in a shipping product. */
    #define TgCRITICAL_MSG( A, ... )            TgANALYSIS_ASSUME(A);                                                                                                      \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_Print( KTgCN_CHANEL_CRITICAL, __VA_ARGS__ );                                                                      \
                                                    tgPM_Abort();                                                                                                          \
                                                };

    #define TgCRITICAL_MSGF( A, ... )           TgANALYSIS_ASSUME(A);                                                                                                      \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_PrintF( KTgCN_CHANEL_CRITICAL, __VA_ARGS__ );                                                                     \
                                                    tgPM_Abort();                                                                                                          \
                                                };

    #define TgCRITICAL( A )                     TgANALYSIS_ASSUME(A);                                                                                                      \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_Print( KTgCN_CHANEL_CRITICAL, TgT(#A) TgT("\n") );                                                                \
                                                    tgPM_Abort();                                                                                                          \
                                                };
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__CRITICAL */
#else
    #define TgCRITICAL_MSGF( A, ... )           TgANALYSIS_ASSUME(A); ((void)0)
    #define TgCRITICAL_MSG( A, ... )            TgANALYSIS_ASSUME(A); ((void)0)
    #define TgCRITICAL( A )                     TgANALYSIS_ASSUME(A); ((void)0)
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__CRITICAL */
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__ERROR
    /* Asserts are used in release and debug executables when continuing execution is undesirable.  Most often this is the case similar to above, where the executable would
    be in an illegal state.  These are often used for bounds checking.  The difference is that asserts can be used to validate values and quantities during development that
    are "assumed" to be valid in a final build. */
    #define TgERROR_MSG( A, ... )               TgANALYSIS_ASSUME(A);                                                                                                      \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_Print( KTgCN_CHANEL_ERROR, __VA_ARGS__ );                                                                         \
                                                };

    #define TgERROR_MSGF( A, ... )              TgANALYSIS_ASSUME(A);                                                                                                      \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_PrintF( KTgCN_CHANEL_ERROR, __VA_ARGS__ );                                                                        \
                                                };

    #define TgERROR( A )                        TgANALYSIS_ASSUME(A);                                                                                                      \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_PrintF( KTgCN_CHANEL_ERROR, TgT("%-16.16s(%-32.32s): %-64.64s\n"), TgT("SYSTEM"), TgT("ERROR"), TgT(#A) );        \
                                                };

    #define TgERROR_INDEX( A, B )               MSVC_ATTRIBUTE(__analysis_assume((A) < ( sizeof(B) / sizeof((B)[0]) )));                                                   \
                                                if ( ((TgSIZE)(A)) >= ( sizeof(B) / sizeof((B)[0]) ) )                                                                     \
                                                {                                                                                                                          \
                                                    tgCN_PrintF( KTgCN_CHANEL_ERROR, TgT("%-16.16s(%-32.32s): %-64.64s\n"),                                                \
                                                        TgT("SYSTEM"), TgT("ERROR"), TgT("Exceeded array length - ") TgT(#A) );                                            \
                                                };
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__ERROR */
#else
    #define TgERROR_MSGF( A, ... )              TgANALYSIS_ASSUME(A); ((void)0)
    #define TgERROR_MSG( A, ... )               TgANALYSIS_ASSUME(A); ((void)0)
    #define TgERROR( A )                        TgANALYSIS_ASSUME(A); ((void)0)
    #define TgERROR_INDEX( A, B )               MSVC_ATTRIBUTE(__analysis_assume((A) < ( sizeof(B) / sizeof((B)[0]) )))
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__ERROR */
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__PARAM_CHECK
    #define TgPARAM_CHECK_MSGF( A, ... )        TgERROR_MSGF( A, __VA_ARGS__ )
    #define TgPARAM_CHECK_MSG( A, ... )         TgERROR_MSG( A, __VA_ARGS__ )
    #define TgPARAM_CHECK( A )                  TgERROR( A )
    #define TgPARAM_CHECK_INDEX( A, B )         TgERROR_INDEX( A, B )
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__PARAM_CHECK */
#else
    #define TgPARAM_CHECK_MSGF( A, ... )        TgANALYSIS_ASSUME(A); ((void)0)
    #define TgPARAM_CHECK_MSG( A, ... )         TgANALYSIS_ASSUME(A); ((void)0)
    #define TgPARAM_CHECK( A )                  TgANALYSIS_ASSUME(A); ((void)0)
    #define TgPARAM_CHECK_INDEX( A, B )         MSVC_ATTRIBUTE(__analysis_assume((A) < ( sizeof(B) / sizeof((B)[0]) )))
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__PARAM_CHECK */
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__DIAG
    #define TgDIAG_MSG( A, ... )                TgANALYSIS_ASSUME(A);                                                                                                      \
                                                {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if ((TgFALSE == bSkip) && !(A))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_Print( KTgCN_CHANEL_ERROR, __VA_ARGS__ );                                                                     \
                                                    };                                                                                                                     \
                                                };

    #define TgDIAG_MSGF( A, ... )               TgANALYSIS_ASSUME(A);                                                                                                      \
                                                {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if ((TgFALSE == bSkip) && !(A))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_ERROR, __VA_ARGS__ );                                                                    \
                                                    };                                                                                                                     \
                                                };

#define TgDIAG( A )                         TgANALYSIS_ASSUME(A);                                                                                                      \
                                                {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if ((TgFALSE == bSkip) && !(A))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_ERROR, TgT("%-16.16s(%-32.32s): %-64.64s\n"),                                            \
                                                            TgT("SYSTEM"), TgT("DIAG ASSERT"), TgT(#A) );                                                                  \
                                                    };                                                                                                                     \
                                                };
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__DIAG */
#else
    #define TgDIAG_MSGF( A, ... )               TgANALYSIS_ASSUME(A); ((void)0)
    #define TgDIAG_MSG( A, ... )                TgANALYSIS_ASSUME(A); ((void)0)
    #define TgDIAG( A )                         TgANALYSIS_ASSUME(A); ((void)0)
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__DIAG */
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__VERIFY
    #define TgVERIFY_MSG( A, ... )              TgANALYSIS_ASSUME(A);                                                                                                      \
                                                {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if (!(A) && (TgFALSE == bSkip))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_Print( KTgCN_CHANEL_ERROR, __VA_ARGS__ );                                                                     \
                                                    };                                                                                                                     \
                                                };

    #define TgVERIFY_MSGF( A, ... )             TgANALYSIS_ASSUME(A);                                                                                                      \
                                                {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if (!(A) && (TgFALSE == bSkip))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_ERROR, __VA_ARGS__ );                                                                    \
                                                    };                                                                                                                     \
                                                };

    #define TgVERIFY( A )                       TgANALYSIS_ASSUME(A);                                                                                                      \
                                                {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if (!(A) && (TgFALSE == bSkip))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_ERROR, TgT("%-16.16s(%-32.32s): Failed Validation: %-32.32s (File:% 5d) |\n"),           \
                                                            TgT("SYSTEM"), TgT("ERROR"), TgWIDEN(__FUNCTION__), __LINE__ );                                                \
                                                    };                                                                                                                     \
                                                };
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__VERIFY */
#else
    #define TgVERIFY_MSGF( A, ... )             TgANALYSIS_ASSUME(A); ((void)(A))
    #define TgVERIFY_MSG( A, ... )              TgANALYSIS_ASSUME(A); ((void)(A))
    #define TgVERIFY( A )                       TgANALYSIS_ASSUME(A); ((void)(A))
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__VERIFY */
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__WARNING
    /* Warnings are used to communicate potential development issues to the console. */
    #define TgWARNING_MSG( A, ... )             {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if ((TgFALSE == bSkip) && !(A))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_Print( KTgCN_CHANEL_WARNING, __VA_ARGS__ );                                                                   \
                                                    };                                                                                                                     \
                                                };

    #define TgWARNING_MSGF( A, ... )            {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if ((TgFALSE == bSkip) && !(A))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_WARNING, __VA_ARGS__ );                                                                  \
                                                    };                                                                                                                     \
                                                };

    #define TgWARNING( A )                      {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if ((TgFALSE == bSkip) && !(A))                                                                                        \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_WARNING, TgT("%-16.16s(%-32.32s): %-64.64s\n"), TgT("SYSTEM"), TgT("WARNING"), TgT(#A) );\
                                                    };                                                                                                                     \
                                                };
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__WARNING */
#else
    #define TgWARNING_MSGF( A, ... )            ((void)0)
    #define TgWARNING_MSG( A, ... )             ((void)0)
    #define TgWARNING( A )                      ((void)0)
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__WARNING */
#endif

#if TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__MESSAGE
    /* Messages are used to communicate general development information to the console */
    #define TgMSG( L, ... )                     {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if (TgFALSE == bSkip)                                                                                                  \
                                                    {                                                                                                                      \
                                                        tgCN_Print( KTgCN_CHANEL_MESSAGE|L, __VA_ARGS__ );                                                                 \
                                                    };                                                                                                                     \
                                                };

    #define TgMSGF( L, ... )                    {                                                                                                                          \
                                                    static TgBOOL bSkip = TgFALSE;                                                                                         \
                                                    if (TgFALSE == bSkip)                                                                                                  \
                                                    {                                                                                                                      \
                                                        tgCN_PrintF( KTgCN_CHANEL_MESSAGE|L, __VA_ARGS__ );                                                                \
                                                    };                                                                                                                     \
                                                };
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__MESSAGE */
#else
    #define TgMSGF( A, ... )                    ((void)0)
    #define TgMSG( A, ... )                     ((void)0)
/*# TgCOMPILE_ASSERT && TgCOMPILE_ASSERT__MESSAGE */
#endif

#if TgCOMPILE_MEM_TRACK
    #define TgMALLOC_EXACT(A)                   tgMM_Malloc( ETgMM_ALLOCATOR_EXACT, A, TgWIDEN(__FILE__), __LINE__ )
    #define TgFREE__EXACT(A)                    tgMM_Free( ETgMM_ALLOCATOR_EXACT, A, TgWIDEN(__FILE__), __LINE__ )
    #define TgMALLOC_POOL(A)                    tgMM_Malloc_Pool( A, TgWIDEN(__FILE__), __LINE__ )
    #define TgFREE_POOL(A)                      tgMM_Free_Pool( A, TgWIDEN(__FILE__), __LINE__ )
    #define TgREALLOC_POOL(A,B)                 tgMM_Realloc_Pool( A,B, TgWIDEN(__FILE__), __LINE__ )
    #define TgMALLOC_TEMP(A)                    tgMM_Malloc( ETgMM_ALLOCATOR_TEMP, A, TgWIDEN(__FILE__), __LINE__ )
    #define TgFREE_TEMP(A)                      tgMM_Free( ETgMM_ALLOCATOR_TEMP, A, TgWIDEN(__FILE__), __LINE__ )
    #define TgPUSH_SCRATCH(A)                   tgMM_TL_Push_Scratch( A, TgWIDEN(__FILE__), __LINE__ )
    #define TgPOP_SCRATCH(A)                    tgMM_TL_Pop_Scratch( A, TgWIDEN(__FILE__), __LINE__ )
    #define TgRESERVE_VIRTUAL(A)                tgMM_Reserve_Virtual( A, TgWIDEN(__FILE__), __LINE__ )
    #define TgCOMMIT_VIRTUAL(A,B)               tgMM_Commit_Virtual( A,B, TgWIDEN(__FILE__), __LINE__ )
    #define TgFREE_VIRTUAL(A)                   tgMM_Free_Virtual( A, TgWIDEN(__FILE__), __LINE__ )
#else
    #define TgMALLOC_EXACT(A)                   tgMM_Malloc( ETgMM_ALLOCATOR_EXACT, A )
    #define TgFREE__EXACT(A)                    tgMM_Free( ETgMM_ALLOCATOR_EXACT, A )
    #define TgMALLOC_POOL(A)                    tgMM_Malloc_Pool( A )
    #define TgFREE_POOL(A)                      tgMM_Free_Pool( A )
    #define TgREALLOC_POOL(A,B)                 tgMM_Realloc_Pool( A,B )
    #define TgMALLOC_TEMP(A)                    tgMM_Malloc( ETgMM_ALLOCATOR_TEMP, A )
    #define TgFREE_TEMP(A)                      tgMM_Free( ETgMM_ALLOCATOR_TEMP, A )
    #define TgPUSH_SCRATCH(A)                   tgMM_TL_Push_Scratch( A )
    #define TgPOP_SCRATCH(A)                    tgMM_TL_Pop_Scratch( A )
    #define TgRESERVE_VIRTUAL(A)                tgMM_Reserve_Virtual( A )
    #define TgCOMMIT_VIRTUAL(A,B)               tgMM_Commit_Virtual( A,B )
    #define TgFREE_VIRTUAL(A)                   tgMM_Free_Virtual( A )
#endif


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Base TgS RESULT Values                                                                                                                                                */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define MAKE_TgRESULT(fac,code)             ((TgSINT32) (((TgRESULT)(fac)<<16) | ((TgRESULT)(code))))
#define MAKE_ERROR(A,B)                     CTgERROR( TgWIDEN(__FILE__), __LINE__, A, B )

/* 64 Libraries, 256 Classes per Library, 262144 Functions per Class - 32 bits to describe overloads/parameters */
#define MAKE_CODE(lib,cls,fcn,pm)           ((TgUINT64) (((TgUINT64)(lib)) | ((TgUINT64)(cls) >> 6) | ((TgUINT64)(fcn) >> 14) | ((TgUINT64)(pm) >> 32) ))

#define TM_TIMER                            1L
#define TIME_MAXITERATIONS                  7


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Code Helpers                                                                                                                                                          */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define TgSUCCEEDED(Status)                 ((TgSINT32)(Status) >= 0)
#define TgFAILED(Status)                    ((TgSINT32)(Status) <  0)

#define TgTYPE_PREFIX_INTERNAL(B)           typedef const B                                 C_##B;                                                             \
                                            typedef B *                                     P_##B;                                                             \
                                            typedef const B *                               CP_##B;                                                            \
                                            typedef B * const                               PC_##B;                                                            \
                                            typedef const B * const                         CPC_##B;                                                           \
                                            typedef B**                                     PP_##B;                                                            \
                                            typedef const B **                              CPP_##B;                                                           \
                                            typedef B ** const                              PPC_##B;                                                           \
                                            typedef const B *const *                        CPCP_##B;                                                          \
                                                                                                                                                                           \
                                            typedef B * __restrict                          PU_##B;                                                            \
                                            typedef const B * __restrict                    CPU_##B;                                                           \
                                            typedef B * const __restrict                    PCU_##B;                                                           \
                                            typedef const B * const __restrict              CPCU_##B;                                                          \
                                            typedef B ** __restrict                         PPU_##B;                                                           \
                                            typedef const B ** __restrict                   CPPU_##B;                                                          \
                                            typedef B ** const __restrict                   PPCU_##B;                                                          \
                                            typedef const B *const * __restrict             CPCPU_##B

#define TgTYPE_DECLARE(A,B)                 typedef A                                   B;                                                                                 \
                                            TgTYPE_PREFIX_INTERNAL( B )

#define TgTYPE_PREFIX(A)                    TgTYPE_PREFIX_INTERNAL( A )

#define TgTYPE_STRUCT(A, ...)               typedef struct A                            A;                                                                                 \
                                            TgTYPE_PREFIX_INTERNAL( A );                                                                                                   \
                                            __VA_ARGS__ struct A

#define TgTYPE_UNION(A, ...)                typedef union A                             A;                                                                                 \
                                            TgTYPE_PREFIX_INTERNAL( A );                                                                                                   \
                                            __VA_ARGS__ union A

#define TgTYPE_STRUCT_ALIGN(A,B,...)        typedef struct TgALIGN(B) A                            A;                                                                                 \
                                            TgTYPE_PREFIX_INTERNAL( A );                                                                                                   \
                                            __VA_ARGS__ struct TgALIGN(B) A

#define TgTYPE_UNION_ALIGN(A,B,...)         typedef union TgALIGN(B) A                             A;                                                                                 \
                                            TgTYPE_PREFIX_INTERNAL( A );                                                                                                   \
                                            __VA_ARGS__ union TgALIGN(B) A

#define TgTYPE_ENUM(A,B,...)                typedef enum                                                                                                                   \
                                            {                                                                                                                              \
                                                __VA_ARGS__                                                                                                                \
                                            } A;                                                                                                                           \
                                            TgTYPE_PREFIX( A )

#define TgFOURCC(ch0, ch1, ch2, ch3)        (((TgUINT32)(TgUINT08)(ch0)      ) | ((TgUINT32)(TgUINT08)(ch1) << 8  ) | \
                                             ((TgUINT32)(TgUINT08)(ch2) << 16) | ((TgUINT32)(TgUINT08)(ch3) << 24 ))

#if TgCOMPILE_LITTLE_ENDIAN
#define TgKI_DECLARE_STRUCT(A)                                                                                                                                             \
    typedef struct                                                                                                                                                         \
    {                                                                                                                                                                      \
        volatile TgATOMIC_SINT32                    iK;                                                                                                                    \
        volatile TgATOMIC_SINT32                    iI;                                                                                                                    \
    } Tg##A##_ELEM;
#else
#define TgKI_DECLARE_STRUCT(A)                                                                                                                                             \
    typedef struct                                                                                                                                                         \
    {                                                                                                                                                                      \
        volatile TgATOMIC_SINT32                    iI;                                                                                                                    \
        volatile TgATOMIC_SINT32                    iK;                                                                                                                    \
    } Tg##A##_ELEM;
#endif

#define TgKI_DECLARE_TYPE(A)                                                                                                                                               \
                                                                                                                                                                           \
    TgKI_DECLARE_STRUCT(A)                                                                                                                                                 \
    typedef union                                                                                                                                                          \
    {                                                                                                                                                                      \
        volatile TgATOMIC_SINT64 m_iKI;                                                                                                                                    \
        Tg##A##_ELEM m;                                                                                                                                                    \
    } Tg##A;                                                                                                                                                               \
                                                                                                                                                                           \
    TgTYPE_PREFIX( Tg##A );

#define TgKI_DECLARE_DATA(A)                                                                                                                                               \
                                                                                                                                                                           \
    TgEXTN volatile TgATOMIC_SINT32 tgKI_NUI_##A;                                                                                                                          \
    TgEXTN C_Tg##A KTg##A##__INVALID;

#define TgKI_DEFINE_FUNC(A)                                                                                                                                                \
                                                                                                                                                                           \
    TgFORCEINLINE TgVOID tgInit_##A( PCU_Tg##A psKI, C_TgSINT32 iI )                                                                                                       \
    {                                                                                                                                                                      \
        psKI->m.iK = tgAM32_INC(&tgKI_NUI_##A);                                                                                                                            \
        psKI->m.iI = iI;                                                                                                                                                   \
    }                                                                                                                                                                      \
                                                                                                                                                                           \
    TgFORCEINLINE TgBOOL tgEQ_##A( C_Tg##A psK0, C_Tg##A psK1 )                                                                                                            \
    {                                                                                                                                                                      \
        return (psK0.m_iKI == psK1.m_iKI ? TgTRUE : TgFALSE);                                                                                                              \
    }                                                                                                                                                                      \
                                                                                                                                                                           \
    TgFORCEINLINE TgBOOL tg##A##_Is_Valid( C_Tg##A psK0 )                                                                                                                  \
    {                                                                                                                                                                      \
        return (psK0.m_iKI != ~0LL ? TgTRUE : TgFALSE);                                                                                                                    \
    }                                                                                                                                                                      \


#define TgKI_DECLARE(A)                                                                                                                                                    \
                                                                                                                                                                           \
    TgKI_DECLARE_TYPE(A)                                                                                                                                                   \
    TgKI_DECLARE_DATA(A)                                                                                                                                                   \
    TgKI_DEFINE_FUNC(A)

#define TgKI_DEFINE(A)                                                                                                                                                     \
    volatile TgATOMIC_SINT32 tgKI_NUI_##A;                                                                                                                                 \
    C_Tg##A KTg##A##__INVALID = { ~0LL }

#if defined(TgCOMPILE_WIDE_CHAR)
    #define TgT( A )                            L##A
    #define TgTEXT( A )                         L##A
#else
    #define TgT( A )                            A
    #define TgTEXT( A )                         A
#endif
#define TgWIDEN( A )                        TgT(A)
#define TgTO_TEXT( A )                      TgTEXT(#A)

#define TgTEST_MSG( A, ... )                {                                                                                                                              \
                                                if (!(A))                                                                                                                  \
                                                {                                                                                                                          \
                                                    tgCN_Print( KTgCN_CHANEL_ERROR, TgT("FAILED: ") TgT(#A) TgT("\n") );                                                   \
                                                    tgPM_Break();                                                                                                          \
                                                }                                                                                                                          \
                                                else                                                                                                                       \
                                                {                                                                                                                          \
                                                    tgCN_Print( KTgCN_CHANEL_MESSAGE, TgT("PASSED: ") TgT(#A) TgT("\n") );                                                 \
                                                };                                                                                                                         \
                                            };


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Optimization Macros                                                                                                                                                   */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

/* Optimizer Hints */
#if !defined(TgS_NO_DEFAULT)
#if TgCOMPILE_ASSERT
    #define TgS_NO_DEFAULT(...) TgCRITICAL(0); __VA_ARGS__
#else
    #define TgS_NO_DEFAULT(...) __VA_ARGS__
#endif
#endif


/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Macro Existance Check                                                                                                                                                 */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#if !defined(TgCOMPILE_LITTLE_ENDIAN)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_SYSTEM_INFORMATION)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_BASE_API_PLATFORM)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_THREAD)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_THREAD_INFO)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_THREAD_LOCAL)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_FLOAT64)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_64BIT_ATOMIC)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_64BIT_POINTER) || !defined(TgCOMPILE_32BIT_POINTER)
#error Token Undefined
#endif

#if TgCOMPILE_64BIT_POINTER && TgCOMPILE_32BIT_POINTER
#error Both Pointer Sizes can not be valid at the same time
#endif

#if TgCOMPILE_64BIT_POINTER
    #define TgCOMPILE_POINTER_SIZE              8
#elif TgCOMPILE_32BIT_POINTER
    #define TgCOMPILE_POINTER_SIZE              4
#else
    #error Unsupported pointer size
#endif

#if !defined(TgCOMPILE_MEM_TRACK)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__CRITICAL)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__ERROR)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__PARAM_CHECK)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__DIAG)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__VERIFY)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__WARNING)
#error Token Undefined
#endif

#if !defined(TgCOMPILE_ASSERT__MESSAGE)
#error Token Undefined
#endif

#if defined(TgCOMPILE_FORCE_ANSI)
    #if defined(TgCOMPILE_WIDE_CHAR)
    #error Illegal for ANSI C
    #endif
#endif

TgCOMPILER_ASSERT( sizeof( void* ) == TgCOMPILE_POINTER_SIZE, 0 );


/* ====================================================================================================================================================================== */
#endif