comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Specialization generic package parameters
Date: Sat, 24 May 2008 10:00:52 +0200
Date: 2008-05-24T10:00:53+02:00	[thread overview]
Message-ID: <4s3i3iblzpe9$.11777ypdr70kr$.dlg@40tude.net> (raw)
In-Reply-To: d164fe51-5f68-4452-b1b0-2a1923a510bb@a1g2000hsb.googlegroups.com

On Fri, 23 May 2008 13:17:02 -0700 (PDT), christoph.grein@eurocopter.com
wrote:

> Why not a combination of 1+3:
> 
>     generic
>       type Some_S is new S with private;
>     package P.Q is
>     private
>       -- has access to the private part of P
>     end P.Q;

But this would not constrain the parent P.

A typical example for the case is implementation of parallel types
hierarchies. For instance handles to the types T and S. (S <: T)

generic
   type Some_T is new T with private;
package P
   type T_Handle is private;
   procedure Foo (O : T_Handle); -- Delegation to Foo of T
   ...
private
   type T_Ptr is not null access all Some_T'Class;
   type T_Handle is new Ada.Finalization.Controlled with record
      Ptr : T_Ptr;
   end record;
end P;

[ It is extremely tedious and error-prone to declare such delegation
wrappers to all primitive operations of T, but there is no any help for
this in Ada. ]

Now, let S, derived from T adds some new operations and there should be
specialized handles to S to accommodate to this:

generic
   type Some_S is new S with private;
package P
   type S_Handle is private; -- (or is new T_Handle with private)

-- New operations:
   procedure Boo (O : S_Handle); -- Delegation to Boo of S

-- Old operations from T:
-- Oops, we should start all the mess again!
-- It seems that there is no way to re-use the wrappers declared in P,
-- by inheriting from T_Handle, without exposing private parts of
-- T_Handle (the variant 1). Alternatively, S_Handle should leave the
-- object pointer unconstrained, which would mean that delegators
-- would have to downcast them to S'Class (=distributed performance
-- hit) (the variant 3)

   procedure Foo (O : T_Handle); -- Delegation to Foo of T
   ...
private
   ...
end P;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-05-24  8:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-23 17:29 Specialization generic package parameters Dmitry A. Kazakov
2008-05-23 20:17 ` christoph.grein
2008-05-24  8:00   ` Dmitry A. Kazakov [this message]
2008-05-24 12:48 ` Stephen Leake
2008-05-24 14:07   ` Dmitry A. Kazakov
replies disabled

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