home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / StackList.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  2.4 KB  |  133 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        StackList.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __STACKLIST__
  15. #define    __STACKLIST__
  16.  
  17. #ifndef    __TYPES__
  18. #include "Types.h"
  19. #endif
  20.  
  21. #ifndef    __DIRECTOBJECT__
  22. #include "DirectObject.h"
  23. #endif
  24.  
  25. /***********************************|****************************************/
  26.  
  27. class TStackLink;
  28.  
  29. class TStack : public TDirectObject
  30. {
  31. public:        TStack ();
  32.             ~TStack ();
  33.  
  34.             void                    Push ( const void* );
  35.             const void*                Pop ();
  36.             void                    Clear ();
  37.  
  38.             const void*                Top () const;
  39.             Boolean                    Contains ( const void* ) const;
  40.             unsigned long            Length () const;
  41.  
  42. private:    TStack ( const TStack& );
  43.             TStack&                    operator = ( const TStack& );
  44.  
  45.             unsigned long            fLength;
  46.  
  47.             TStackLink*            fTop;
  48. };
  49.  
  50. class TStackLink : public TDirectObject 
  51. {
  52. public:
  53.  
  54.     TStackLink ( const void* value, TStackLink*& last );
  55.     ~TStackLink ();
  56.     const void* fValue;
  57.     TStackLink* fNext;
  58. };
  59.  
  60. /***********************************|****************************************/
  61. /***********************************|****************************************/
  62.  
  63. #pragma push
  64. #pragma segment SortedList
  65.  
  66. inline
  67. TStackLink::TStackLink ( const void* value, TStackLink*& last ):
  68.     fValue ( value ),
  69.     fNext ( last )
  70. {
  71.     last = this;
  72. }
  73.  
  74. /***********************************|****************************************/
  75.  
  76. inline
  77. TStackLink::~TStackLink ()
  78. {
  79.     delete fNext;
  80. }
  81.  
  82. /***********************************|****************************************/
  83. /***********************************|****************************************/
  84.  
  85. inline
  86. TStack::TStack ():
  87.     fLength ( 0 ),
  88.     fTop ( 0 )
  89. {
  90. }
  91.  
  92. /***********************************|****************************************/
  93.  
  94. inline unsigned long
  95. TStack::Length () const
  96. {
  97.     return fLength;
  98. }
  99.  
  100. /***********************************|****************************************/
  101.  
  102. inline void
  103. TStack::Push ( const void* value )
  104. {
  105.     new TStackLink ( value, fTop );
  106.     ++fLength;
  107. }
  108.  
  109. /***********************************|****************************************/
  110.  
  111. inline const void*
  112. TStack::Top () const
  113. {
  114.     if ( fTop )
  115.         return fTop->fValue;
  116.     else
  117.         return 0;
  118. }
  119.  
  120. /***********************************|****************************************/
  121.  
  122. inline
  123. TStack::~TStack ()
  124. {
  125.     delete fTop;
  126. }
  127.  
  128. #pragma pop
  129.  
  130. /***********************************|****************************************/
  131.  
  132. #endif    // __STACK__
  133.