Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Base - Type [IO].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_TYPE_IO_H)
#define TGS_COMMON_BASE_TYPE_IO_H
#pragma once


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

/* ---- STg2_Input ------------------------------------------------------------------------------------------------------------------------------------------------------ */

TgTYPE_STRUCT(STg2_Input,)
{
    TgSIZE                                      (*m_pfnRead)( PC_STg2_Input, C_TgSIZE, P_TgVOID, C_TgSIZE ); /*« Read up to some bytes from offset, return bytes read. */
    TgBOOL                                      (*m_pfnEnd_Of_File)( PC_STg2_Input, C_TgSIZE ); /*« Tests to see if input is complete */
    TgVOID                                      (*m_pfnClose)( PC_STg2_Input ); /*« Close the object */

#if !defined(TGS_FINAL)
    CP_TgCHAR                                   m_pszName; /*« Used in non-final builds to describe | identify the location of the input */
/*# !defined(TGS_FINAL) */
#endif
};


TgINLINE TgSIZE                             tgIO_Read_Line( PC_STg2_Input, C_TgSIZE, PC_TgCHAR, C_TgSIZE );


/* ---- STg2_Output ----------------------------------------------------------------------------------------------------------------------------------------------------- */

TgTYPE_STRUCT(STg2_Output,)
{
    TgSIZE                                      (*m_pfnWrite)( PC_STg2_Output, C_TgSIZE, CP_TgVOID, C_TgSIZE ); /*« Writes out count of bytes at offset */
    TgVOID                                      (*m_pfnClose)( PC_STg2_Output ); /*« Close the object */
};


TgINLINE TgSINT32                           tgIO_Print( PC_STg2_Output, CPC_TgCHAR );
TgEXTN TgSINT32                             tgIO_PrintF( PC_STg2_Output, CPC_TgCHAR, ... ); /*« R+: Number of characters printed, R-: Error code */


/* ---- STg2_Input_MEM -------------------------------------------------------------------------------------------------------------------------------------------------- */

TgTYPE_STRUCT(STg2_Input_MEM,)
{
    STg2_Input                                  m_sInput;

                                                /* 1: Return value holding the pointer to the memory block */
                                                /* 2: Size of the memory block expected */
                                                /* 3: Input Memory structure */
                                                /* 4: Offset */
    TgSIZE                                      (*m_pfnBind)( PP_TgVOID, C_TgSIZE, PC_STg2_Input_MEM, C_TgSIZE ); /*« Used to do an "in place" memory assignment */

    TgSIZE                                      m_uiSize; /*« Maximum size of the input buffer */
    CP_TgVOID                                   m_pData; /*« Memory buffer bound to this instantiation */
    TgFCN_MEM_FREE                              m_pfnFree;
};


                                            /* 1: Pointer to the output structure to be initialized */
                                            /* 2: Pointer to the data buffer */
                                            /* 3: Size of the data buffer */
                                            /* 4: Pointer to a freeing function for the buffer.  nullptr is valid. */
TgINLINE TgVOID                             tgIO_IM_Open( PC_STg2_Input_MEM, CP_TgVOID, C_TgSIZE, TgFCN_MEM_FREE );
TgINLINE TgVOID                             tgIO_IM_Close( PC_STg2_Input );
TgINLINE TgSIZE                             tgIO_IM_Size( PC_STg2_Input_MEM );

TgINLINE TgSIZE                             tgIO_IM_Read( PC_STg2_Input, C_TgSIZE, P_TgVOID, C_TgSIZE );
TgINLINE TgBOOL                             tgIO_IM_End_Of_File( PC_STg2_Input, C_TgSIZE );


/* ---- STg2_Output_MEM ------------------------------------------------------------------------------------------------------------------------------------------------- */

TgTYPE_STRUCT(STg2_Output_MEM,)
{
    STg2_Output                                 m_sOutput;

    TgSIZE                                      m_uiSize_Current; /*« Current size of the output buffer */
    TgSIZE                                      m_uiSize; /*« Maximum size of the output buffer */
    P_TgUINT08                                  m_pData; /*« Memory buffer bound to this instantiation */
    TgFCN_MEM_FREE                              m_pfnFree;
};


                                            /* 1: Pointer to the output structure to be initialized */
                                            /* 2: Pointer to the data buffer */
                                            /* 3: Size of the data buffer */
                                            /* 4: Pointer to a freeing function for the buffer.  nullptr is valid. */
TgINLINE TgVOID                             tgIO_OM_Open( PC_STg2_Output_MEM, P_TgVOID, C_TgSIZE, TgFCN_MEM_FREE );
TgINLINE TgVOID                             tgIO_OM_Close( PC_STg2_Output );
TgINLINE CP_TgUINT08                        tgIO_OM_Query_Data( PC_STg2_Output_MEM );

TgINLINE TgSIZE                             tgIO_OM_Write( PC_STg2_Output, C_TgSIZE, CP_TgVOID, C_TgSIZE );


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