Flexible Type Mapping
The 44 built-in schema types are mapped to C++ types using the default mapping shown in
Table 4 . You can map any of these schema types to a C++ type of your choice. In order to provide this mapping flexibility, HydraExpress requires the following information:
code to convert to and from a standard
std::string instance
NOTE: The HydraExpress internal parser,
rwsf::XmlReader, uses
std::string instances to hold content before converting to the type specified by the datamap. Therefore, your custom types must provide a way to convert to and from
std::string. See the example below for an illustration of how to do this.
a value to use as a default value
an indication of how to construct an instance of your chosen type given a default value specification in an XML Schema
user-defined types require one additional attribute:
The
include attribute specifies the header file for the user-defined type. The attribute must contain any path information necessary for the compiler to locate the file.
Here is an example HydraExpress project file that maps xsd:string, xsd:date, xsd:dateTime, xsd:time, xsd:integer and xsd:duration to std::string.
<rwsf-codegen-project project-name="CustomMappings">
<mappings>
<type xsdType="string" cppType="std::string"/>
<type xsdType="date" cppType="std::string"/>
<type xsdType="dateTime" cppType="std::string"/>
<type xsdType="time" cppType="std::string"/>
<type xsdType="duration" cppType="std::string"/>
<type xsdType="integer" cppType="std::string"/>
<typeinfo cppType="std::string" include="string">
<fromString>std::string($value$)
</fromString>
<toString>std::string($value$)
</toString>
<defaultValue>std::string("$value$")</defaultValue>
<initialValue></initialValue>
</typeinfo>
</mappings>
</rwsf-codegen-project>
A type element defines a mapping between an XML Schema type and a C++ type. Each type element must contain an xsdType attribute and a cppType attribute. The xsdType attribute defines the XML Schema type the mapping applies to. The cppType attribute defines the C++ type that HydraExpress generates for the XML Schema type.
Each cppType must be defined in a typeinfo element. The typeinfo element provides the information that HydraExpress needs to successfully generate code for the cppType. You may specify the following attributes and child elements for the typeinfo element.
cppType attribute – This is required and must match exactly with the
cppType attribute value from the type mapping element.
include attribute – This is required and provides the include filename so the type definition is available to the generated usage of it. The value may be empty (
include="") if not relevant, but the attribute must be present.
isPrimitive attribute – This is optional and specifies that the type is primitive (
bool,
int,
double, etc...)
fromString element – Provides the logic to convert from an
std::string instance to the user specified type. The
$value$ parameter represents the
std::string variable that needs to be operated on.
toString element – Provides the logic to convert from the user specified type to an
std::string instance. The
$value$ parameter represents the user defined type instance that needs to be converted to an
std::string.
defaultValue element – Provides the logic to construct a valid user specified type instance from a default value specified in a schema. This is the
unquoted literal, extracted from the default attribute in the XML Schema. Note that if the literal needs to be quoted, you must include the quotes in this element value.
initialValue element – Whatever is provided for this element is used in the default constructor to initialize all members of this user specified type.