From: William FRANCK <william.franck@free.fr>
Subject: Re: How to transfer Class-Wide object to a Task ?
Date: Tue, 15 Oct 2019 07:43:47 +0200
Date: 2019-10-15T07:43:47+02:00 [thread overview]
Message-ID: <5da55c93$0$20322$426a74cc@news.free.fr> (raw)
In-Reply-To: 4cbdb7ee-96aa-4653-8bae-65aea700e8f5@googlegroups.com
Thank you Shark,
I'll give it a try too :-)
And send you all a more complete source code of my use case.
William
On 2019-10-14 21:57:57 +0000, Shark8 said:
> On Monday, October 14, 2019 at 2:21:50 PM UTC-6, William FRANCK wrote:
>> On 2019-10-14 19:41:53 +0000, William FRANCK said:
>>
> Maybe something like this:
>
> procedure Example is
> Package Types is
> Subtype Params is Ada.Streams.Root_Stream_Type'Class;
> Type Root is abstract tagged null record;
> Function Create (Parameters : not null access Params)
> return Root is abstract;
>
> Type Circle is new Root with record
> Radius : Float;
> end record;
>
> Type Square is new Root with record
> Side : Integer;
> end record;
> Private
>
> Function Create (Parameters : not null access Params)
> return Square;
> Function Create (Parameters : not null access Params)
> return Circle;
> End Types;
>
>
> Use Types;
> Package Class_Holder is new
> Ada.Containers.Indefinite_Holders(Root'Class);
> Task Type Producer( Stream : not null access
> Ada.Streams.Root_Stream_Type'Class ) is
> Entry Get( Object: out Class_Holder.Holder );
> End Producer;
>
> Task body Producer is
> Function MAKE is new Ada.Tags.Generic_Dispatching_Constructor(
> T => Types.Root,
> Parameters => Ada.Streams.Root_Stream_Type'Class,
> Constructor => Types.Create
> );
>
> Function To_Tag return Ada.Tags.Tag is
> Begin
> Return Square'Tag;
> -- (if Ch = 'C' then Circle'Tag
> -- elsif Ch = 'S' then Square'Tag
> -- else raise Constraint_Error with "Tag '"&Ch&"' is
> invalid.");
> End;
>
> Begin
> accept Get (Object : out Class_Holder.Holder) do
> Object:=
> Class_Holder.To_Holder( MAKE(To_Tag, Stream) );
> end Get;
> end Producer;
>
> Function Get(P : Producer) return Root'Class is
> H : Class_Holder.Holder;
> Begin
> P.Get(H);
> Return H.Element;
> End Get;
>
>
>
> Package Body Types is
> Function Create(Parameters : not null access Params) return
> Square is
> Begin
> Return (Side => 3);
> End;
>
> Function Create(Parameters : not null access Params) return
> Circle is
> Begin
> Return (Radius => 2.2);
> End;
> End Types;
>
> begin
> Ada.Text_IO.Put_Line( "START EXAMPLE." );
> declare
> I : Ada.Text_IO.File_Type renames Ada.Text_IO.Standard_Input;
> P : Producer( Ada.Text_IO.Text_Streams.Stream(I) );
> O : Root'Class := Get(P);
> begin
> Ada.Text_IO.Put_Line( "Tag: " & Ada.Tags.Expanded_Name(O'Tag) );
> end;
> Ada.Text_IO.Put_Line( "STOP EXAMPLE." );
> end Example;
prev parent reply other threads:[~2019-10-15 5:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 19:41 How to transfer Class-Wide object to a Task ? William FRANCK
2019-10-14 19:55 ` Shark8
2019-10-14 20:48 ` William FRANCK
2019-10-14 22:01 ` Shark8
2019-10-15 5:13 ` William FRANCK
2019-10-14 19:58 ` Dmitry A. Kazakov
2019-10-14 20:58 ` William FRANCK
2019-10-15 4:40 ` Per Sandberg
2019-10-15 5:40 ` William FRANCK
2019-10-16 20:04 ` William FRANCK
2019-10-16 23:43 ` Anh Vo
2019-10-17 9:28 ` William FRANCK
2019-10-17 10:00 ` Dmitry A. Kazakov
2019-10-17 10:45 ` William FRANCK
2019-10-15 7:21 ` Dmitry A. Kazakov
2019-10-15 14:31 ` Optikos
2019-10-15 19:41 ` William FRANCK
2019-10-15 20:03 ` Shark8
2019-10-14 20:21 ` William FRANCK
2019-10-14 20:32 ` Dmitry A. Kazakov
2019-10-14 21:04 ` William FRANCK
2019-10-14 21:57 ` Shark8
2019-10-15 5:43 ` William FRANCK [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox