Elements may be declared nillable by using the nillable="true"
facet.
When an element is declared nillable, an occurrence of that element in an XML
document may have an xsi:type attribute with a value of "true", which requires its
contents to then be empty.
XBinder models the nilled status of elements according to the following rules:
If the element is simple type, a null pointer represents a nilled element.
If the element is complex type and non-repeating, then a field is added to the "m" structure of the type that contains the element. It is named <element_name>Nil.
If the element is complex type and repeating, then an OSDynOctStr is used to hold a string of bits, each bit representing a nil flag for one of the occurrences of the element. In this case, helper methods are generated for setting and getting the nilled status for each occurrence of the element.
The signatures of the helper methods depend on the language and whether the nillable elements appear in a choice group:
//C signatures for elements in a choice group int <Type>_setNil(OSCTXT* pctxt, <Type>* pvalue, size_t index, OSBOOL value); OSBOOL <Type>_isNilSet(<Type>* pvalue, size_t index); //C signatures for elements in sequence or all group int <Type>_<element>_setNil(OSCTXT* pctxt, <Type>* pvalue, size_t index, OSBOOL value); OSBOOL <Type>_<element>_isNilSet(<Type>* pvalue, size_t index); //C++ signatures for elements in a choice group int setNil(size_t index, OSBOOL value); OSBOOL isNilSet(size_t index); //C++ signatures for elements in sequence or all group int <element>_setNil(size_t index, OSBOOL value); OSBOOL <element>_isNilSet(size_t index);
In the following example, a sequence "nilsInSequence" has four nillable elements: one_int is a non-repeating, simple type element; many_int is a repeating, simple type element; one_complex is a non-repeating, complex type element; and many_complex is a repeating, complex type element.
The generated C code would resemble the following:
typedef struct nilsInSequence { struct { //Flag for one_complex's nilled state unsigned one_complexNil : 1; ... } m; /* String of flags for many_complex's nilled states */ OSDynOctStr many_complexNilFlags; /* if -x64 is not used */ OSDynOctStr64 many_complexNilFlags; /* if -x64 is used */ OSRTDList many_complex; //null pointer represents a nilled one_int element OSINT32 *one_int; //null pointers represent a nilled many_int element struct { OSUINT32 n; /* if -x64 is not used */ OSSIZE n; /* if -x64 is used */ OSINT32 *elem[...]; } many_int; ... } nilsInSequence; //Specify whether a given occurrence of many_complex is nilled or not. //(index is 0-based). int nilsInSequence_many_complex_setNil( OSCTXT* pctxt, nilsInSequence* pvalue, size_t index, OSBOOL value); //Check whether a given occurrence of many_complex is nilled or not. OSBOOL nilsInSequence_many_complex_isNilSet(nilsInSequence* pvalue, size_t index);
The generated C++ code would resemble the following:
class nilsInSequence : public OSXSDComplexType { public: //null pointers represent a nilled many_int element struct many_int_array : public OSRTBaseType { OSINT32 *elem[...]; ... } ; many_int_array many_int; struct { //Flag for one_complex's nilled state unsigned one_complexNil : 1; ... } m; ::MyComplex *one_complex; //String of flags for many_complex's nilled states OSDynOctStr many_complexNilFlags; many_complex_list many_complex; //null pointer represents a nilled one_int element OSINT32 *one_int; //Specify whether a given occurrence of many_complex is nilled or not. //(index is 0-based). int many_complex_setNil(size_t index, OSBOOL value); //Check whether a given occurrence of many_complex is nilled or not. OSBOOL many_complex_isNilSet(size_t index); ... };