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 X-Received: by 10.182.236.197 with SMTP id uw5mr2717138obc.32.1438350658680; Fri, 31 Jul 2015 06:50:58 -0700 (PDT) X-Received: by 10.140.22.167 with SMTP id 36mr24323qgn.4.1438350658644; Fri, 31 Jul 2015 06:50:58 -0700 (PDT) Path: buffer2.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!pg9no5698904igb.0!news-out.google.com!78ni1185qge.1!nntp.google.com!z61no4404891qge.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 31 Jul 2015 06:50:58 -0700 (PDT) In-Reply-To: <1ktkfm2fakx3h.28azibg1gr7y.dlg@40tude.net> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=81.203.145.32; posting-account=AFCLjAoAAABJAOf_HjgEEEi3ty-lG5m2 NNTP-Posting-Host: 81.203.145.32 References: <2df4698f-4c8e-457c-822d-209cb2f8ab5e@googlegroups.com> <014427b1-ff7a-4a69-82e6-0330af77ed96@googlegroups.com> <91f88d79-197c-419f-84a8-908e05967a2c@googlegroups.com> <135c2b00-d13c-4f5d-a586-8aca442d363b@googlegroups.com> <87380683vc.fsf@adaheads.sparre-andersen.dk> <347c6be9-c918-4bc0-9494-c93cd6740def@googlegroups.com> <4cb32c40-f659-490d-bbb6-73585fc069e8@googlegroups.com> <1ktkfm2fakx3h.28azibg1gr7y.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <80c91140-1bdc-49eb-ad93-04ba1c5241a2@googlegroups.com> Subject: Re: Running a preprocessor from GPS? From: EGarrulo Injection-Date: Fri, 31 Jul 2015 13:50:58 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.giganews.com comp.lang.ada:194573 Date: 2015-07-31T06:50:58-07:00 List-Id: On Friday, July 31, 2015 at 1:02:03 PM UTC+2, Dmitry A. Kazakov wrote: > > Apparently, the next version > > of GNATCOLL will include an alternative implementation[1] that removes this > > requirement. But this means that right now there is GNATCOLL.Refcount only. > > That will add a level of indirection as some other implementations do. I > don't see much merits doing this. There are no cases you might wish to have > another type as the base and furthermore it won't do any good anyway. I don't understand what you mean. A common case is when you have an existing class that wraps a resource and thus you can't change its base class. Therefore the only general solution is to use composition, not inheritance, for reference counting; like this, for example: generic type T is private; package Shared_Accesses is type Shared_Object is record Reference_Count : Natural; Object : T; end record; type Shared_Object_Access is access Shared_Object; type Shared_Access is -- Implementation of a controlled type that holds a Shared_Object_Access. end; end Shared_Accesses; > Because the only usable pattern of using strong pointers is this: > > type Object_Interface is interface; > -- define operations here > procedure Foo (X : in out Object_Interface) is abstract; > > in private > type Object_Implementation is > new Reference_Counted and Object_Interface with ... > -- implement operations here > overriding procedure Foo (X : in out Object_Implementation); > > in public > type Object is new Object_Interface with private; > -- implement operations here > overriding procedure Foo (X : in out Object); > > in private > type Object_Implementation_Ptr is access Object_Implementation'Class; > > type Object is new Strong_Reference with record > Ptr : Object_Implementation_Ptr; > end record; > > The implementation of Object's Foo delegates: > > procedure Foo (X : in out Object) is > begin > X.Ptr.Foo; > end Foo; > > If Object_Implementation must use some existing type, aggregate it. That > won't change anything, because public clients won't see > Object_Implementation anyway. Who cares what was the parent type of? I can't follow what the code does, sorry. What would be the equivalent of this C++ code: std::shared_ptr shared_object (new Object); in the above example? Thanks.