
/***************************************************************************
**
**    $Header:   D:/EPSLDV1/SRC/LOG/MEMPOOL.H__   1.8   20 Jun 1996 09:28:32   ZJRD  $
**
**    $Log:   D:/EPSLDV1/SRC/LOG/MEMPOOL.H__  $
** 
**    Rev 1.8   20 Jun 1996 09:28:32   ZJRD
** EasyPack/SLD Version 1.20a
** 
**    Rev 1.6   10 Jun 1996 10:23:10   ZJRD
** EasyPack/SLD Version 1.20
** 
**    Rev 1.4   29 May 1996 09:34:18   ZJRD
** No change.
** 
**    Rev 1.3   16 May 1996 09:02:52   ZJRD
** No change.
** 
**    Rev 1.2   10 May 1996 09:14:26   ZJRD
** No change.
** 
**    Rev 1.1   02 May 1996 10:29:18   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.31   18 Apr 1996 12:58:32   Shirley
** No change.
** 
**    Rev 1.30   12 Apr 1996 10:42:14   Shirley
** EasyPack/SLD Version 1.90
** 
**    Rev 1.28   15 Feb 1996 08:57:14   Shirley
** No change.
** 
**    Rev 1.27   12 Feb 1996 14:08:36   Shirley
** No change.
** 
**    Rev 1.26   06 Feb 1996 15:35:02   Shirley
** No change.
** 
**    Rev 1.25   06 Feb 1996 13:49:20   Shirley
** No change.
** 
**    Rev 1.24   01 Feb 1996 10:15:22   Shirley
** No change.
** 
**    Rev 1.23   26 Jan 1996 09:18:46   Shirley
** No change.
** 
**    Rev 1.22   25 Jan 1996 13:18:40   Shirley
** No change.
** 
**    Rev 1.21   24 Jan 1996 10:34:52   Shirley
** No change.
** 
**    Rev 1.20   23 Jan 1996 11:25:40   Shirley
** No change.
** 
**    Rev 1.19   18 Jan 1996 10:07:46   Shirley
** No change.
** 
**    Rev 1.18   15 Jan 1996 16:16:38   Shirley
** No change.
** 
**    Rev 1.17   04 Jan 1996 11:08:44   Shirley
** No change.
** 
**    Rev 1.16   30 Nov 1995 09:11:26   Shirley
** No change.
** 
**    Rev 1.15   28 Nov 1995 15:32:04   Shirley
** No change.
** 
**    Rev 1.14   21 Nov 1995 11:18:56   Shirley
** No change.
** 
**    Rev 1.13   13 Nov 1995 09:23:10   Shirley
** No change.
** 
**    Rev 1.12   12 Nov 1995 11:34:04   Shirley
** No change.
** 
**    Rev 1.11   08 Nov 1995 16:34:32   Shirley
** No change.
** 
**    Rev 1.10   08 Nov 1995 12:44:26   Shirley
** No change.
** 
**    Rev 1.9   02 Nov 1995 10:05:54   Shirley
** No change.
** 
**    Rev 1.8   27 Oct 1995 16:48:04   Shirley
** No change.
** 
**    Rev 1.7   27 Oct 1995 13:46:08   Shirley
** No change.
** 
**    Rev 1.6   25 Oct 1995 14:30:18   Shirley
** No change.
** 
**    Rev 1.5   18 Oct 1995 14:51:42   Shirley
** No change.
** 
**    Rev 1.4   13 Oct 1995 13:20:18   Shirley
** No change.
** 
**    Rev 1.3   29 Sep 1995 09:49:36   Shirley
** No change.
** 
**    Rev 1.2   20 Sep 1995 10:55:54   Shirley
** No change.
** 
**    Rev 1.1   15 Sep 1995 09:46:04   Shirley
** No change.
** 
**    Rev 1.0   07 Sep 1995 09:54:52   Shirley
** Initial revision.
**
****************************************************************************/

/*----------------------------------------------------------------------------
** Name: mempool.h
**
** Title: Memory Pool
**
** Purpose:
**  Define the interface for the Memory Pool routines; generic routines used
**  to create, expand, and put data into an expandable pool of memory.
**
** Status: PRELIMINARY
**
** $Log$
** 
** $Header:   D:/EPSLDV1/SRC/LOG/MEMPOOL.H__   1.8   20 Jun 1996 09:28:32   ZJRD  $
**
** Copyright (C) 1995 Microtek International.  All rights reserved.
**
**--------------------------------------------------------------------------*/

#ifndef _MEMPOOL_

                       /****************************
                        *                          *
                        *       INCLUDE FILES      *
                        *                          *
                        ****************************/
#include "memmanag.h"
#include "symutil.h"

                       /****************************
                        *                          *
                        *        DEFINITIONS       *
                        *                          *
                        ****************************/


                       /**********************************
                        *                                *
                        *   MEMBER FUNCTION PROTOTYPES   *
                        *                                *
                        **********************************/
#ifdef __cplusplus
class MemPool : public Table {

private:
   TABLE_OFFSET availMemOffset;   //acts as pointer to start of available mem
                                  //also equals the number of bytes used
   U16 bytesThrownAway;           //measurement of memory loss

public:
//---------------------------------------------------------------------------
// MemPool constructor
//
// Purpose:
//    Initialize specific table variables for memory management.
//    Insert one byte so that any pointers to table will be non-zero;
//    i.e. non-NULL
//---------------------------------------------------------------------------
MemPool();    // constructor


//------------------------------------------------------------------------
// AllocBytes
//
// Purpose:
//    Allocate 1 to 255 bytes into table.  Returns offset to start of data.
//
// Input parameters:
//    size: number of bytes
//
// Output parameters:
//    tableDataOffset: offset to start of stored bytes.
//
// Error: Reports ER_MEM_OUT_OF_MEMORY if there is not enough memory
//        to hold data
//------------------------------------------------------------------------
RETCODE AllocBytes(U8 size, TABLE_OFFSET& tableDataOffset);


//------------------------------------------------------------------------
// IsValidTableOffset
//
// Purpose:
//    Checks that the input table offset is not larger that the memory
//    allocated in the table thus far.
//
// Input parameters:
//    tableDataOffset: value to be compared with end of memory offset pointer
//
// Output parameters:  returns FALSE if not valid, TRUE if valid
//------------------------------------------------------------------------
BOOLEAN IsValidTableOffset(TABLE_OFFSET tableDataOffset)   {
   return (BOOLEAN)((tableDataOffset >= availMemOffset) ? FALSE : TRUE);
}


//---------------------------------------------------------------------------
// GetAvailMemOffset
//
// Purpose:
//    Return the value of the variable that points to the next available
//    location in the table to add data.
//---------------------------------------------------------------------------
TABLE_OFFSET GetAvailMemOffset() {return availMemOffset;};


//---------------------------------------------------------------------------
// GetBytesThrownAway
//
// Purpose:
//    FOR TESTING.
//    Return the value of the variable holding the number of bytes that were
//    "discarded" when it crossed the allocated boundary (which required
//    ReAlloc)
//---------------------------------------------------------------------------
U16 GetBytesThrownAway() { return bytesThrownAway; };


//---------------------------------------------------------------------------
// GetString
//
// Purpose:
//    Get a name from the symbol table and return it in a standard C string
//    The internal name format is the PASCAL string format:
//        length (U8) followed by that number of characters
//
// Input:
//    tableDataOffset: offset into symbol table
//
// Output:
//    outputString: far pointer to U8 holding the string; max length is 255
//                  256 with NULL termination
//---------------------------------------------------------------------------
VOID GetString(TABLE_OFFSET tableDataOffset, LPU8 outputString);


//---------------------------------------------------------------------------
// ObliterateTable
//
// Purpose:
//    Unlocks, then frees the table to Windows memory.
//---------------------------------------------------------------------------
VOID ObliterateTable(VOID);


//------------------------------------------------------------------------
// PutBytes
//
// Purpose:
//    Insert 1 to 255 bytes into table.  Returns offset to start of data.
//    This routine is used for putting structures into the table by passing
//    a pointer to the structure with size = sizeof(struct).
//
// Input parameters:
//    inputDataPtr: pointer to data.
//    size: number of bytes
//
// Output parameters:
//    tableDataOffset: offset to start of stored bytes.
//
// Error: Reports ER_MEM_OUT_OF_MEMORY if there is not enough memory
//        to hold data
//------------------------------------------------------------------------
RETCODE PutBytes(U8 *inputDataPtr, U8 size,
                    TABLE_OFFSET& tableDataOffset);


//------------------------------------------------------------------------
// PutString
//
// Purpose:
//    Insert string into table.  The maximum storable string is 255 chars.
//    Any string longer will be truncated with no error.
//    The representation of the string is: length, string
//    The stored string is NOT null terminated; rather, the length is the
//    first byte.  This makes string compares much faster (length checked
//    first).
//
// Input parameters:
//    lpString: long pointer to string.  Must be null terminated.
//
// Output parameters:
//    tableDataOffset: offset to start of stored string.  Points to length.
//
// Error: Reports STRING_LENGTH_0 if string is length 0
//        Reports ER_MEM_OUT_OF_MEMORY if there is not enough memory
//        to hold string
//------------------------------------------------------------------------
RETCODE PutString(LPSTR lpString, TABLE_OFFSET& tableDataOffset);


//------------------------------------------------------------------------
// PutU32
//
// Purpose:
//    install a U32 into the table
//------------------------------------------------------------------------
RETCODE PutU32(U32 data);


//---------------------------------------------------------------------------
// SetAvailableMem
//
// Purpose:
//    TESTING ONLY!!  Positions the unused memory pointer to a new location.
//---------------------------------------------------------------------------
VOID SetAvailableMem(U32 setValue) {
	availMemOffset = min(setValue, tableSize);
}

};  // end of class MemPool
#endif

#define _MEMPOOL_
#endif
/******************************** E O F *************************************/
