comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: automatic tag conversion?
Date: Mon, 26 May 2003 10:29:59 +0200
Date: 2003-05-26T10:29:59+02:00	[thread overview]
Message-ID: <basj5q$32qm4$1@ID-77047.news.dfncis.de> (raw)
In-Reply-To: bararj$hk4$1@news.cs.tu-berlin.de

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



  reply	other threads:[~2003-05-26  8:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-23 23:04 automatic tag conversion? Stephan Heinemann
2003-05-23 23:57 ` Stephan Heinemann
2003-05-24 17:39   ` Georg Bauhaus
2003-05-25 20:59     ` Stephan Heinemann
2003-05-26  8:29       ` Dmitry A. Kazakov [this message]
2003-05-26 18:16         ` Georg Bauhaus
2003-05-26 18:27           ` Georg Bauhaus
2003-05-26 20:49             ` Stephan Heinemann
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox