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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Running a preprocessor from GPS? Date: Fri, 31 Jul 2015 13:01:49 +0200 Organization: cbb software GmbH Message-ID: <1ktkfm2fakx3h.28azibg1gr7y.dlg@40tude.net> 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> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: ChlmA4XFxcJoDoqGdDSflw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:27261 Date: 2015-07-31T13:01:49+02:00 List-Id: On Fri, 31 Jul 2015 02:31:26 -0700 (PDT), EGarrulo wrote: > On Friday, July 31, 2015 at 11:13:21 AM UTC+2, Dmitry A. Kazakov wrote: >> Soft/weak reference/pointer is a pointer that does not prevent collection, >> but itself becomes invalid if collection occurs. [To access the target, a >> strong pointer is obtained from the weak pointer, the object is accessed >> through it, and then the strong pointer is disposed.] >> [...] >> Yes, there exist many implementations in Ada *and* there is no reason to >> have it in the language, as it can be implemented at the library level. > > Many? Do you mean many libraries that implement "shared/weak pointer" > semantics? Because I only know of GNATCOLL.Refcount, but this library > requires you "to create a new tagged type that extends > GNATCOLL.Refcount.Refcounted, so > that it has a counter." This can be impractical. Can be, but isn't. My implementation also uses a base type: http://www.dmitry-kazakov.de/ada/components.htm#Objects_etc It has weak pointers as well: http://www.dmitry-kazakov.de/ada/components.htm#persistent_objects > 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. 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? If you mean that this is too complex for your case, then you probably need no smart pointers at all, which is, my estimate, 95% of cases when smart pointers come into consideration. As others many times said pointers rarely needed in Ada. Cases when in C++ you would use a pointer are handled by the language itself. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de