home *** CD-ROM | disk | FTP | other *** search
-
- #if defined (CMEMLIB_Sym)
- #else
- #define CMEMLIB_Sym
-
-
- ////////////////////////////////////////////////////////////////////////
- //
- // Module Name: cmemlib.h
- //
- // Description: Cmemlib include for class definitions
- //
- // Written by: John Tal
- //
- //
- // Modification history:
- //
- // Date Engineer Mod # Modification Description
- //
- // 23-May-1991 Tal v 1.0-001 Initial conversion to C++
- // 01-Oct-1991 Tal v 1.0-002 Added comments on container
- // class
- //
- ////////////////////////////////////////////////////////////////////////
-
- #include <stdlib.h>
- #include "memincs.h"
-
-
- //
- // Tree Class
- //
-
- class TREE_C
- {
-
- private:
-
- // Available to class
- // Unavailable to derived classes
- // Unavailable to application
-
- //
- // TRE structs
- //
-
- struct TNODE_S
- {
- PVOID pvData;
- struct TNODE_S *pstLeft;
- struct TNODE_S *pstRight;
- };
- typedef struct TNODE_S TNODE_T;
- typedef TNODE_T *TNODE_P;
- typedef TNODE_T **TNODE_PP;
-
- // The TNODE_x structure CLASS appears within the TREE_C class.
- // This was done to resolve the problem in needing a head pointer
- // to the entire tree. If the TREE_C class pointed to itself, then
- // every node on the tree would have had to be an instance of the
- // TREE_C class (the head accessed by being declared static to
- // each instance).
- //
- // The solution was to have TREE_C contain TNODE_T, TREE_C is then
- // 'officially' known as a 'container' class.
- //
- // Another clue leading to the use of container class is that it
- // would not have made sense to create multiple instances of the
- // TNODE_ class each having the same references to the manipulation
- // routines (Ins, Del, Leaf, etc). The use of a container class
- // also promotes better data hiding, the user/application does not
- // know about the 'real' class utilized at the lowest layer.
-
-
- TNODE_P pstHead;
- TNODE_P pstNode;
- SHORT Leaf(TNODE_P);
- VOID RotateLeft(TNODE_P,TNODE_PP);
- VOID RotateRight(TNODE_P,TNODE_PP);
- VOID Ins(TNODE_PP,TNODE_P);
- SHORT Del(PVOID, TNODE_P, TNODE_PP);
-
- protected:
-
- // Available to class
- // Available to derived classes
- // Unavailable to application
-
- SHORT (*pCompareFunc)(PVOID,PVOID);
-
- // Note: Use virtual functions VERY sparingly.
- // Here we got around it by storing a ptr to func
- // Do not recommend using friend functions at all
- // (possibly unless trying to overload operators)
-
- public:
-
- // Available to class
- // Available to derived classes
- // Available to application
-
- TREE_C(VOID);
- ~TREE_C(VOID);
- SHORT Delete(PVOID); // Remove entry
- SHORT Find(PVOID,PPVOID); // Find entry
- SHORT Insert(PVOID); // Insert entry
- SHORT Vacate(BOOL); // Remove all entries
- SHORT SetCompareFunc(SHORT (*)(PVOID,PVOID));
- };
-
-
- typedef TREE_C * TREE_CP;
- typedef TREE_C ** TREE_CPP;
-
-
-
-
- //
- // Link List Class
- //
-
- class LLIST_C
- {
-
- private:
-
- // Available to class
- // Unavailable to derived classes
- // Unavailable to application
-
-
- protected:
-
- // Available to class
- // Available to derived classes
- // Unavailable to application
-
- //
- // LST structs
- //
-
- struct LLIST_S
- {
- struct LLIST_S *pstPrev;
- struct LLIST_S *pstNext;
- PVOID pvData;
- };
- typedef struct LLIST_S LLIST_T;
- typedef LLIST_T *LLIST_P;
- typedef LLIST_T **LLIST_PP;
-
-
- LLIST_P pstHead;
- LLIST_P pstCurNode;
-
- // Since we are keeping application away from internals, we will provide
- // a way for application to set multiple 'markers' in the list to jump
- // around
-
- struct TRACK_S
- {
- LLIST_P pstNode;
- SHORT sState;
- };
- typedef struct TRACK_S TRACK_T;
- typedef TRACK_S * TRACK_P;
-
-
- TRACK_P pstTrack;
- SHORT sTrackSize;
-
- #define TRACK_AVAIL 0
- #define TRACK_USED 1
-
- //
- // Internal maint routines
- //
-
- SHORT AddAfterNode(LLIST_P, LLIST_P);
- SHORT AddBeforeNode(LLIST_P, LLIST_P);
- SHORT DeleteNode(LLIST_P);
- SHORT FindNode(PVOID,LLIST_PP);
- SHORT FindLastNode(LLIST_PP);
- SHORT Alloc(PVOID,LLIST_PP);
- SHORT UnlinkNode(LLIST_P);
-
- SHORT (*pCompareFunc) (PVOID,PVOID); // Used for most funcs below
-
- public:
-
- // Available to class
- // Available to derived classes
- // Available to application
-
-
- LLIST_C(SHORT = 10); // initializes sTrackSize
- ~LLIST_C(VOID); // Vacate
-
- // Following are all standard application functions
- // Application never sees the LLIST_x types
-
- SHORT AddAfterCur(PVOID); // Used after Find or GoMark
- SHORT AddBeforeCur(PVOID); // ""
- SHORT DeleteCur(VOID); // Deletes Current node
- // current node undefined after
- SHORT Find(PVOID,PPVOID); // Return address PPVOID based on key
- // At address PVOID, cf pCompareFunc
- SHORT FindLast(PPVOID); // Return last address
- SHORT FindFirst(PPVOID); // Return 1st address
- SHORT GetCur(PPVOID); // Read based on pstCurNode
- SHORT GetPrev(PPVOID); // Read prev based on pstCurNode
- SHORT GetNext(PPVOID); // Read next based on pstCurNode
- SHORT Insert(PVOID); // Insert Address
- SHORT Vacate(BOOL); // Removes all data from list
- SHORT SetMark(PSHORT); // Remember pstCurNode
- SHORT GoMark(SHORT); // Restore pstCurNode
- SHORT ReleaseMark(SHORT); // Release/free mark
- SHORT SetCompareFunc(SHORT (*)(PVOID,PVOID));
- };
-
- typedef LLIST_C * LLIST_CP;
- typedef LLIST_C ** LLIST_CPP;
-
-
- //
- // Queue Class
- //
-
- class QUEUE_C : LLIST_C // derived from LLIST_C class
- {
- private:
-
- LLIST_P pstTail;
- long lEntries;
-
- public:
-
- QUEUE_C(VOID);
- ~QUEUE_C(VOID) { Vacate(C_FALSE); };
- SHORT Vacate(BOOL); // Vacate all entries
- SHORT Enq(PVOID); // Add entry
- SHORT Deq(PPVOID); // Remove entry
- SHORT GetEntries(PLONG); // Return entries in queue
- SHORT Find(PVOID,PPVOID); // Return address PPVOID based on key
- SHORT SetCompareFunc(SHORT (*)(PVOID,PVOID));
- };
-
- typedef QUEUE_C * QUEUE_CP;
- typedef QUEUE_C ** QUEUE_CPP;
-
-
-
- //
- // Stack Class
- //
-
- class STACK_C : LLIST_C
- {
-
-
- public:
- STACK_C(VOID) { pCompareFunc = NULL; };
- ~STACK_C(VOID) { Vacate(C_FALSE); };
- SHORT Vacate(BOOL);
- SHORT IsEmpty(PBOOL);
- SHORT Pop(PPVOID);
- SHORT Push(PVOID);
- SHORT Find(PVOID,PPVOID); // Return address PPVOID based on key
- SHORT SetCompareFunc(SHORT (*)(PVOID,PVOID));
-
- };
-
- typedef STACK_C * STACK_CP;
- typedef STACK_C ** STACK_CPP;
-
-
- //
- // Heap Class
- //
-
-
- class HEAP_C
- {
- private:
-
- //
- // HEP structs
- //
-
- struct HEAP_DATA_S
- {
- SHORT sPriority;
- PVOID pvData;
- };
-
- typedef struct HEAP_DATA_S HEAP_DATA_T;
- typedef HEAP_DATA_T * HEAP_DATA_P;
- typedef HEAP_DATA_T ** HEAP_DATA_PP;
-
- HEAP_DATA_P pstHeapData;
- SHORT sMaxElms;
- SHORT sBottom;
-
- SHORT Down(VOID);
- SHORT Up(VOID);
- VOID Swap(HEAP_DATA_P,HEAP_DATA_P);
-
- protected:
-
- SHORT (*pCompareFunc) (PVOID,PVOID); // Used for most funcs below
-
- public:
-
- HEAP_C(SHORT = 100);
- ~HEAP_C(VOID) { Vacate(); free(pstHeapData); };
- SHORT Enq(SHORT, PVOID);
- SHORT Deq(PSHORT, PPVOID);
- SHORT Find(PVOID, PPVOID);
- SHORT GetEntries(PSHORT);
- SHORT SetCompareFunc(SHORT (*)(PVOID,PVOID));
- SHORT Vacate(BOOL = C_FALSE);
- };
-
- typedef HEAP_C * HEAP_CP;
- typedef HEAP_C ** HEAP_CPP;
-
-
-
- #endif
-
-