[xsd-users] Enumerated types that serialize as numbers
Boris Kolpackov
boris at codesynthesis.com
Thu Jun 20 10:05:50 EDT 2013
Hi Ray,
Ray Lischner <rlischner at proteuseng.com> writes:
> We can use --custom-type and customize classes easily enough, but we
> would need to customize each enumerated type individually.
You could create a class template that provides the enum semantics that
you need and then use it to "wrap" generated enums via type customization.
For example:
template <typename T>
class numeric_enum: public T
{
// Customize parsing c-tors to expect numbers.
};
// Customize the serialization operators to save enum values as numbers.
Then:
--custom-type my_enum=numeric_enum<my_enum_base>/my_enum_base
Converting to/from numbers is easy via the underlying enum type
(my_enum_base::value). The only thing that you won't be able to
do is validate that the number you get in the parsing c-tor is
within range.
Boris
More information about the xsd-users
mailing list