home *** CD-ROM | disk | FTP | other *** search
- /*
- File: StackList.h
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __STACKLIST__
- #define __STACKLIST__
-
- #ifndef __TYPES__
- #include "Types.h"
- #endif
-
- #ifndef __DIRECTOBJECT__
- #include "DirectObject.h"
- #endif
-
- /***********************************|****************************************/
-
- class TStackLink;
-
- class TStack : public TDirectObject
- {
- public: TStack ();
- ~TStack ();
-
- void Push ( const void* );
- const void* Pop ();
- void Clear ();
-
- const void* Top () const;
- Boolean Contains ( const void* ) const;
- unsigned long Length () const;
-
- private: TStack ( const TStack& );
- TStack& operator = ( const TStack& );
-
- unsigned long fLength;
-
- TStackLink* fTop;
- };
-
- class TStackLink : public TDirectObject
- {
- public:
-
- TStackLink ( const void* value, TStackLink*& last );
- ~TStackLink ();
- const void* fValue;
- TStackLink* fNext;
- };
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- #pragma push
- #pragma segment SortedList
-
- inline
- TStackLink::TStackLink ( const void* value, TStackLink*& last ):
- fValue ( value ),
- fNext ( last )
- {
- last = this;
- }
-
- /***********************************|****************************************/
-
- inline
- TStackLink::~TStackLink ()
- {
- delete fNext;
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- inline
- TStack::TStack ():
- fLength ( 0 ),
- fTop ( 0 )
- {
- }
-
- /***********************************|****************************************/
-
- inline unsigned long
- TStack::Length () const
- {
- return fLength;
- }
-
- /***********************************|****************************************/
-
- inline void
- TStack::Push ( const void* value )
- {
- new TStackLink ( value, fTop );
- ++fLength;
- }
-
- /***********************************|****************************************/
-
- inline const void*
- TStack::Top () const
- {
- if ( fTop )
- return fTop->fValue;
- else
- return 0;
- }
-
- /***********************************|****************************************/
-
- inline
- TStack::~TStack ()
- {
- delete fTop;
- }
-
- #pragma pop
-
- /***********************************|****************************************/
-
- #endif // __STACK__
-