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!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed3-a.proxad.net!nnrp1-2.free.fr!not-for-mail From: William FRANCK Newsgroups: comp.lang.ada Date: Thu, 17 Oct 2019 11:28:08 +0200 Message-ID: <5da83417$0$31419$426a34cc@news.free.fr> References: <5da4cf81$0$20312$426a74cc@news.free.fr> <5da4e182$0$20321$426a74cc@news.free.fr> <55cpF.815759$bv6.689110@fx04.am4> <5da777d4$0$21611$426a34cc@news.free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: How to transfer Class-Wide object to a Task ? User-Agent: Unison/2.2 Organization: Guest of ProXad - France NNTP-Posting-Date: 17 Oct 2019 11:27:51 CEST NNTP-Posting-Host: 94.199.126.21 X-Trace: 1571304471 news-4.free.fr 31419 94.199.126.21:62700 X-Complaints-To: abuse@proxad.net Xref: reader01.eternal-september.org comp.lang.ada:57309 Date: 2019-10-17T11:27:51+02:00 List-Id: On 2019-10-16 20:04:41 +0000, William FRANCK said: I've uploaded my PoC source file on the comp.lang.ada group. main_ClassWide_to_2Task.adb "Transfering Class-Wide Objects to task-entries, with Ada.Containers.Indefinite_Holders." -- ==== here it is as a copy ===== with Ada.Containers.Indefinite_Holders, Ada.Text_IO; use Ada, Ada.Text_IO; procedure main_ClassWide_to_2Task is -- ======================================================================== -- Demo program showing how to transfer Class-Wide objects to task-entries, -- with Ada.Containers.Indefinite_Holders -- ======================================================================== type Geo2D is tagged record Y, X : Integer; Name : String (1 .. 8) := "Object 0"; end record; type Circle is new Geo2D with record Radius : Integer; end record; package Geo2D_Holders is new Ada.Containers.Indefinite_Holders (Geo2D'Class); myDataStore : Geo2D_Holders.Holder; -- ========================================================== package Object_Reading is task reading is entry Open; entry Object (DataStore : in out Geo2D_Holders.Holder); entry Stop; end reading; end Object_Reading; -- ========================================================== package Object_Writing is task writing is entry Create; entry Object (DataStore : in Geo2D_Holders.Holder); entry Stop; end writing; end Object_Writing; -- ========================================================== package body Object_Reading is task body reading is LocalDataStore : Geo2D_Holders.Holder; Nb_items : Natural := 0; -- for tracing begin accept Open do -- end go further only after open is complete Text_IO.Put_Line (Standard_Error,"Opening file ..."); end Open; Text_IO.Put_Line (Standard_Error,"Input file ready !"); loop select accept Object (DataStore : in out Geo2D_Holders.Holder) do DataStore := Geo2D_Holders.Copy (Source => LocalDataStore); end Object; declare -- (shortcut to simulate real case with Streams and *'Class'Input dispatching) :: --Object : constant Geo2D'Class := Dispatching_Input (Ada.Tags.Internal_Tag (External_Tag), Stream); O2D : Geo2D'Class := Circle'(0, 0, "Cercle 0", 10); -- simulate object creation done by 'Dispatching_Input' begin NB_Items := NB_Items +1; -- for demo O2D.Name(7..8) := Natural'Image(Nb_Items); -- for demo Text_IO.Put_Line (Standard_Error,"Reading 2D Object #"& Natural'Image(Nb_Items)&": " & O2D.Name); -- debug trace Geo2D_Holders.Replace_Element (Container => LocalDataStore, New_Item => O2D); end; or accept Stop do Text_IO.Put_Line (Standard_Error,"Closing Input file..."); end Stop; Text_IO.Put_Line (Standard_Error,"File cloded, Reading Stopped !"); exit; end select; end loop; end reading; end Object_Reading; -- ========================================================== package body Object_Writing is task body writing is LocalDataStore : Geo2D_Holders.Holder; Nb_items : Natural := 0; begin accept Create; -- and go ahead (with i.e. opening input file) Text_IO.Put_Line (Standard_Error,"Creating file ..."); Text_IO.Put_Line (Standard_Error,"Output file ready !"); loop select accept Object (DataStore : in Geo2D_Holders.Holder) do LocalDataStore := Geo2D_Holders.copy (DataStore ); end Object; -- go return to the main process, and go ahead with reading next record if not Geo2D_Holders.Is_Empty(Container => LocalDataStore) then declare O2D : Geo2D'Class := Geo2D_Holders.Element (Container => LocalDataStore); begin NB_Items := NB_Items +1; -- for demo -- (shortcut to simulate real case with Streams and *'Class'Output dispatching) :: Text_IO.Put_Line (Standard_Error," Writing 2D Object #"& Natural'Image(Nb_Items)&": " & O2D.Name); -- debug trace end; end if; or accept Stop do Text_IO.Put_Line (Standard_Error,"Closing Output file..."); end Stop; Text_IO.Put_Line (Standard_Error,"File Closed, Writing Stopped ! "); exit; end select; end loop; end writing; end Object_Writing; -- ========================================================== use Object_Reading; use Object_Writing; begin Writing.Create; Reading.Open; for i in 1 .. 9 loop -- While not end_of_file() Reading.Object (myDataStore); Writing.Object (myDataStore); end loop; Reading.Stop; Writing.Stop; end main_ClassWide_to_2Task;