[xsde-users] Re: Type mapping
Boris Kolpackov
boris at codesynthesis.com
Tue Dec 8 09:39:22 EST 2009
Hi Thomas,
Thomas Frenzel (TomSun) <tftomsun at streamteam.de> writes:
> 1. Template base classes
> i am not sure, but i think it is possible to replace a generated type
> by a self implemented type, right?.
Yes, see Section 4.8, "Customizing the Object Model" in the Embedded
C++/Hybrid Mapping Getting Started Guide:
http://www.codesynthesis.com/projects/xsde/documentation/cxx/hybrid/guide/#4.8
> Is it also possible to create a type mapping to a template type?
You can map it to an instantiation of a template, but not to a template
itself. In other words, if you have:
template <typename Base>
class wrapper
{
...
};
Then you can re-map a type in the object model to something like
wrapper<type_base>.
> What i would like to do is the following:
>
> I create a schema with an empty base complex type and several derived type.
> In the code generation i want to replace the empty base type by an self
> implemented template type. So i would need a posibility to define the
> template parameters foreach derived type.
>
> One use case for this scenario would be:
> Each derived complex type implements a Value attribute. But the Value
> attributes have a different types (e.g. int, float, long, etc.)
> My template class implements some operators (e.g. +, -, etc.)
You could use the wrapper template as shown above. That is, you would
ask the XSD/e compiler to still generate the types but with different
names (say for type A it would be A_base). Then you re-map the type
to wrapper<A_base>. The wrapper template could inherit from its
argument and provide some extra functionality, like +/- operators.
>
> 2. overriding, abstract definition
> Another feature would be nice, too. If i could define a attribute or
> element as abstract in the base complex type and define an element
> with the same name but with an default value in the derived type,
> i could provide something like metadata for my generated types.
This is illegal in XML Schema and you will get a redefinition error
in the derived type.
> With this solution i could determine without any casting of which
> type the current instance in a list of "MyBase" is.
Have you looked at the --generate-typeinfo option? With this option
each generated type gets the following two functions:
virtual const std::string&
_dynamic_type () const;
static const std::string&
_static_type ();
Then you can do:
base* b = ...
if (b->_dynamic_type () == derived_a::_static_type ())
{
// Got derived_a.
}
See Section 4.9, "Polymorphic Object Models" for details:
http://www.codesynthesis.com/projects/xsde/documentation/cxx/hybrid/guide/#4.8
Boris
More information about the xsde-users
mailing list