comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov>
Subject: Re: Generic default parameters
Date: 13 May 2002 12:42:45 -0400
Date: 2002-05-13T16:49:26+00:00	[thread overview]
Message-ID: <u8z6oov7e.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 60lvdu4ifauunm4qob6ir7rlas4soe0cp4@4ax.com

Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> writes:

> A concrete example. Let we want to implement smart pointers / handles.
> It could go as follows:
> 
> package Object is
>    type Entity is new
>       Ada.Finalization.Limited_Controlled with
>    record
>       Use_Count : Natural := 0; -- Reference count
>    end record;
> ...
> end Object;
> 
> generic
>    type Object_Type (<>) is abstract new Entity with private;
>    type Object_Type_Ptr is access all Object_Type'Class;
> package Object.Handle is
>    type Handle is tagged private;
> ...
> private
>    type Handle is new Ada.Finalization.Controlled with record
>       Ptr : Object_Type_Ptr := null;
>    end record;
> end Object.Handle;
> 
> Now the problem, how to instantiate Object.Handle having Object_Type
> private? Let we have:
> 
> package IO is
> ...
> private
>    type File_Descriptor is new Entity with ...;
>    type File_Descriptor_Ptr is access all File_Descriptor'Class;
> end IO;
> 
> package IO.Handles is
>    package Handles is
>        new Object.Handle (File_Descriptor, File_Descriptor_Ptr);
>            -- Illegal, File_Descriptor is not visible here
>    subtype IO_Handle is Handles.Handle;
>    ...
> end IO.Handles;

Simple. Make IO.Handles a private package:

private package IO.Handles is

Now the only places IO.Handles.IO_Handles can be seen are the same
places IO.File_Descriptor can be seen.

Hmm, perhaps you _wanted_ IO.Handles.IO_Handle to be public, so
clients could do stuff. Simple :

with Object.Handle;
package IO.Handles is
   type IO_Handle is private;
private
   package Handles is new Object.Handle (File_Descriptor, File_Descriptor_Ptr);
           -- Illegal, File_Descriptor is not visible here
   type IO_Handle is new Handles.Handle with null record;

end IO.Handles;


-- 
-- Stephe



  reply	other threads:[~2002-05-13 16:42 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-10 14:22 Generic default parameters Thomas Wolf
2002-05-10 16:38 ` Preben Randhol
2002-05-10 16:50   ` Marin David Condic
2002-05-11  9:29     ` Simon Wright
2002-05-13 15:03       ` Hyman Rosen
2002-05-11 12:28     ` Preben Randhol
2002-05-13 14:03       ` Marin David Condic
2002-05-13 14:49       ` Hyman Rosen
2002-05-10 19:04   ` Hyman Rosen
2002-05-11 12:23     ` Preben Randhol
2002-05-11 13:49       ` Larry Kilgallen
2002-05-13 14:06       ` Marin David Condic
2002-05-10 19:27   ` Randy Brukardt
2002-05-11 12:32     ` Preben Randhol
2002-05-10 22:14 ` Stephen Leake
2002-05-13  7:49   ` Thomas Wolf
2002-05-13  8:49 ` Dmitry A. Kazakov
2002-05-13 14:00   ` Stephen Leake
2002-05-13 15:21     ` Dmitry A. Kazakov
2002-05-13 16:42       ` Stephen Leake [this message]
2002-05-14 10:24         ` Dmitry A. Kazakov
2002-05-14 14:02           ` Stephen Leake
2002-05-15 10:08             ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
2002-05-14  4:57 Grein, Christoph
2002-05-14 10:23 ` Dmitry A. Kazakov
2002-05-14 11:03 Grein, Christoph
2002-05-14 12:01 ` Dmitry A. Kazakov
2002-05-14 14:05   ` Stephen Leake
2002-05-15  8:44     ` 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