Array

Arrays are implemented in a way similar to the other aggregates. The difference is that an array has fixed size while the others are expandable. The basic array class is dbArray, and the array element type is added by the template mechanism.
template <typename ArrayElement>
class Array : public dbArray
An array of object pointers is declared in the following way:
Array<product*> *prodArr = new(ma)Array<product>(ma, sdaiINSTANCE, 3, 8);
The parameters are the same as for the other aggregates, except for that the buffer size parameter is substituted with Min and Max boundaries of the array.
Array methods:

  • ArrayElement get(int index) - returns the array elements at the specified index.
  • void put(int index, ArrayElement am) - puts an array element at the specified index.
  • void unSet(int index) – unset an array element at the specified index.
  • bool isSet(int index) – returns true if the element at the specified index is set otherwise false.
  • ArrayElement& operator[] (int index) – operator that works for the types sdaiINTEGER, sdaiREAL, sdaiBOOLEAN and sdaiLOGICAL. This method is only available for the in memory object model.


Examples:
// Declare array of int with min index 5 and max index 15
Array< EDMLONG> arr(&ma, sdaiINTEGER, 5, 15);
// Initialize the array
for (EDMLONG i=5; i <= 15; i++) arr[i] = 100 + i;
// Print the array values
for (EDMLONG i=5; i <= 15; i++) {
printf("arr[%d] = %d\n", i, arr[i]);
}
// An example using ap209 euler_angles
parametric_volume_3d_element_coordinate_system *pv3d = newObject(parametric_volume_3d_element_coordinate_system);
Array<double>angles (&ma, sdaiREAL, 1, 3);
angles[1] = 2.7; angles[2] = 3.14; angles[3] = 6.6;
euler_angles *euang = newObject(euler_angles);
euang->put_angles(&angles);
pv3d->put_eu_angles(euang);
// The entity euler_angles have an array that is retrieved
// by the method ea->get_angles();
euler_angles *ea = pv3d->get_eu_angles();
Array<double> *myangles = ea->get_angles();
double angle1 = myangles->get(1);
double angle2 = myangles->get(2);
double angle3 = myangles->get(3);
printf("\n\nEuler angles : %f,%f,%f",angle1,angle2,angle3);