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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5ee499d03212eed3 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-06 10:52:30 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!feed.textport.net!out.nntp.be!propagator-SanJose!news-in-sanjose!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Dynamic dispatch again References: <3BBE5993.1CF0069D@san.rr.com> X-Newsreader: Tom's custom newsreader Message-ID: Date: Sat, 06 Oct 2001 17:52:30 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 1002390750 24.7.82.199 (Sat, 06 Oct 2001 10:52:30 PDT) NNTP-Posting-Date: Sat, 06 Oct 2001 10:52:30 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:13835 Date: 2001-10-06T17:52:30+00:00 List-Id: >OK, I'm still trying to figure out how to make one entry call wind up >calling code in different units. >... >Essentially, I have a basic manager task doing I/O, distributing >messages to "profiles". Each "profile" can get the same set of messages >(start, stop, are you ready, here's a message), but each responds to the >messages in different ways. How about having a single "profile" task, and using tagged type "methods" to respond in different ways, eg: package profile is type changeable_content is abstract tagged limited null record; type changeable_content_pointer is access all changeable_content'class; procedure xlate_content(what_to_do : in changeable_content; in_in : in integer; out_out : out integer) is abstract; task type general_task(content : changeable_content_pointer) is entry xlate(in_in : in integer; out_out : out integer); end general_task; type general_task_pointer is access general_task; end profile; package body profile is task body general_task is begin loop select accept xlate(in_in : in integer; out_out : out integer) do xlate_content(content.all, in_in, out_out); end xlate; or terminate; end select; end loop; end general_task; end profile; with profile; package double is type content is new profile.changeable_content with null record; procedure xlate_content(what_to_do : in content; in_in : in integer; out_out : out integer); end double; package body double is procedure xlate_content(what_to_do : in content; in_in : in integer; out_out : out integer) is begin out_out := in_in + in_in; end xlate_content; end double; with profile; package negate is type content is new profile.changeable_content with null record; procedure xlate_content(what_to_do : in content; in_in : in integer; out_out : out integer); end negate; package body negate is procedure xlate_content(what_to_do : in content; in_in : in integer; out_out : out integer) is begin out_out := - in_in; end xlate_content; end negate; with profile; with double; with negate; with Ada.Text_IO; procedure driver is type pat is array(1..2) of profile.general_task_pointer; pa : pat; i : integer; doubler : profile.changeable_content_pointer := new double.content; negater : profile.changeable_content_pointer := new negate.content; begin pa(1) := new profile.general_task(doubler); pa(2) := new profile.general_task(negater); pa(1).xlate(100, i); Ada.Text_IO.Put_Line("First, " & Integer'Image(I)); pa(2).xlate(100, i); Ada.Text_IO.Put_Line("Second, " & Integer'Image(I)); end driver;