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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f7a9613bbc2bd8c9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-14 03:22:53 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!supernews.com!iad-peer.news.verio.net!news.verio.net!fu-berlin.de!uni-berlin.de!pec-139-192.tnt8.hh2.uunet.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Generic default parameters Date: Tue, 14 May 2002 12:24:10 +0200 Message-ID: <8ep1eukksjmf65te5pvfreethdsbevsa9d@4ax.com> References: <60lvdu4ifauunm4qob6ir7rlas4soe0cp4@4ax.com> NNTP-Posting-Host: pec-139-192.tnt8.hh2.uunet.de (149.225.139.192) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1021371770 21563104 149.225.139.192 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:24008 Date: 2002-05-14T12:24:10+02:00 List-Id: On 13 May 2002 12:42:45 -0400, Stephen Leake wrote: >Dmitry A. Kazakov 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; > >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); > type IO_Handle is new Handles.Handle with null record; > >end IO.Handles; Yes, but this would kill the nature of IO_Handle. It would be just a private or a tagged private type. All operations defined on Handle get invisible, as well as the fact that IO_Handle is a descendant of an instance of Object.Handle. --- Regards, Dmitry Kazakov www.dmitry-kazakov.de