comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: smart pointer dangerous (no -> operator)
Date: Sat, 17 Jan 2009 10:28:01 +0100
Date: 2009-01-17T10:28:02+01:00	[thread overview]
Message-ID: <138mfqjaug7ie.c1nu0yulmks7.dlg@40tude.net> (raw)
In-Reply-To: 6j22n4ll4932l07nqc1c8d5q5rubrj9c3a@4ax.com

On Sat, 17 Jan 2009 00:43:17 +0000, Brian Drummond wrote:

> On Fri, 16 Jan 2009 12:09:16 +0100, "Dmitry A. Kazakov"
> <mailbox@dmitry-kazakov.de> wrote:
> 
>>1. In Ada 95 I declare the proxy type tagged controlled. The handle is
>>created through a instantiation in the private part of the generic package
>>Handle:
>>
>>   type X_Handle is new Ada.Finalization.Controlled with private;
>>      -- Repeat all operations of the target
>>   procedure Foo (Object : X_Handle);
>>   ... -- and so on
>>private
>>   package Handles is not Object.Handle (...); -- Instantiation
>>   type X_Handle is new Handles.Handle with null record;
>>
>>The implementation of Foo goes as follows:
>>
>>   procedure Foo (Object : X_Handle) is
>>   begin
>>       Foo (Ptr (Object).all);
>>   end Foo;
>>
>>this is extremely tedious, but the best way I know.
> 
> As an Ada newbie, I've probably lost track of something important, but
> I can't see a reason not to create a generic procedure, and simply
> instantiate it for each Foo, which would be slightly less boring if it
> worked..

I am not sure what you mean. To have a generic subprogram in addition to
each primitive operation of the target type? That would be even more
boring.

The problem is:

You have a target type:

   type T is ...;
   procedure Foo (X : T);
   function Bar return T;
   procedure Baz (X : T; Y : in out T; Z : Float);
   ...

Now you want to create a type T_Handle which would in its implementation
Ada.Finalization.Controlled with a pointer to an instance of T and all
operations of T delegated to the pointer's target:

   type T_Handle is Ada.Finalization.Controlled with private;
   procedure Foo (X : T_Handle);
   function Bar return T_Handle;
   procedure Baz (X : T_Handle; Y : in out T_Handle; Z : Float);
   ...

Generics do not solve that. What does is delegation + interface inheritance
from concrete type (T). Ada has neither.

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



  reply	other threads:[~2009-01-17  9:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-16 10:04 smart pointer dangerous (no -> operator) Oliver Kowalke
2009-01-16 11:09 ` Dmitry A. Kazakov
2009-01-16 11:42   ` Georg Bauhaus
2009-01-16 12:43     ` Dmitry A. Kazakov
2009-01-16 21:21     ` Maciej Sobczak
2009-01-17 19:07       ` Georg Bauhaus
2009-01-16 11:46   ` Oliver Kowalke
2009-01-16 12:45     ` Dmitry A. Kazakov
2009-01-17  0:43   ` Brian Drummond
2009-01-17  9:28     ` Dmitry A. Kazakov [this message]
2009-01-16 20:08 ` Tero Koskinen
2009-01-16 21:16   ` Maciej Sobczak
2009-01-18 12:21 ` Samuel Tardieu
replies disabled

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