📄 mmulist.cpp
字号:
/*\t*******************************************************************/
/* Creation Date ....... Thu 05-20-1993 12:52:35 */
/* Filename ........... mmulist.cpp */
/* Project ............. Memory Management */
/* Author ............. Matthew J. W. Ratcliff */
/* Language ........... C++ */
/* Operating System ... DOS/Windows */
/* Processor .......... MMU - Memory Management Utilities */
/* Function: Linked list package. */
/* */
/* Matthew Ratcliff's linked list class definitions. There are NO */
/* INHERENT LIMITATIONS to this doubly linked list class. Can't say */
/* that about most other link list functions provided by Microsoft & */
/* Borland libraries. */
/* */
/* As of July 1994 I have over 150,000 lines of Windows & DOS */
/* application C++ software that depend on this linked list class and */
/* its subclasses. It works flawlessly. It has been used in a Windoz*/
/* file viewer utility to view the entire contents of an ASCII file */
/* containing 560 character lines, a total of 14 megabytes in size! */
/* Try that with your Borland or Microsoft tools! */
/* */
/*\t*******************************************************************/
/*\r********************************************************************
** Revision History
***********************************************************************/
/*
Date By Change Description
dd-mmm-yy nnn text
--------- ---- -----------------------------------------------
20-May-93 MJWR Implement C++ linked list package.
**\r*/
/*\i********************************************************************
** Module Include Files
***********************************************************************/
/*********************** System Include Files *************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/********************** Constant Include Files ************************/
#include "liidSys.h"
#include "mmplist.h"
#include "mmglist.h"
/***************** External Variable Include Files ********************/
/***************** External Procedure Include Files *******************/
#include "mmulist.h"
/*\i*/
/*\m********************************************************************
** Module Declarations
***********************************************************************/
/************************* Module Constants ***************************/
/************************* Module Variables ***************************/
/************************* Module Procedures **************************/
/*\m*/
/*\p********************************************************************
** **
** **
NAME: MMUllist::MMUllist
PURPOSE: to construct a linked list.
** **
** **
**\p*******************************************************************/
MMUllist::MMUllist()
{ /* MMUllist::MMUllist procedure */
/******************* Local Constant Declarations **********************/
/* Proc name for error log */
//CHARPTR MML_PROC_NAME = "MMUllist::MMUllist";
/******************* Local Variable Declarations **********************/
/************************* Procedure Body *****************************/
head = NULL;
tail = NULL;
current = NULL;
numEntries = 0L;
} /* MMUllist::MMUllist end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::~MMUllist
PURPOSE: to destroy an existing list.
** **
** **
**\p*******************************************************************/
MMUllist::~MMUllist()
{ /* MMUllist::~MMUllist procedure */
/******************* Local Constant Declarations **********************/
/* Proc name for error log */
//CHARPTR MML_PROC_NAME = "MMUllist::~MMUllist";
/******************* Local Variable Declarations **********************/
/************************* Procedure Body *****************************/
if (numEntries != 0L)
{
DeleteList();
}
} /* MMUllist::~MMUllist end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::mmuSetFirstEntry
PURPOSE: to set the first entry in the list.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** mmlErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE MMUllist::mmuSetFirstEntry( MMG_LLIST_TY *pasEntry )
{ /* MMUllist::mmuSetFirstEntry procedure */
/******************* Local Constant Declarations **********************/
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE mmlErr;
/************************* Procedure Body *****************************/
/* Initialize return val */
mmlErr = SUCCEEDED_;
numEntries = 1L;
pasEntry->prev = NULL;
pasEntry->next = NULL;
current = pasEntry;
head = current;
tail = current;
return(mmlErr);
} /* MMUllist::mmuSetFirstEntry end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::mmuCreateEntry
PURPOSE: to create storage for a new entry and return a pointer
to it. If unable to allocate the storage, return a NULL
pointer.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** mmlPtr FNC MMG_LLIST_TY *, new buffer dude. **
**\p*******************************************************************/
MMG_LLIST_TY *MMUllist::mmuCreateEntry( INT32 pasSizeofBuf,
void *pasBufPtr )
{ /* mmuCreateEntry procedure */
/******************* Local Constant Declarations **********************/
/******************* Local Variable Declarations **********************/
MMG_LLIST_TY *mmlPtr;
/************************* Procedure Body *****************************/
mmlPtr = NULL;
if (pasSizeofBuf > 0 && pasBufPtr != NULL)
{
mmlPtr = new MMG_LLIST_TY;
if (mmlPtr)
{
mmlPtr->prev = NULL;
mmlPtr->next = NULL;
mmlPtr->buf.size = pasSizeofBuf;
mmlPtr->buf.body = new char[(unsigned)pasSizeofBuf];
if (mmlPtr->buf.body)
{
memcpy(mmlPtr->buf.body, pasBufPtr, (unsigned)pasSizeofBuf);
}
}
}
return(mmlPtr);
} /* mmuCreateEntry end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::mmuDestroyEntry
PURPOSE: to destroy an existing list entry.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** mmlErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE MMUllist::mmuDestroyEntry( MMG_LLIST_TY *refEntry )
{ /* mmuDestroyEntry procedure */
/******************* Local Constant Declarations **********************/
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE mmlErr;
/************************* Procedure Body *****************************/
/* Initialize return val */
mmlErr = FAILED_;
if (refEntry != NULL)
{
mmlErr = SUCCEEDED_;
if (refEntry->buf.body)
{
LIMDELA(refEntry->buf.body);
refEntry->buf.body = NULL;
}
LIMDEL(refEntry);
}
return(mmlErr);
} /* mmuDestroyEntry end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::InsertBeforeHead
PURPOSE: to insert a new entry before the head of the list.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** mmlErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE MMUllist::InsertBeforeHead( MMP_DATA_TY &pasEntry )
{ /* MMUllist::InsertBeforeHead procedure */
/******************* Local Constant Declarations **********************/
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE mmlErr;
/************************* Procedure Body *****************************/
mmlErr = InsertBeforeHead( pasEntry.size, pasEntry.body );
return(mmlErr);
} /* MMUllist::InsertBeforeHead end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::AppendAfterTail
PURPOSE: to insert a new entry after the end of the list.
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** mmlErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE MMUllist::AppendAfterTail( MMP_DATA_TY &pasEntry )
{ /* MMUllist::AppendAfterTail procedure */
/******************* Local Constant Declarations **********************/
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE mmlErr;
/************************* Procedure Body *****************************/
mmlErr = AppendAfterTail( pasEntry.size, pasEntry.body );
return(mmlErr);
} /* MMUllist::AppendAfterTail end */
/*\p********************************************************************
** **
** **
NAME: MMUllist::InsertBeforeCurrent
PURPOSE: to insert a new entry before the current entry
in the list
** **
** **
** INTERFACE DEFINITION: **
** variable def. expected/description **
** ------------ ----- ------------------------------------- **
** mmlErr FNC (SUCCEEDED_ / FAILED_) error return **
**\p*******************************************************************/
STAT_TYPE MMUllist::InsertBeforeCurrent( MMP_DATA_TY &pasEntry )
{ /* MMUllist::InsertBeforeCurrent procedure */
/******************* Local Constant Declarations **********************/
/******************* Local Variable Declarations **********************/
/* error return flag */
STAT_TYPE mmlErr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -