* Re: dispatching query
[not found] <34CFD22D.1D20CEA9@dsto.defence.gov.au>
@ 1998-02-04 0:00 ` John English
1998-02-05 0:00 ` Stephen Leake
1 sibling, 0 replies; 2+ messages in thread
From: John English @ 1998-02-04 0:00 UTC (permalink / raw)
Mark Rutten (Mark.Rutten@dsto.defence.gov.au) wrote:
: Is it only possible to dispatch on subprograms which can be inherited
: (i.e. specified in the same declarative block)?
You're talking about primitives. Dispatching happens when you have a
class wide type (X'Class).
: package messages is
: type message is abstract tagged null record;
: type message_ptr is access all message'Class;
: procedure copy(msg: access message) is abstract;
: end messages;
: Then (in some other package) I declare a type (or several types) which
: extend message. What I would like to do is to define a set of procedures
: in a third package (separate to the declarations of the types) which can
: be dispatched upon
: e.g.
: procedure handle(msg: access boolean_message);
: procedure handle(msg: access integer_message);
So, make handle a primitive of Message (abstract if necessary) and
then hand it a class-wide pointer (an access Message'Class) to make
it dispatch. That is, add
procedure Handle (Msg : access Message) is abstract;
to Messages, and then call Handle(This_Message'Access)
(where This_Message is a Message'Class object).
-----------------------------------------------------------------
John English | mailto:je@brighton.ac.uk
Senior Lecturer | http://www.it.bton.ac.uk/staff/je
Dept. of Computing | ** NON-PROFIT CD FOR CS STUDENTS **
University of Brighton | -- see http://burks.bton.ac.uk
-----------------------------------------------------------------
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: dispatching query
[not found] <34CFD22D.1D20CEA9@dsto.defence.gov.au>
1998-02-04 0:00 ` dispatching query John English
@ 1998-02-05 0:00 ` Stephen Leake
1 sibling, 0 replies; 2+ messages in thread
From: Stephen Leake @ 1998-02-05 0:00 UTC (permalink / raw)
Mark Rutten wrote:
>
> Is it only possible to dispatch on subprograms which can be inherited
> (i.e. specified in the same declarative block)?
This is correct; see LRM 3.9.2. A dispatching operation is a primitive
operation, which is declared in the same block as the tagged type.
>
> e.g.
>
> package messages is
>
> type message is abstract tagged null record;
> type message_ptr is access all message'Class;
>
> procedure copy(msg: access message) is abstract;
>
> end messages;
>
> Then (in some other package) I declare a type (or several types) which
> extend message. What I would like to do is to define a set of procedures
> in a third package (separate to the declarations of the types) which can
why do you want the operations in a third package?
If you want to hide the operations from some parts of the application,
you can declare the operations in the private part of the package spec.
> be dispatched upon
>
> e.g.
>
> procedure handle(msg: access boolean_message);
> procedure handle(msg: access integer_message);
>
> where boolean_message and integer_message have been inherited from
> message and are declared in the second package. Then I would like to
> call
>
> handle(msg);
>
> (msg of type message_ptr) and have this dispatch on the above two
> procedures.
>
> I guess what I'm really trying to do is to replace what might be a case
> statement over the different inherited types with this set of
> procedures. I've tried the above with gnat3.09 on Solaris, but it
> complains at having too many choices when trying to resolve the
> procedure call, rather than recognising a dispatchable operation. Is
> there a way around this?
As you guessed, you must declare dispatching operations with the types.
--
- Stephe
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-02-05 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <34CFD22D.1D20CEA9@dsto.defence.gov.au>
1998-02-04 0:00 ` dispatching query John English
1998-02-05 0:00 ` Stephen Leake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox