comp.lang.ada
 help / color / mirror / Atom feed
From: "REH" <spamjunk@stny.rr.com>
Subject: Re: generics in Ada 83
Date: 13 Sep 2005 11:53:36 -0700
Date: 2005-09-13T11:53:36-07:00	[thread overview]
Message-ID: <1126637616.954302.85630@f14g2000cwb.googlegroups.com> (raw)
In-Reply-To: <pxDVe.3$Fv6.0@dfw-service2.ext.ray.com>


Jeffrey Carter wrote:
> REH wrote:
> >
> > generic
> >     type X is private;
> >     with procedure Y(Z : in X);
> > package Foo;
> >
> > I want to define a default for Y, but how can I without knowing X?
>
> Defaults are defined for subprograms by inserting "is Name" or "is <>"
> before the semicolon (;):
>
>     with procedure Y (Z : in X) is A;
>
> or
>
>     with procedure Y (Z : in X) is <>;
>
> You can't use the former, since it requires a procedure A, visible at
> the point of the generic, that matches Y. Since you don't know what X is
> at the point of the generic, you can't have such a procedure.
>
> You can use the latter, which requires a procedure Y, visible at the
> point of the instantiation. However, that's unlikely to be what you want.
>
> You can also use a 2-step instantiation:
>
> generic -- Outer
>     type X is private;
> package Outer is
>     procedure Null_Proc (Z : in X);
>
>     generic -- Inner
>        with procedure Y (Z : in X) is Null_Proc;
>     package Inner is
>        ...
>     end Inner;
> end Outer;
>
> Such an approach complicates the process of instantiating the generic,
> but may be OK if it results in an overall reduction in the complexity of
> the instantiation process. If your generic has many formal subprograms,
> but only a small percentage are likely to need explicit actuals, this
> might be acceptable.
>
> However, if it's unlikely that a client will use all the services of the
> package, and different clients will use different subsets of those
> services, then you probably have a design problem. In such a case, you
> probably want to redesign to have several packages that factor out the
> likely subsets: several generics that provide the non-overlapping
> subsets of the possible services, and perhaps some higher-level generics
> that instantiate 2 or more of the non-overlapping subsets to provide
> overlapping subsets.
>
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.

Thanks for your time and help.

REH




  reply	other threads:[~2005-09-13 18:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-13 13:26 generics in Ada 83 REH
2005-09-13 13:30 ` Georg Bauhaus
2005-09-13 16:25   ` REH
2005-09-13 19:23     ` Georg Bauhaus
2005-09-13 13:50 ` Martin Dowie
2005-09-13 16:30   ` REH
2005-09-13 16:41     ` Martin Dowie
2005-09-13 18:43       ` REH
2005-09-13 19:37         ` Ludovic Brenta
2005-09-13 19:53           ` REH
2005-09-13 16:56 ` Jeffrey Carter
2005-09-13 18:53   ` REH [this message]
2005-09-13 22:16     ` Jeffrey Carter
2005-09-13 22:44       ` REH
2005-09-14  8:14   ` Jean-Pierre Rosen
2005-09-14 12:40     ` REH
2005-09-14 13:15     ` Hyman Rosen
2005-09-14 14:08       ` Jean-Pierre Rosen
2005-09-14 15:23         ` Hyman Rosen
2005-09-14 15:41           ` Robert A Duff
2005-09-19 17:58             ` REH
2005-09-20  4:58               ` Hyman Rosen
2005-09-20 12:36                 ` REH
2005-09-20  1:34             ` adaworks
2005-09-20  4:14               ` Jim Rogers
2005-09-21 22:58               ` Robert A Duff
2005-09-22 15:18                 ` adaworks
replies disabled

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