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 X-Google-Thread: 103376,22ab316b1096e177 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!2a02:590:1:1::196.MISMATCH!news.teledata-fn.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Tasks, Entries, and Variables of a Class-wide type Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-7" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <7e77bb8f-17b6-4d51-9946-ea825f726682@f33g2000yqh.googlegroups.com> Date: Mon, 1 Nov 2010 10:21:09 +0100 Message-ID: NNTP-Posting-Date: 01 Nov 2010 10:21:09 CET NNTP-Posting-Host: 859a5194.newsspool4.arcor-online.net X-Trace: DXC=III>lZBXmHHA@P]\D4IUK67Cdc?2D[6LHn;2LCVN7enW;^6ZC`D\`mfM[68DCCFBQQ]2R^Z>@ X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:16061 Date: 2010-11-01T10:21:09+01:00 List-Id: On Sun, 31 Oct 2010 22:40:37 -0700 (PDT), Shark8 wrote: > I�d originally wanted to have something like this: > > Task Type Parser_Task is > Entry Parse( Input : in out String ) Return PostScript_Object�Class; > End Parser; This does not make sense, because it would parse during a rendezvous. So the effect on the caller would be same as if the caller would parse on its own context. Why not to make parsing a plain function then? In order to take an advantage of tasking it should be like: task type Parser_Task is entry Request_Parsing (Input : String); entry Wait_For_Result (Output : out Post_Script_Object); end Parser; > is invalid because the tags won�t match. We now have the problem where > the class-wide type needs to know what particular object the parser > will return, and the parser needs that class-wide variable wherein to > store the type in the first place. {A programming Catch-22 or Chicken/ > Egg problem} > > I figured out how to work around this problem, however. Inside the > Parser_Task we can do something like the following: > > Task body Parse_Task is > [...] > Accept Parse( Input : in out String; Object : Out > PostScript_Object�Class ) do > Declare > Temp : PostScript_Object�Class:= Parse_Function( Input ); > For Temp�Address use Output�Address; > Begin > Null; > End; > End Parse; > [...] A bad idea. What you could do is to use the generic dispatching constructor (ARM 3.9). Here is the outline: package Parsers is type Parser_Task; type Post_Script_Object is tagged null record; function Constructor (Parser : not null access Parser_Task) return Post_Script_Object; task type Parser_Task is entry Request (Input : String); entry Wait_For_Result (Output : out Tag); entry Get_Result (Output : out Post_Script_Object'Class); end Parser_Task; function Get_Object is new Ada.Tags.Generic_Dispatching_Constructor (Post_Script_Object, Parser_Task, Constructor); end Parsers; The implementation: package body Parsers is function Constructor (Parser : not null access Parser_Task) return Post_Script_Object is begin return Result : Post_Script_Object do Parser.Get_Result (Result); end return; end Constructor; task body Parser_Task is Source : Unbounded_String; begin loop select accept Request (Input : String) do Source := To_Unbounded_String (Input); end Request; or terminate; end select; -- Here we parsing the stuff in Source. It will create all -- sorts of objects derived from Post_Script_Object. -- For example: declare Result : Post_Script_Object'Class := Post_Script_Object'(null record); begin accept Wait_For_Result (Output : out Tag) do Output := Result'Tag; end Wait_For_Result; accept Get_Result (Output : out Post_Script_Object'Class) do Output := Result; end Get_Result; end; end loop; end Parser_Task; end Parsers; Note, you will need to override Constructor for each type derived from Post_Script_Object. Here is how to use it on the client side: Worker : aliased Parser_Task; begin Worker.Request ("..."); declare Result_Type : Tag; begin Worker.Wait_For_Result (Result); -- Now we know the type declare Object : Post_Script_Object'Class := Get_Object Result_Type, Worker'Access); begin -- Doing something with object; end; end; Note, you can also pack Wait_For_Result into Constructor, but then you will not be able to wait for the parser in a timed entry call. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de