From: James Brewer <firstvestor@gmail.com>
Subject: Using generic package to store and retrieve string data
Date: Fri, 7 Oct 2016 14:30:26 -0700 (PDT)
Date: 2016-10-07T14:30:26-07:00 [thread overview]
Message-ID: <9cbda86b-57e3-4f9c-81bb-03a9a28a4cb6@googlegroups.com> (raw)
Hey guys, I am trying to create a generic package that will take strings of a fixed length store them in an array one at a time and later remove them one at a time. I was using a generic stack example I found on the net to get started but I can't seem to get it to work for string data.
Is there something that needs to be imported into the main program for string handling?
I tested it with character and integer data and it works with those.
Also, this is just a starting point for getting a generic to function with string data, ideally this will be converted into a queue.
Here is the code for the generic.
--ads
generic
Size : Positive;
type Item is private;
package Generic_Stack is
procedure Push(E : in Item);
procedure Pop (E : out Item);
Overflow, Underflow : exception;
end Generic_Stack;
--adb
package body Generic_Stack is
type Table is array (Positive range <>) of Item;
Space : Table(1 .. Size);
Index : Natural := 0;
procedure Push(E : in Item) is
begin
if Index >= Size then
raise Overflow;
end if;
Index := Index + 1;
Space(Index) := E;
end Push;
procedure Pop(E : out Item) is
begin
if Index = 0 then
raise Underflow;
end if;
E := Space(Index);
Index := Index - 1;
end Pop;
end Generic_Stack;
next reply other threads:[~2016-10-07 21:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-07 21:30 James Brewer [this message]
2016-10-07 23:11 ` Using generic package to store and retrieve string data Jeffrey R. Carter
2016-10-08 7:42 ` Dmitry A. Kazakov
2016-10-08 9:01 ` Simon Wright
2016-10-08 10:17 ` Dmitry A. Kazakov
2016-10-08 16:07 ` Jeffrey R. Carter
2016-10-08 16:21 ` Stephen Leake
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox