From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Extending a third party tagged type while adding finalization
Date: Mon, 27 Nov 2017 10:10:55 -0800 (PST)
Date: 2017-11-27T10:10:55-08:00 [thread overview]
Message-ID: <24767ee5-cda8-45e4-98d1-7da44757bd40@googlegroups.com> (raw)
In-Reply-To: <6106dfe6-c614-4fc1-aace-74bf8d7435e3@googlegroups.com>
On Sunday, November 26, 2017 at 10:33:50 AM UTC-7, Jere wrote:
>
> What I tried to do was use a mixin but have it keep a reference to a
> classwide access on the object. Then I tried dispatching out to the
> correct object type from there. This kind of highlighted the evils
> of using redispatch in Ada though as I found that if I had component
> definitions like this:
JP Rosen's paper "A Naming Convention for Classes in Ada 9X" details a way you might be able to ease the pain of such constructs.
The example of adding a "with benefits" extension to "computer scientist" which is itself an "employee" is detailed as follows:
with Employee; use Employee;
generic
type Origin is new Employee.lnstance with private;
packaqe With_Benefits_Facet is
type Instance is new Origin with private;
subtype Class is Instance'Class;
-- Operations to handle benefits private
end With__Benefits_Facet;
--------------------------------
with Computer__Scientist, With_Benefits_Facet; use Computer_Scientist;
package Computer_Scientists__With__Benefits is
new With__Benefits__Facet(Computer_Scientist. Instance);
So, to do this sort of thing how you want, couldn't you handle things via generic?
Generic
-- You might want to put a Base here and derive from it...
Type Controlled is limited private;
with procedure Initialize (Object : in out Controlled) is null;
with procedure Adjust (Object : in out Controlled) is null;
with procedure Finalize (Object : in out Controlled) is null;
Package Controlled_Mixin is
Type Instance is new Ada.Finalization.Limited_Controlled with record
Component : Controlled;
end record;
--...
End Controlled_Mixin;
>
> Based on what I have read so far, I didn't see any discussion that would
> lead me to think this will be changed at least in the near future. I
> wish there was a way it would be easy for vendors to do something like:
>
> type Some_Type is tagged private;
> for Some_Type'Initialize use Initialize_Some_Type;
> for Some_Type'Adjust use Adjust_Some_Type;
> for Some_Type'Finalize use Finalize_Some_Type;
>
> and then just have the compiler handle adding the needed structures
> to the type under the hood (like how GNAT uses Controlled to hold
> a linked list under the hood...but compiler managed).
That would be pretty nice.
next prev parent reply other threads:[~2017-11-27 18:10 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-22 12:43 Extending a third party tagged type while adding finalization Jere
2017-11-22 16:42 ` AdaMagica
2017-11-26 17:33 ` Jere
2017-11-26 18:15 ` Dmitry A. Kazakov
2017-11-26 19:31 ` Jere
2017-11-27 9:46 ` AdaMagica
2017-11-27 12:56 ` Jere
2017-11-27 15:00 ` AdaMagica
2017-11-27 16:38 ` Jere
2017-11-27 18:37 ` AdaMagica
2017-11-27 19:53 ` Jere
2017-11-28 11:48 ` AdaMagica
2017-12-03 2:22 ` Jere
2017-12-03 21:53 ` Robert Eachus
2017-12-04 7:58 ` Dmitry A. Kazakov
2017-12-04 14:59 ` Robert Eachus
2017-12-04 15:39 ` Dmitry A. Kazakov
2017-11-27 18:10 ` Shark8 [this message]
2017-11-27 19:56 ` Jere
2017-11-28 1:55 ` Randy Brukardt
2017-12-03 2:47 ` Jere
2017-12-03 9:29 ` Dmitry A. Kazakov
2017-12-03 15:10 ` AdaMagica
2017-12-03 16:39 ` Dmitry A. Kazakov
2017-12-03 19:34 ` AdaMagica
2017-12-03 19:41 ` Dmitry A. Kazakov
2017-12-04 12:38 ` AdaMagica
2017-12-04 13:19 ` AdaMagica
2017-12-04 13:55 ` Dmitry A. Kazakov
2017-12-04 15:44 ` AdaMagica
2017-12-04 16:19 ` Dmitry A. Kazakov
2017-12-04 20:54 ` Randy Brukardt
2017-12-04 21:02 ` Dmitry A. Kazakov
2017-12-05 21:09 ` Randy Brukardt
2017-12-05 21:29 ` Dmitry A. Kazakov
2017-12-07 1:13 ` Randy Brukardt
2017-12-07 8:36 ` Dmitry A. Kazakov
2017-12-07 23:22 ` Randy Brukardt
2017-12-08 9:30 ` Dmitry A. Kazakov
2017-12-09 0:17 ` Randy Brukardt
2017-12-11 9:03 ` Dmitry A. Kazakov
2017-12-11 22:42 ` Randy Brukardt
2017-12-12 16:11 ` AdaMagica
2017-12-12 20:08 ` G. B.
2017-12-12 20:32 ` 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