TOC PREV NEXT INDEX


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 general mapping is as follows:
XSD type:
<xsd:simpleType name="TypeName">
 
   <restriction base="xsd:string">
 
      <xsd:enumeration value="enum1"/>
 
      <xsd:enumeration value="enum2"/>
 
      ...
 
      <xsd:enumeration value="enumN"/>
 
   </xsd:restriction>
 
</xsd:simpleType>
 

 
Generated C code:
typedef enum {
 
   TypeName_enum1 = 0,
 
   TypeName_enum2 = 1,
 
   ...
 
   TypeName_enumN = N - 1,
 
} TypeName_ENUM;
 

 
typedef OSUINT16 TypeName;
 

 
Generated C++ code:
class TypeName : public OSBaseType {
 
public:
 
   enum {
 
      enum1 = 0,
 
      enum2 = 1,
 
      ...
 
      enumN = N - 1,
 
   } ;
 
   OSUINT16 value;
 
   ...
 
} ;
 


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).

Objective Systems, Inc.

102 Pickering Way, Suite #506
Exton, 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
TOC PREV NEXT INDEX