[ wxwindows-Patches-1687073 ] wxStreamBase should inherit wxObject

SourceForge.net noreply at sourceforge.net
Mon Apr 2 10:54:52 PDT 2007


Patches item #1687073, was opened at 2007-03-23 22:32
Message generated for change (Comment added) made by stsp
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=309863&aid=1687073&group_id=9863

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Common
Group: bug fix
>Status: Open
Resolution: None
Priority: 3
Private: No
Submitted By: Stas Sergeev (stsp)
Assigned to: Nobody/Anonymous (nobody)
Summary: wxStreamBase should inherit wxObject

Initial Comment:
Hi.

It seems the stream classes do not work with the
RTTI of wx. So that the one can't wxDynamicCast
the wxOutputStream* to wxMemoryOutputStream* for
example.
Of course the native RTTI can still be used, but...
the patch is attached.

----------------------------------------------------------------------

>Comment By: Stas Sergeev (stsp)
Date: 2007-04-02 21:54

Message:
Logged In: YES 
user_id=501371
Originator: YES

> Or else I'm
> missing something really fundamental.
Yes, you do, although perhaps not so fundamental
after all. :)
wxDynamicCast does not fail with my patch. I
tested it, rechecked and double-checked.
Actually, I was checking it so much that found
that it actually simply never returns NULL at all,
even when it should. :(
So yes, it is broken. Not exactly as per your
expectations, but its still the same.
Attached is another patch.
But now, after messing around those stupid macros,
I can see why you were sceptical about that patch.
I myself now am. If you still don't want to apply
such a patch, then maybe are there any plans to
make the wxRTTI be simply a wrapper of a native RTTI?
File Added: dcastrm1.diff

----------------------------------------------------------------------

Comment By: Vadim Zeitlin (vadz)
Date: 2007-03-31 18:55

Message:
Logged In: YES 
user_id=71618
Originator: NO

wxDynamicCast will compile, of course, with this patch -- but it won't
work, i.e. upcasting will always fail (return NULL). It can't, really, if
you don't define wxClassInfo for the derived classes correctly. Or else I'm
missing something really fundamental.

----------------------------------------------------------------------

Comment By: Stas Sergeev (stsp)
Date: 2007-03-31 12:12

Message:
Logged In: YES 
user_id=501371
Originator: YES

Thats a bit strange - I am _using_ that patch
for my prog, and it seems to work. And without
the patch, the wxDynamicCast(ptr, wxMemoryOutputStream)
doesn't even compile.
Could you please double-check if it is really
broken? I'll take a closer look, although not
before the monday.

----------------------------------------------------------------------

Comment By: Vadim Zeitlin (vadz)
Date: 2007-03-31 00:01

Message:
Logged In: YES 
user_id=71618
Originator: NO

Ok, I'm convinced by your arguments. But looking at the patch itself, it
seems to be useless as while it changes the base class it doesn't add all
the necessary DECLARE_DYNAMIC_CLASS() macros so wxRTTI still doesn't know
anything about the stream classes. Could you please add them?

----------------------------------------------------------------------

Comment By: Stas Sergeev (stsp)
Date: 2007-03-25 14:09

Message:
Logged In: YES 
user_id=501371
Originator: YES

> it doesn't make much sense to me to derive streams
> from wxObject but not e.g. wxFile.
But it seems pointless to dynamic-cast wxFile
to anything, while dynamic-casting the stream
objects makes a lot of sense. I pass the pointers
to the wxMemoryOutputStream as wxOtputStream* to
some class. It has "wxOutputStream *GetStream()"
method, after which, I have to dynamic-cast it
back.
You may argue that there are no needs to do the
things like that etc, but this is not the point.
The point is that the RTTI of wx should either work
or became deprecated, IMHO.
Is it specified and documented somewhere which
classes are wxRTTI-compatible, and which are not?
If not - then I expect wxDynamicCast to work with
all the classes of wx, but right now it works only
with some of them. Is there any strict rule to find
out on which classes I should use wxRTTI, and on
which - the native RTTI? I actually don't like mixing
the things. If I use wxRTTI, then I prefer to not
use the native RTTI, and vice-versa.
Is there any good reason for wxRTTI not to work with
the stream classes?

> And, of course, I don't want to derive
> *everything* from wxObject just because we can.
For the classes without a virtual destructor, I am
not suggesting to do this. But for the rest of them -
I think so.

> So unless there is a
> popular clamour for being able to use wxDynamicCast with wxStream I'd
> rather not apply this.
I think you are approaching the problem from the wrong
side. To me the question is rather why the wxDynamicCast
does _not_ work with the stream classes. _This_ have to
be justified/documented/etc. Not the need to use it must
be provided, but rather an explanation why it does not
work. And that explanation I fail to find. There can't
be the things that work only sometimes. It either works
or it is broken.

----------------------------------------------------------------------

Comment By: Vadim Zeitlin (vadz)
Date: 2007-03-25 04:58

Message:
Logged In: YES 
user_id=71618
Originator: NO

Personally I'm against deriving everything from wxObject without any good
reason. C++ RTTI does work for streams as you say and besides I see few
reasons to use dynamic casts with them anyhow. I'd rather not use wxObject
as the base class here, it doesn't make much sense to me to derive streams
from wxObject but not e.g. wxFile. And, of course, I don't want to derive
*everything* from wxObject just because we can. So unless there is a
popular clamour for being able to use wxDynamicCast with wxStream I'd
rather not apply this.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=309863&aid=1687073&group_id=9863




More information about the wx-dev mailing list