
Repeating Elements
Elements within a sequence definition may be declared to be repeating by using the minOccurs and/or maxOccurs facets. In this case, a C or C++ list or array container type structure is used instead of a C/C++ element type definition. This container holds a series of objects of the element type.
If the C element type is a simple type and the maximum number of elements (maxOccurs) is less than or equal to 10,000, then an array type of the following form is used:
In this definition, n is used to hold the count of element occurrences to be encoded (or that were decoded), and data holds the actual element data values.
If either of the above conditions is not true, a linked list type is used to hold a dynamic list of the data objects. This type is OSRTDList (run-time doubly linked list). It is defined in rtxDList.h as follows:
There is a complete set of functions available for adding, deleting, and traversing lists of this type available in the run-time library. See the rtxDList.h File Reference section for documentation on these functions.
For C++, there is a corresponding class definition (OSRTDListClass) that extends the OSRTDList structure and contains constructors and methods for adding, removing, and finding items in the list.
The following example shows a sequence with two repeating elements. The first will cause an array type to be generated, the second, a list:
Note that a comment is added to the generated C structure before the list declaration to indicate what type of objects the list is to contain.
In the case of C++, a constructor is added to the generated array structure to initialize the number of elements to zero. An inline class is generated for the list variable that extends the OSRTDListClass and adds methods to append items to the list and retrieve items from the list:
class SeqWithArrayAndList : public OSBaseType { public: struct anArray_array { OSUINT32 n; OSINT32 elem[10]; anArray_array() { n = 0; } } anArray; /* List of SomeOtherType */ class aList_list : public OSRTDListClass { public: void append (const SomeOtherType* pdata) { OSRTDListClass::append ((const void*)pdata); } void append (SomeOtherType* pdata, OSBOOL ownMemory=FALSE) { OSRTDListClass::append ((void*)pdata, ownMemory); } const SomeOtherType* getItem (int idx) { return (const SomeOtherType*) OSRTDListClass::getItem (idx); } } aList; ... } ;
Objective Systems, Inc.102 Pickering Way, Suite #506Exton, 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 |