[xsd-users] Inheritance : Ways to get the real type

Klaim - Joël Lamotte mjklaim at gmail.com
Fri Nov 25 06:34:06 EST 2011


2011/11/25 Boris Kolpackov <boris at codesynthesis.com>

> > No type name information provided by xsd/tree generated types, right?
>
> Right. What kind of type information are you looking for?
>
> Boris
>


Well if a there was a value at runtime providing the name or some
identifier of the real type, I would have used that instead of
dynamic_cast, for performance reasons, as the information would have been
generated at code generation.
As it's not a big concern for my crurent project I'm fine with using
type_id.name() as it is known to be faster than dynamic_cast.

The use-case is that depending on the real type I need to call a specific
processing function. I have some kind of switch table (in fact a map of
functors) and use it to call the right function. As it's specific to my
tool reading the xml file and not to the xml-based language itself, I don't
want to add infos to the xsd generated code.

I don't know if it's a common pattern but it seems that any tool I'll be
writing for this language will require some kind of function table to do
the right thing depending on the real type of some of my inherited types.

Is there an obvious simpler and efficient solution I missed? Maybe using
inheritance with xsd isn't such a good idea anyway, but I can't find ways
to express this language concepts without it.

Joël Lamotte


More information about the xsd-users mailing list