From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.103.135 with SMTP id b129mr5841055ywc.14.1475875826726; Fri, 07 Oct 2016 14:30:26 -0700 (PDT) X-Received: by 10.157.10.196 with SMTP id 62mr2352840otq.2.1475875826679; Fri, 07 Oct 2016 14:30:26 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!g45no691914qte.1!news-out.google.com!203ni2990itk.0!nntp.google.com!l13no1030549itl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 7 Oct 2016 14:30:26 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:2c4:101:d816:95d0:cd94:975:2873; posting-account=bfqYCQoAAADhOBV9jx08D2gm5EA72sgj NNTP-Posting-Host: 2601:2c4:101:d816:95d0:cd94:975:2873 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <9cbda86b-57e3-4f9c-81bb-03a9a28a4cb6@googlegroups.com> Subject: Using generic package to store and retrieve string data From: James Brewer Injection-Date: Fri, 07 Oct 2016 21:30:26 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:32042 Date: 2016-10-07T14:30:26-07:00 List-Id: 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 ge= t 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 stri= ng handling? =20 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 :=3D 0; procedure Push(E : in Item) is begin if Index >=3D Size then raise Overflow; end if; Index :=3D Index + 1; Space(Index) :=3D E; end Push; procedure Pop(E : out Item) is begin if Index =3D 0 then raise Underflow; end if; E :=3D Space(Index); Index :=3D Index - 1; end Pop; end Generic_Stack;