comp.lang.ada
 help / color / mirror / Atom feed
* Using generic package to store and retrieve string data
@ 2016-10-07 21:30 James Brewer
  2016-10-07 23:11 ` Jeffrey R. Carter
  2016-10-08 16:21 ` Stephen Leake
  0 siblings, 2 replies; 7+ messages in thread
From: James Brewer @ 2016-10-07 21:30 UTC (permalink / 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;


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-10-08 16:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-07 21:30 Using generic package to store and retrieve string data James Brewer
2016-10-07 23:11 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox