Modeling Services > Relations > Array-relations > Dynamic Arrays
 
Dynamic Arrays
Defining Dynamic Arrays
You define dynamic arrays containing relations using the class templates IlsUsesDynamicArray and IlsOwnsDynamicArray:
IlsOwnsDynamicArray<OwnerType,OwnedType>
IlsUsesDynamicArray<UserType,UsedType>
Unlike class templates for declaring static arrays, these class templates do not take a dimension as their third argument.
Building Dynamic Arrays
As for simple relations, you build an array-relation by providing a reference to the origin of the relation.
The constructor of the Platoon class is the following:
Platoon::Platoon():
soldiers(*this)
{}
Getting the Size of a Dynamic Array
You can get the size of a dynamic array at any time using the getSize function:
unsigned int getSize() const;
Creating a New Array
You can allocate or create a new array with a specified size using the renew function.
As its argument, the renew function takes the new size of the array. By default, the value of this integer is 0. Smart pointers to objects contained in the old array are erased and replaced with null smart pointers in the new array. This function returns a reference to the array.
Getting an Element From an Array
To get the ith element from an array, you just have to enclose it between brackets, like this:
soldiers[i]
This instruction returns the ith array element. If i is greater than the size specified for the array (minus 1), the exception IlsSizeViolation is thrown.
The value returned when an array element is accessed can be assigned a new value:
soldiers[10]=new Soldier();

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.