AW: [xsd-users] how to get type information from tree nodes
Lena Herscheid
lenaherscheid at gmail.com
Wed Aug 21 18:05:33 EDT 2013
Thanks for the quick answer!
When saying that RTTI was not portable, I was referring to platform
differences with typeidx().name().
But it surely is possible to compare to the typeid of a "fresh class
instance" instead of hard coded strings.
So I'll certainly find a solution.
Cheers
Lena
-----Ursprüngliche Nachricht-----
Von: Boris Kolpackov [mailto:boris at codesynthesis.com]
Gesendet: 21 August 2013 20:16
An: Lena Herscheid
Cc: xsd-users at codesynthesis.com
Betreff: Re: [xsd-users] how to get type information from tree nodes
Hi Lena,
Lena Herscheid <lenaherscheid at gmail.com> writes:
> Is it possible with cxx-tree to generate member functions returning
> the typename of the current node (as string)?
No, there is no such support.
> I'm asking because the alternative way of efficiently determining the
> type of any during runtime requires some RTTI which is not portable.
I am not sure what you mean by "some RTTI", but standard C++ RTTI (i.e.,
dynamic_cast, typeid) are very much portable. Some projects may choose to
disable this support in order to minimize code size, but that's another
story.
So if you need a type name in C++/Tree, then typeid(x).name () is the
recommended way. If, however, you want to find whether x is of a particular
dynamic type, then use dynamic_cast, it will be much faster than any custom
RTTI with string comparison:
base& x = ...
if (derived1* d1 = dynamic_cast<derived1*> (&x)) {
// x is derived1
}
else if (derived2* d2 = dynamic_cast<derived2*> (&x)) {
// x is derived2
}
...
else
{
// x is something else
}
Boris
More information about the xsd-users
mailing list