comp.lang.ada
 help / color / mirror / Atom feed
From: Michael Erdmann <michael.erdmann@snafu.de>
To: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Q: Endless loop by dispatching
Date: Fri, 11 Jul 2003 17:07:52 +0200
Date: 2003-07-11T17:07:52+02:00	[thread overview]
Message-ID: <3F0ED2C8.6080409@snafu.de> (raw)
In-Reply-To: <uu0tgv8ru6be67limc43p4itiu46s4ac19@4ax.com>

Dmitry A. Kazakov wrote:

>>Does any body know, what this loop causes?! I am not sure
>>if this is a bug or simply i missed the point.
> 
> 
> Serialize is class-wide and a view conversion does not change the
> tag..I.e. you have a re-dispatching case. Re-dispatching is a
> dangerous thing. [I would like it removed from Ada]
> 
> So Serialize re-dispatches to B.Write which again calls Serialize.
> From design point of view, one should never call class-wide routines
> from specific ones, this warranties that dispatch happens only once.
> 
> I suppose that you want sort of procedure expansion instead of
> complete overriding, if so, then you should explicitly call parent's
> Write, similarly as one does it for Initialize/Finalize:
> 
Unfortuantly this was not the complete code. The Serialize was itended
to do a  more complex job, which i have to replicate any where i want
to serialize an object. The original serialize code looks some what
like this:

procedure Serialize( This : in Object'Class ) is
   ........
    a := next(Attributes(This'Tag))
    while a /= null loop
        Write( this.all, a.id );
        a := next(....);
    end loop;

end;

The procedure write is a procedures which  writes out a selected 
attribute of an object. The procedure Serialize the complete
object. I would have been great when i could write something
like this in ada:

procedure Serialize( This : in Object'Class ) is

    Serialize( Super( This ) );

    a := next(Attributes(This'Tag))
    while a /= null loop
        Write( this.all, a.id );
        a := next(....);
    end loop;

end;


I think something like this does not exist in Ada!?


> package body B is
> ...
> procedure Write (This : in Object) is
> begin
> --       A.Serialize( A.Object( This ) );
>    A.Write (A.Object (This)); -- Write parent's things
>    Put_Line( "Q =" & Natural'Image(This.Q));
> end Write;
> 
> BTW, why do not you use Ada.Streams? It is for things like this.

I fact i am using Ada.Stream, but as i have written above the code was
simply a consended version.
> 
> ---
> Regards,
> Dmitry Kazakov
> www.dmitry-kazakov.de




  reply	other threads:[~2003-07-11 15:07 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-11  8:22 Q: Endless loop by dispatching Michael Erdmann
2003-07-11  9:46 ` Jean-Pierre Rosen
2003-07-11 15:19   ` Michael Erdmann
2003-07-11 10:01 ` Q: " Dmitry A. Kazakov
2003-07-11 15:07   ` Michael Erdmann [this message]
2003-07-12  1:41     ` Jeffrey Carter
2003-07-14  8:48     ` Dmitry A. Kazakov
2003-07-14 18:38       ` Randy Brukardt
2003-07-15  8:47         ` Dmitry A. Kazakov
2003-07-15 17:23           ` Randy Brukardt
2003-07-16  8:08             ` Dmitry A. Kazakov
2003-07-16 17:44               ` Robert I. Eachus
2003-07-17  1:57               ` Robert A Duff
2003-07-18  9:10                 ` Dale Stanbrough
2003-07-18 20:26                   ` Robert I. Eachus
2003-07-18 21:35                     ` tmoran
2003-07-19  0:25                       ` Robert I. Eachus
2003-07-19  2:30                         ` tmoran
2003-07-19  5:48                           ` Robert I. Eachus
2003-07-21  8:38                             ` Dmitry A. Kazakov
2003-07-21 10:08                               ` Robert I. Eachus
2003-07-21 13:21                                 ` Dmitry A. Kazakov
2003-07-21 18:51                                   ` Robert I. Eachus
2003-07-22  7:41                                     ` Dmitry A. Kazakov
2003-07-22 10:36                                       ` Lutz Donnerhacke
2003-07-22 12:11                                         ` Dmitry A. Kazakov
2003-07-22 12:18                                           ` Lutz Donnerhacke
2003-07-22 14:46                                             ` Dmitry A. Kazakov
2003-07-22 15:11                                               ` Lutz Donnerhacke
2003-07-23  8:12                                                 ` Dmitry A. Kazakov
2003-07-19 14:44                     ` Chad R. Meiners
2003-07-20 12:36                       ` Robert I. Eachus
2003-07-11 16:27 ` T. Kurt Bond
2003-07-12  8:37   ` Michael Erdmann
2003-07-15  7:11     ` Kenneth Almquist
replies disabled

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