Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Base - Type.inl
    »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_TYPES_INL)
#define TGS_COMMON_BASE_TYPES_INL
#pragma once


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

/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */
/*  Public Functions                                                                                                                                                      */
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. */

#define BITFIELD_IMPL( CLASS, TYPE, SIZE ) \
TgINLINE TgVOID tgBF_Set_Flag_##CLASS ( PCU_##TYPE ptyBF, C_TgUINT32 uiFlag, C_TgBOOL bFlag ) { \
        TgERROR( uiFlag < SIZE ); \
        *ptyBF = (TYPE)((TgFALSE != bFlag) ? (*ptyBF | (1<<uiFlag)) : (*ptyBF & ~(1<<uiFlag))); \
    } \
TgINLINE TgVOID tgBF_Toggle_Flag_##CLASS ( PCU_##TYPE ptyBF, C_TgUINT32 uiFlag ) { \
        TgERROR( uiFlag < SIZE ); \
        *ptyBF ^= (TYPE)(1<<uiFlag); \
    } \
TgINLINE TgBOOL tgBF_Query_Flag_##CLASS ( CPCU_##TYPE ptyBF, C_TgUINT32 uiFlag ) { \
        TgERROR( uiFlag < SIZE ); \
        return ((0 != (*ptyBF & (1<<uiFlag))) ? TgTRUE : TgFALSE); \
    } \
TgINLINE TgVOID tgBF_Reset_##CLASS ( PCU_##TYPE ptyBF ) { *ptyBF = 0; }

BITFIELD_IMPL( U08, TgUINT08, 8 )
BITFIELD_IMPL( U16, TgUINT16, 16 )
BITFIELD_IMPL( U32, TgUINT32, 32 )

#undef BITFIELD_IMPL

/* ---- tgBF_Set_Flag_U64 ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgBF_Set_Flag_U64( PCU_TgUINT64 ptyBF, C_TgUINT32 uiFlag, C_TgBOOL bFlag )
{
    TgERROR(uiFlag < 64);
    *ptyBF = bFlag ? (*ptyBF | (1ULL << uiFlag)) : (*ptyBF & ~(1ULL << uiFlag));
}


/* ---- tgBF_Toggle_Flag_U64 -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgBF_Toggle_Flag_U64( PCU_TgUINT64 ptyBF, C_TgUINT32 uiFlag )
{
    TgERROR(uiFlag < 64);
    *ptyBF ^= (1ULL << uiFlag);
}


/* ---- tgBF_Query_Flag_U64 --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgBF_Query_Flag_U64( CPCU_TgUINT64 ptyBF, C_TgUINT32 uiFlag )
{
    TgERROR(uiFlag < 64);
    return ((0ULL != (*ptyBF & (1ULL << uiFlag))) ? TgTRUE : TgFALSE);
}


/* ---- tgBF_Reset_U64 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgBF_Reset_U64( PCU_TgUINT64 ptyBF )
{
    *ptyBF = 0ULL;
}


/* ---- tgBF_Set_Flag_UXX ----------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgBF_Set_Flag_UXX( PCU_TgUINTXX ptyBF, C_TgUINT32 uiFlag, C_TgBOOL bFlag )
{
    TgERROR(uiFlag < 8 * sizeof( TgUINTXX ));
    *ptyBF = bFlag ? (*ptyBF | (((TgUINTXX)1) << uiFlag)) : (*ptyBF & ~(((TgUINTXX)1) << uiFlag));
}


/* ---- tgBF_Toggle_Flag_UXX -------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgBF_Toggle_Flag_UXX( PCU_TgUINTXX ptyBF, C_TgUINT32 uiFlag )
{
    TgERROR(uiFlag < 8 * sizeof( TgUINTXX ));
    *ptyBF ^= (((TgUINTXX)1) << uiFlag);
}


/* ---- tgBF_Query_Flag_UXX --------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL tgBF_Query_Flag_UXX( CPCU_TgUINTXX ptyBF, C_TgUINT32 uiFlag )
{
    TgERROR(uiFlag < 8 * sizeof( TgUINTXX ));
    return ((((TgUINTXX)0) != (*ptyBF & (((TgUINTXX)1) << uiFlag))) ? TgTRUE : TgFALSE);
}


/* ---- tgBF_Reset_UXX -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgBF_Reset_UXX( PCU_TgUINTXX ptyBF )
{
    *ptyBF = ((TgUINTXX)0);
}


/* ---- tgPath_Check_File_Block_With_Assert ----------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVOID tgPath_Check_File_Block_With_Assert( CPCU_STg2_File_Block psFB )
{
    TgERROR(TgFOURCC( 'T', 'G', 'S', 'F' ) == psFB->m_uiFourCC);
    TgERROR(sizeof( STg2_File_Block ) == psFB->m_uiSize);
    TgERROR(0x01 == psFB->m_uiVersion);
    TgERROR(0x01 == psFB->m_uiSection_Version);
    TgERROR(sizeof( STg2_File_Section ) == psFB->m_uiSection_Size);
}


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