////////////////////////////////////////////////////////// // PointerStack.cpp // // // // A fuly encapsulated stack of generalized pointers // // // // CALLED BY: // // RemoveFolder // // // // AUTHOR: Lucas Scharf // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: 1.00 // ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // Compiler Directives // ////////////////////////////////////////////////////////// #include "Constants.h" //Used for "null" #include "PointerStack.h" //Self ////////////////////////////////////////////////////////// // Private Type Declarations // ////////////////////////////////////////////////////////// //-- Stack Element -- typedef struct StackItemTypeTag { void *MoreInfoPtr; //Generic pointer to whatever StackItemTypeTag *LinkPrevious; //Link to the next lower item on the stack } StackItemType; //-- Pointer to stack element -- typedef StackItemType *StackItemTypePtr; ////////////////////////////////////////////////////////// // File-Scoped Variables // ////////////////////////////////////////////////////////// StackItemTypePtr TopOfStack; //Pointer to the top item in the stack ////////////////////////////////////////////////////////// // StackInit // // // // Initializes the stack // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: No parameters or return value. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void StackInit(){ TopOfStack = null; }//End StiackInit ////////////////////////////////////////////////////////// // StackPush // // // // Pushes an item onto the top of the stack // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: // // void *PushThis: In - The pointer info to push onto // // the stack. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void StackPush(void *PushThis){ //-- Variable Declaration -- StackItemTypePtr NewItem; //Pointer to the new item on the stack //-- Create New item -- NewItem = new StackItemType; //-- Assign Info -- NewItem->MoreInfoPtr = PushThis; //-- Attach to top of stack -- NewItem->LinkPrevious = TopOfStack; TopOfStack = NewItem; }//end StackPush ////////////////////////////////////////////////////////// // StackPop // // // // Removes the top item from the stack // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: None // // Returns: The pointer that was on the top of the // // stack // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void* StackPop(){ //-- Variable Declaration -- StackItemTypePtr ItemToDelete; //Pointer to the item being nuked void* ReturnValue; //The value to be returned //-- Empty List Check-- if (StackEmpty()) return (void*)null; //-- Remove Item from top of the list -- ItemToDelete = TopOfStack; TopOfStack = TopOfStack->LinkPrevious; //-- Get value from item -- ReturnValue = ItemToDelete->MoreInfoPtr; //-- Return item to heap -- delete ItemToDelete; //-- Return value -- return ReturnValue; }//end StackPop ////////////////////////////////////////////////////////// // StackTop // // // // Returns a copy the top item on the stack without // // popping // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: None // // Returns: The pointer that was on the top of the // // stack // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void* StackTop(){ return TopOfStack->MoreInfoPtr; }//end StackTop ////////////////////////////////////////////////////////// // StackDestroy // // // // Empties the stack // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: None // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void StackDestroy(){ //-- Empty Stack -- while (!StackEmpty()) StackPop(); }//end StackDestroy ////////////////////////////////////////////////////////// // StackEmpty // // // // Tests to see if the stack is Empty // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: None // // Returns: True - if stack is empty, false iff stack // // contains at least 1 item. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// bool StackEmpty(){ return !TopOfStack; //Returns true if stack contains no items, else false }//end StackEmpty ////////////////////////////////////////////////////////// // StackFull // // // // Tests to see if the stack is full // // // // CALLED BY: RemoveFolder // // CALLS: None // // // // PARAMETERS: None // // Returns: True -- this stack is never full until the // // machine runs out of memory. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// bool StackFull(){ return false; }//end StackFull