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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3e960bf7341df1d2 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: parameter passing Date: 2000/02/18 Message-ID: <88kkhf$460$1@nntp4.atl.mindspring.net>#1/1 X-Deja-AN: 587268236 References: <88gqg5$4a8$1@bunyip.cc.uq.edu.au> Organization: MindSpring Enterprises X-Server-Date: 18 Feb 2000 23:27:43 GMT Newsgroups: comp.lang.ada Date: 2000-02-18T23:27:43+00:00 List-Id: In article <88gqg5$4a8$1@bunyip.cc.uq.edu.au>, "Riyaz Mansoor" wrote: >i want to pass a generic package as a parameter to another genric package. > --how do i declare the gen2_pack with gen1 as a parameter? >also how would the code look like in gen2_pack which actually accepts the >gen1 package as a generic "paramter" ? The following Sort Utilities package is an abbreviated version of the original package with removal of a lot of comments. It should be easy to read. -- ========================================================= -- Sort_Utilities.Ads Richard Riehle, AdaWorks -- -- This package contains a set of generic sort routines that -- can be instantiated for the sorting of an unconstrained -- array. The Big-O notation associated with each sort is a -- kind of design metric that represents the relative performance -- of each algorithm. -- ============================================================= package Sort_Utilities is generic type Data is private; type Index is (<>); type Data_Set is array(Index range <>) of Data; with function Is_Greater (Left, Right : Data) return Boolean; with function Is_Equal (Left, Right : Data) return Boolean; package Sort_Signature is end Sort_Signature; generic with package Signature is new Sort_Signature(<>); procedure QuickSort(The_Data : in out Signature.Data_Set); -- Note the dot notation generic with package Signature is new Sort_Signature(<>); procedure BubbleSort(The_Data : in out Signature.Data_Set); generic with package Signature is new Sort_Signature(<>); use Signature; -- Note the use clause procedure InsertionSort(The_Data : in out Data_Set); -- Dot notation not required -- More kinds of sort algorithms. end Sort_Utilities; The generic sort procedures each have a generic formal package parameter using a signature immediately enclosed in the same package specification. The following little procedure, some code deleted for pedagogic purposes, demonstrates how to instantiate one of these sort routines. with Sort_Utilities; procedure Test_Utilities is type Stock is record Data : String(1..20); Key : Positive; end record; type Stock_Array is array(Positive range <>) of Stock; function "="(L, R : Stock) return Boolean is begin return L.Key = R.Key; end "="; function ">"(L, R : Stock) return Boolean is begin return L.Key > R.Key; end ">"; package Stock_Signature is new Sort_Utilities.Sort_Signature (Data => Stock, Index => Positive, Data_Set => Stock_Array, Is_Equal => "=", Is_Greater => ">"); procedure Stock_Sort is new Sort_Utilities.QuickSort (Signature => Stock_Signature); begin null; -- Of course you will want some actual code here. :) end Test_Utilities; In the body of the Sort_Utilities, you will refer to each signature parameter with dot notation, unless you prefer a use clause, as we did for InsertionSort. Hope you find this useful. Richard Riehle