comp.lang.ada
 help / color / mirror / Atom feed
From: "per" <commander@death-star.com>
Subject: Re: OO problem: Performing actions on messages (very long, sorry)
Date: 4 Jan 2005 07:21:39 -0800
Date: 2005-01-04T07:21:39-08:00	[thread overview]
Message-ID: <1104852099.054703.265080@f14g2000cwb.googlegroups.com> (raw)
In-Reply-To: <1ogeykubpns90.2jnblmdu1wg2.dlg@40tude.net>

Ah, we understand each other!

Dmitry:

>OK, try this:

>generic
>  type Argument_Type is private;
>  type Message_Type is new Message with private;

The above will force the Message_Type to be an ancestor of Message,
right? So Message_Type is still generic but have some additional
restrictions...?

>  with procedure Put (This : in out Message_Type; Value :
Argument_Type);
>package Action.Generic_Override is
>  type Override is new Action with record
>     Argument : Argument_Type;
>  end record;
>  Execute (This : in out Override; Message : in Message'Class);
>end Action.Generic_Override;

>package body Action.Generic_Override is
>  ...
>  Execute (This : in out Override; Message : in Message'Class) is
>  begin
>     if This not in Message_Type'Class then

Do you mean "Message" instead of "This"?

>        Ada.Exceptions.Raise_Exception
>        (  Constraint_Error'Identity,
>           "Illegal message type in Execute, found " &
>           Ada.Tags.External_Tag (Message'Tag) &
>           "expected a descendant of:"
>           Ada.Tags.External_Tag (Message_Type'Tag) &
>        );

(Wow!)

>     end if;
>     Put (Message_Type'Class (Message), This.Argument);

The conversion is needed to be compatible with the declaration of Put,
right?

And since argument Message is within Message'Class AND Message_Type is
a descendant of Message it will work?

>  end Execute;
>  ...

>You have to instantiate Action.Generic_Override for each combination
of
>parameter / message. For example:

>package Action_on_B_for_M2 is
>  new Action.Override
>      (  Argument_Type => Float;
>         Message_Type => M2;
>         Put => Put_B
>      );

I see! So you're saying that I need one instantiation for each
*Put-procedure* and message (instead of one for each *type* and
message)? Hm, that's a lot of instances in my system...

This may be the solution I looked for, and I think I'll give it a try
(as soon as I get used to all those instances :).

Thanks a lot Dmitry and others for your efforts on this issue! I've
learned lots of other Ada stuff on the way.

Finally, Dmitry, would this be your solution if you were free to solve
it anyway you like?




  reply	other threads:[~2005-01-04 15:21 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-22 13:49 OO problem: Performing actions on messages (very long, sorry) per
2004-12-22 15:17 ` Dmitry A. Kazakov
2004-12-22 16:28 ` Martin Krischik
2004-12-22 17:42   ` per
2004-12-22 18:16     ` Martin Krischik
2004-12-22 19:54     ` Dmitry A. Kazakov
2005-01-03 12:37       ` per
2005-01-03 14:14         ` Dmitry A. Kazakov
2005-01-04 12:05           ` per
2005-01-04 13:30             ` Dmitry A. Kazakov
2005-01-04 15:21               ` per [this message]
2005-01-04 17:47                 ` Dmitry A. Kazakov
2005-01-05 12:01                   ` per
2005-01-05 13:23                     ` Dmitry A. Kazakov
2005-01-05 15:59                       ` per
2005-01-05 20:44                         ` Dmitry A. Kazakov
2005-01-10  8:42                           ` per
2005-01-10 14:22                             ` Dmitry A. Kazakov
2005-01-10 16:24                               ` per
2005-01-10 19:09                                 ` Dmitry A. Kazakov
2005-01-11  9:06                                   ` per
2004-12-22 17:46   ` per
2004-12-22 18:02     ` Martin Krischik
2005-01-03 10:05       ` per
2004-12-22 18:35     ` u_int32_t
2004-12-22 18:38       ` u_int32_t
2004-12-24 18:52 ` Nick Roberts
2005-01-03 16:59   ` per
2005-01-10 12:10   ` per
2005-01-10 13:49     ` Marius Amado Alves
2005-01-10 21:54 ` Simon Wright
replies disabled

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