Enumerated Type
Another facet that is frequently applied to XSD string-based types is enumeration. This results in the generation of a C enum typedef that enumerates all of the identifiers that can be used in the type. The actual C typedef that is generated for the item is of type OSUINT16. The reasons for not directly using the generated enum type are:
- The use of OSUINT16 provides for a consistent size of the data variable. Use of enum can produce different sized variables on different platform/compiler combinations, and
- The variable is capable of storing enumerated types that were not defined in the original set. This makes the type extensible in the event a newer version of the schema is produced that contains additional enumeration items that were not in the original version.
The general mapping is as follows:
Note that for C, TypeName is used on the enumerated identifiers as a namespace mechanism in order to prevent name clashes if two or more enumerated types use the same identifier names. In this case, the type name may only be a partial fragment of the full name to keep the names shorter. This is not a problem in C++ as the class provides a namespace for the enumeration constants defined within (for example, enum1 would be referenced as TypeName::enum1 outside the class).
In XSD, the rules for naming enumerated identifiers are more liberal than in the C/C++ programming language. For example, enumerated identifiers can start with numbers or punctuation marks. The logic to transform the XSD enumeration names to C/C++ form makes use of the following rules to ensure the names are valid C/C++ names:
1. If all items are numeric, no symbolic identifiers are generated. The user is expected to work with the items in numeric form.
2. If an enumeration identifier consists of whitespace (for example, enumeration value=" "), the special name BLANK is used.
3. Other special names are used for other single punctuation mark identifiers (for example, `+' = PLUS).
Copyright © Objective Systems 2002-2008 This document may be distributed in any form, electronic or otherwise, provided that it is distributed in its entirety and that the copyright and this notice are included. |
Objective Systems, Inc.55 Dowlin Forge RoadExton, Pennsylvania 19341 http://www.obj-sys.com Phone: (484) 875-9841 Toll-free: (877) 307-6855 (US only) Fax: (484) 875-9830 info@obj-sys.com |