home *** CD-ROM | disk | FTP | other *** search
- Unit Stacks;
-
- { By following the pattern established in the example Object, RealStack }
- { It is possible (and sinfully easy) to implement clean and efficient }
- { Stacks of any desired data type. }
-
- { REMEMBER: Although it is possible to dynamically Re-Size FlexStacks }
- { they are implemented as ARRAYS on the Heap, and so are subject to the }
- { 65521 byte size limitation imposed by GetMem. For larger structures, }
- { see the family of Dynamic Generic Objects, or the MaxArray family. }
-
- INTERFACE
-
- Uses GenStack;
-
- Type
- RealStack = Object (FlexStack)
-
- Procedure Init (MaxElements : Word);
-
- {The following are redefined PRIMARILY to regain Type-Checking}
-
- Procedure Copy (RS : RealStack);
- Procedure Push (R : Real);
- Procedure Pop (Var R : Real); {Pop and Top could be Functions except}
- Procedure Top (Var R : Real); {when defining a structured type stack }
-
- End; {RealStack}
-
- (************************************************************************)
- {
- NOTE: The following procedures and functions are also applicable
- to derived Stacks, but need no redefinition:
-
- Procedure Create; (* MUST CALL FIRST! Need never be called again *)
- Procedure Destroy;(* Call before re-INITting *)
- Procedure ReSize (Num : Word); (* Add (subtract) Num elements *)
-
- Function MaxSize : Word; (* How many elements currently ALLOWED *)
- Function ElemSize : Word;
- Function Full : Boolean;
- Function Empty : Boolean;
- Function Depth : Word; (* How many elements currently in Stack *)
- }
- (************************************************************************)
-
- IMPLEMENTATION
-
- Procedure RealStack.Init (MaxElements : Word);
- Begin
- FlexStack.Init (MaxElements,SizeOf(Real))
- End;
-
- Procedure RealStack.Copy (RS : RealStack);
- Begin
- FlexStack.Copy (RS)
- End;
-
- Procedure RealStack.Push (R : Real); {NOTE: This was working fine without}
- Var Temp : Real; {the TEMP variable, but I do NOT know}
- Begin {what happens when you send a Value to}
- Temp := R; {a routine expecting a typeless Var, so}
- FlexStack.Push (Temp,SizeOf(Real)) {I stuck in the TEMP as a safety measure}
- End; {I recommend always using it this way}
-
- Procedure RealStack.Pop (Var R : Real);
- Begin
- FlexStack.Pop (R,SizeOf(Real))
- End;
-
- Procedure RealStack.Top (Var R : Real);
- Begin
- FlexStack.Top (R,SizeOf(Real))
- End;
-
- BEGIN
- END.