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-Thread: 103376,a8d137db7a5f6c81 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "per" Newsgroups: comp.lang.ada Subject: Re: OO problem: Performing actions on messages (very long, sorry) Date: 4 Jan 2005 07:21:39 -0800 Organization: http://groups.google.com Message-ID: <1104852099.054703.265080@f14g2000cwb.googlegroups.com> References: <1103723394.299024.314670@c13g2000cwb.googlegroups.com> <13465377.hrn0RlrJV7@linux1.krischik.com> <1103737351.196460.85450@f14g2000cwb.googlegroups.com> <1qdvdjid4u58v.1xz6j5ec6nfcy$.dlg@40tude.net> <1104755823.837077.74630@z14g2000cwz.googlegroups.com> <8oknh024yb43$.71qlyp6g8y2x$.dlg@40tude.net> <1104840326.160879.132400@c13g2000cwb.googlegroups.com> <1ogeykubpns90.2jnblmdu1wg2.dlg@40tude.net> NNTP-Posting-Host: 138.14.239.132 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104852103 22405 127.0.0.1 (4 Jan 2005 15:21:43 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 4 Jan 2005 15:21:43 +0000 (UTC) In-Reply-To: <1ogeykubpns90.2jnblmdu1wg2.dlg@40tude.net> User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=138.14.239.132; posting-account=e84-wQ0AAADeDLnjH5yWqnRMVsJLfQJg Xref: g2news1.google.com comp.lang.ada:7426 Date: 2005-01-04T07:21:39-08:00 List-Id: 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?