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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: Victor Porton Newsgroups: comp.lang.ada Subject: Re: Both Ada.Finalization.Limited_Controlled and Ada.Finalization.Controlled Date: Fri, 25 Jul 2014 22:25:24 +0300 Organization: Aioe.org NNTP Server Message-ID: References: NNTP-Posting-Host: rFX7cZOSaeuGGZI2vwQTaQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Complaints-To: abuse@aioe.org User-Agent: KNode/4.12.4 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:21220 Date: 2014-07-25T22:25:24+03:00 List-Id: Victor Porton wrote: > I have implemented the following package to wrap pointers to C records: > > with Ada.Finalization; > > generic > type Record_Type; -- It should be an untagged record for C > compatibility > package RDF.Auxilary.Handled_Record is > > type Access_Type is access Record_Type > with Convention=>C; > > -- It is logically abstract, but not exactly abstract in Ada sense. > -- It can't be abstract because the function From_Handle returns this > type. type Base_Object is new Ada.Finalization.Limited_Controlled with > private; > > overriding procedure Initialize(Object: in out Base_Object); > > overriding procedure Finalize(Object: in out Base_Object); > > not overriding function Get_Handle(Object: Base_Object) return > Access_Type with Inline; > > not overriding function From_Handle(Handle: Access_Type) return > Base_Object with Inline; > > not overriding function Default_Handle(Object: Base_Object) return > Access_Type; > > not overriding procedure Finalize_Handle(Object: Base_Object; Handle: > Access_Type) is null; > > private > > type Base_Object is new Ada.Finalization.Limited_Controlled with > record > Handle: Access_Type; > end record; > > end RDF.Auxilary.Handled_Record; > > I think you guess what the body is, but if you don't look into > https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-auxilary-handled_record.ads > https://github.com/vporton/redland-bindings/blob/ada2012/ada/src/rdf-auxilary-handled_record.adb > > Now I want to create a similar generic package with > > type Base_Object is new Ada.Finalization.Controlled with private; > > and a function to create a copy handle: > > function Copy(Handle: Access_Type) return Access_Type is null; > > and > > procedure Adjust(Object : in out Base_Object) is > begin > if Object.Handle /= null > Object.Handle = Copy (Object.Handle); > end if; > end; > > My question: Is it possible to implement without duplicating code for both > Ada.Finalization.Limited_Controlled and Ada.Finalization.Controlled? Oh, I thought one of .Finalization.Limited_Controlled and Ada.Finalization.Controlled is a child of another. This is not the case, so the code should be duplicated (not a big problem in practice, however). -- Victor Porton - http://portonvictor.org