home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / arrays / generics / flxarray / stacks.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-23  |  2.5 KB  |  77 lines

  1. Unit Stacks;
  2.  
  3. { By following the pattern established in the example Object, RealStack }
  4. { It is possible (and sinfully easy) to implement clean and efficient   }
  5. { Stacks of any desired data type.                                      }
  6.  
  7. { REMEMBER: Although it is possible to dynamically Re-Size FlexStacks   }
  8. { they are implemented as ARRAYS on the Heap, and so are subject to the }
  9. { 65521 byte size limitation imposed by GetMem.  For larger structures, }
  10. { see the family of Dynamic Generic Objects, or the MaxArray family.    }
  11.  
  12. INTERFACE
  13.  
  14. Uses GenStack;
  15.  
  16. Type
  17.   RealStack = Object (FlexStack)
  18.  
  19.     Procedure Init (MaxElements : Word);
  20.  
  21.     {The following are redefined PRIMARILY to regain Type-Checking}
  22.  
  23.       Procedure Copy (RS : RealStack);
  24.       Procedure Push (R : Real);
  25.       Procedure Pop (Var R : Real); {Pop and Top could be Functions except}
  26.       Procedure Top (Var R : Real); {when defining a structured type stack }
  27.  
  28.   End; {RealStack}
  29.  
  30.   (************************************************************************)
  31.    {
  32.    NOTE: The following procedures and functions are also applicable
  33.          to derived Stacks, but need no redefinition:
  34.  
  35.        Procedure Create; (* MUST CALL FIRST! Need never be called again *)
  36.        Procedure Destroy;(* Call before re-INITting *)
  37.        Procedure ReSize (Num : Word); (* Add (subtract) Num elements *)
  38.  
  39.        Function MaxSize : Word; (* How many elements currently ALLOWED *)
  40.        Function ElemSize : Word;
  41.        Function Full : Boolean;
  42.        Function Empty : Boolean;
  43.        Function Depth : Word;   (* How many elements currently in Stack *)
  44.    }
  45.   (************************************************************************)
  46.  
  47. IMPLEMENTATION
  48.  
  49. Procedure RealStack.Init (MaxElements : Word);
  50. Begin
  51.   FlexStack.Init (MaxElements,SizeOf(Real))
  52. End;
  53.  
  54. Procedure RealStack.Copy (RS : RealStack);
  55. Begin
  56.   FlexStack.Copy (RS)
  57. End;
  58.  
  59. Procedure RealStack.Push (R : Real); {NOTE: This was working fine without}
  60. Var Temp : Real;                     {the TEMP variable, but I do NOT know}
  61. Begin                                {what happens when you send a Value to}
  62.   Temp := R;                         {a routine expecting a typeless Var, so}
  63.   FlexStack.Push (Temp,SizeOf(Real)) {I stuck in the TEMP as a safety measure}
  64. End;                                 {I recommend always using it this way}
  65.  
  66. Procedure RealStack.Pop (Var R : Real);
  67. Begin
  68.   FlexStack.Pop (R,SizeOf(Real))
  69. End;
  70.  
  71. Procedure RealStack.Top (Var R : Real);
  72. Begin
  73.   FlexStack.Top (R,SizeOf(Real))
  74. End;
  75.  
  76. BEGIN
  77. END.