OO String Stack Body
MC logo

OO String Stack Body

Ada Code Examples

<<OO String Stack Package Download OO Stack Driver>>
-- Declarations for string stack.

with Ada.Unchecked_Deallocation;

package body SStack is
   -- Creator.
   function SDat(S: String) return StrStackData is
      RetVal: StrStackData;
      RetVal.V := new String'(S);
      return RetVal;
   end SDat;

   -- Extractor.
   function SValue(R: StrStackData) return String is
      return R.V.all;
   end SValue;

   -- Initialize a new object.  Just gets the null pointer.
   procedure Initialize(SR: in out StrStackData) is
      SR.V := null;
   end Initialize;

   -- After assignment, turn the copy of the pointer into a real copy.
   procedure Adjust(SR: in out StrStackData) is
      SR.V := new String'(SR.V.all);
   end Adjust;

   -- When destroyed, free the space.
   procedure Finalize(SR: in out StrStackData) is
      procedure Free is new Ada.Unchecked_Deallocation(String, SPtr);
   end Finalize;
end SStack;
<<OO String Stack Package OO Stack Driver>>