MarkedStack Class Reference

A marked stack is a special purpose stack/list. Its properties are described:. More...

#include <stack.h>

Inheritance diagram for MarkedStack:

List CCObject SimpleCCObject List of all members.

Public Member Functions

 MarkedStack ()
 MarkedStack constructor.
 ~MarkedStack ()
 MarkedStack destructor. The items on the stack are not deleted.
void Push (ListItem *Item)
 Pushes Item onto the stack.
ListItemPop (void)
 Removes the item from the top of the stack, and returns it.
BOOL Mark ()
 Marks the current Top of the stack so that we can easily return to the same state by calling Release().
void Release ()
 Pops and then deletes items from the stack until we find the first mark. If there are no marks then all items on the stack are removed and deleted.
void DeleteAll ()
 Deletes all marks and elements in the MarkedStack.

Private Attributes

Stack MarkStack

Detailed Description

A marked stack is a special purpose stack/list. Its properties are described:.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
It has Push and Pop methods It inherits from list so it can easily be searched

It has a Mark() method which marks the current top of stack. Mark() can be called more than once to insert a number of marks into the stack.

It has a Release() method which restores the state of the stack to the position of the last mark.

eg.

MarkedStack MS();

MS->Push(a) MS->Mark() MS->Push(b) MS->Push(c) MS->Mark() MS->Push(d)

The stack looks like this

d <- Tail c <- Mark b a <- Mark

If we now perform MS->Release() the stack will look like this

c b a <- Mark

If we perform MS->Release() a second time, the stack will look like this

a

See also:
-

Definition at line 210 of file stack.h.


Constructor & Destructor Documentation

MarkedStack::MarkedStack  ) 
 

MarkedStack constructor.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 274 of file stack.cpp.

00275 {
00276 }

MarkedStack::~MarkedStack  ) 
 

MarkedStack destructor. The items on the stack are not deleted.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 293 of file stack.cpp.

00294 {
00295 }


Member Function Documentation

void MarkedStack::DeleteAll  )  [virtual]
 

Deletes all marks and elements in the MarkedStack.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Reimplemented from List.

Definition at line 431 of file stack.cpp.

00432 {
00433     ListItem* TopOfStack;
00434     TopOfStack = GetTail(); 
00435     while (TopOfStack != NULL)   // loop while the stack is not empty 
00436     {
00437         Release(); // Deletes mark and all items before the mark        
00438         TopOfStack = GetTail(); 
00439     }   
00440     // Make sure there are no marks left
00441     ENSURE(MarkStack.Pop() == NULL, "All marks have not been deleted from the MarkedStack"); 
00442 }   

BOOL MarkedStack::Mark void   ) 
 

Marks the current Top of the stack so that we can easily return to the same state by calling Release().

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if we could create Mark, FALSE if we are out of memory

Errors: ERRORIF is called if we are out of memory

See also:
MarkedStack::Release()

Definition at line 357 of file stack.cpp.

00358 {           
00359     // Firstly create a mark                                                    
00360     ListItemPtrItem* pMark = new ListItemPtrItem(); 
00361     // Return with an error if we could not create the mark
00362     if (pMark == NULL)
00363         return FALSE; 
00364     pMark->pListItem = GetTail();   // This will be NULL if the list is empty 
00365 
00366     // Push the mark onto the MarkStack
00367     MarkStack.Push(pMark); 
00368     return TRUE; // Success
00369 }   

ListItem * MarkedStack::Pop void   ) 
 

Removes the item from the top of the stack, and returns it.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The top item on the stack, or NULL if the stack is empty

Errors: -

See also:
-

Definition at line 333 of file stack.cpp.

00334 {   
00335     return (RemoveTail()); 
00336 }

void MarkedStack::Push ListItem Item  ) 
 

Pushes Item onto the stack.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 313 of file stack.cpp.

00314 {
00315     AddTail(Item); // Add the item to the top of the stack 
00316 }

void MarkedStack::Release void   ) 
 

Pops and then deletes items from the stack until we find the first mark. If there are no marks then all items on the stack are removed and deleted.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
8/2/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
MarkedStack::Mark

Definition at line 388 of file stack.cpp.

00389 {
00390     // Find the mark to stop at 
00391     ListItemPtrItem* MarkRec = (ListItemPtrItem*)MarkStack.Pop();
00392     ListItem* Mark; 
00393     if (MarkRec == NULL)                        // There are no marks to find 
00394     {
00395         Mark = NULL; 
00396     } else 
00397     {
00398         Mark = MarkRec->pListItem; 
00399     }  
00400     ListItem* TopOfStack = GetTail(); 
00401     ListItem* AsGoodAsDead; 
00402 
00403     while (TopOfStack != Mark)          // Loop until we find Mark
00404     {
00405         ENSURE(TopOfStack != NULL, "A Mark could not be found in the Marked stack"); 
00406         TopOfStack = GetPrev(TopOfStack);
00407         AsGoodAsDead = RemoveTail();
00408         delete AsGoodAsDead; 
00409     }
00410     if (MarkRec != NULL)
00411     {
00412         delete (MarkRec); // Restored State to that pointed to by Mark, so delete it 
00413     }
00414 } 


Member Data Documentation

Stack MarkedStack::MarkStack [private]
 

Definition at line 225 of file stack.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:56:06 2007 for Camelot by  doxygen 1.4.4