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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c0d427d5f4af20f8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!newscon02.news.prodigy.com!prodigy.net!cyclone.swbell.net!bos-service1.raytheon.com!dfw-service2.ext.ray.com.POSTED!53ab2750!not-for-mail From: Jeffrey Carter User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: generics in Ada 83 References: <1126617980.932226.320710@g43g2000cwa.googlegroups.com> <1126637616.954302.85630@f14g2000cwb.googlegroups.com> In-Reply-To: <1126637616.954302.85630@f14g2000cwb.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Tue, 13 Sep 2005 15:16:04 -0700 NNTP-Posting-Host: 147.24.111.90 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.ray.com 1126649765 147.24.111.90 (Tue, 13 Sep 2005 17:16:05 CDT) NNTP-Posting-Date: Tue, 13 Sep 2005 17:16:05 CDT Organization: Raytheon Company Xref: g2news1.google.com comp.lang.ada:4635 Date: 2005-09-13T15:16:04-07:00 List-Id: REH wrote: > > Well I guess there is always a better way. Here is my actual problem. > My team maintains a set of middleware services for various > applications. We have a Client/Server package as part of this. It > defines a header type for transmitting messages across TCP/IP. One > application group has requested the ability to define their own header. > There are certain pieces of information our software needs to know > from the header, such as the message length. So I re-defined the > package thus: > > generic > type Header_Type is private; > > with function Get_Length(Header : in Header_Type) return Integer; > > with procedure Set_Length(Header : in out Header_Type; > Length : in Integer); > package Client_Server; > > This works fine for using most of the services in the package. But the > thorn is the package provides a "synchronous send" feature that does a > request/response type of transaction over a network. This requires > several more fields to be present in the header and accessed at various > times. Thus, I have added get and set subprograms for those. But I > don't want a client application that does not use this feature to have > to define stubs for all these. Which is where I am tried to find a way > to "default" them. Then you're in good shape. 1st, define your complete generic for using the synchronous send feature: generic -- Client_Server_With_Synchronous_Send type Header_Type is private; -- many formal subprograms package Client_Server_With_Synchronous_Send is procedure Op (Header : in out Header_Type); ... end Client_Server_With_Synchronous_Send; then define your shorter generic: generic -- Client_Server type Header_Type is private; with function Get_Length(Header : in Header_Type) return Integer; with procedure Set_Length(Header : in out Header_Type; Length : in Integer); package Client_Server is -- presumably a smaller set of operations than -- Client_Server_With_Synchronous_Send procedure Op (Header : in out Header_Type); ... end Client_Server; Now, the body of Client_Server instantiates Client_Server_With_Synchronous_Send and implements its operations in terms of Client_Server_With_Synchronous_Send's operations: with Client_Server_With_Synchronous_Send; package body Client_Server is -- Define stub subprograms for instantiation here. package Synchronous is new Client_Server_With_Synchronous_Send (Header_Type => Header_Type, Get_Length => Get_Length, Set_Length => Set_Length, ...); procedure Op (Header : in out Header_Type) renames Synchronous.Op; ... end Client_Server; -- Jeffrey Carter "Now go away or I shall taunt you a second time." Monty Python and the Holy Grail E-mail: jeffrey_r_carter-nr [commercial-at] raytheon [period | full stop] com