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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e044473b43baaf18 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-26 01:27:40 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!dialin-145-254-037-224.arcor-ip.NET!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: automatic tag conversion? Date: Mon, 26 May 2003 10:29:59 +0200 Organization: At home Message-ID: References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: dialin-145-254-037-224.arcor-ip.net (145.254.37.224) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: fu-berlin.de 1053937659 3238596 145.254.37.224 (16 [77047]) User-Agent: KNode/0.7.1 Xref: archiver1.google.com comp.lang.ada:37776 Date: 2003-05-26T10:29:59+02:00 List-Id: Stephan Heinemann wrote: > I am using generic sets like this one: > > generic > type Element is private; > package CNAda.Utils.Sets is > > type Set is private; > type LookProcedure is access procedure (e: in Element); > type MapProcedure is access procedure (e: in out Element); > > procedure empty(s: in out Set); > procedure insert(e: in Element; s: in out Set); > procedure remove(e: in Element; s: in out Set); > > procedure look(lookp: in LookProcedure; s: in Set); > procedure map(mapp: in MapProcedure; s: in Set); [...] > I use the following for instantiation of this package. > > type Node is abstract new Component with private; > type NodeClassAccess is access all Node'Class; > > package NodeClassAccessSets is new CNAda.Utils.Sets(NodeClassAccess); > > NodeClassAccessSets.Set is a component within another tagged (record) > type - a Net. > There are various derived types of Node like Transition, Place and > further Operation, Socket, Port and so on.... > > I want to apply a LookProcedure on the set for example to > print all elements of this set. There is a primitive operation print > defined on the types within the hierarchy: > > procedure print(n: access Node) is abstract; > procedure print(t: access Transition); > procedure print(p: access Place); > > ...and so on. I want the system to dispatch to the most special variant > of the procedure for the apropriate derived type like: > > NodeClassAccessSets.look(print'Access, s); > > It is clearly possible to pass in a NodeClassAccess variable with any > derived *ClassAccess value into a print procedure defined as above even if > the print procedure was not overridden by the new derived type. > The system would always dispatch the most special case, am I right? No, Element is of NodeClassAccess which is different from anonymous "access Node" (that will dispatch). Thus LookProcedure.all is not dispatching at all. However it will be sort of "class-wide" when NodeClassAccess is class-wide, as it is. So you practically have everything to make it working. Just define a wrapper in the same package, where Node is defined: procedure Print_Any (Ptr : NodeClassAccess) is begin Print (Ptr); -- Dispatches end Print_Any; Then NodeClassAccessSets.look (Print_Any'Access, s); should work as expected. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de