Modeling Services > Relations > Array-relations > Fixed Arrays
 
Fixed Arrays
Defining Fixed Arrays
You define fixed arrays containing relations using the class templates IlsUsesFixedArray and IlsOwnsFixedArray:
IlsOwnsFixedArray<OwnerType,OwnedType,size>
IlsUsesFixedArray<UserType,UsedType,size>
The first argument passed to these templates is the owner or the user type. The second argument is the used or the owned type. The third argument specifies the size of the array.
The following code declares a platoon which uses a fixed array of 27 soldiers.
// ...
class Platoon:
public IlsObject
{
public:
   IlsUsesFixedArray<Platoon,Soldier,27> soldiers;
   Platoon();
};
Constructing Fixed 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)
{}
As a second argument, you can provide an identifier of type IlsRelationId. This identifier is used to invert relations.
For details, see Using Relation Identifiers with an Inverted Relation and Using Relation Identifiers with an Inverted List-Relation.
When a fixed array is created, it contains as many relations as specified. These relations are automatically initialized to null smart pointers.
Getting an Element From an Array
To get the ith array element, you just have to enclose this element between brackets, like this:
soldiers[i]
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 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.