Quote:
Originally Posted by fysiks
Dynamic arrays are limited to two dimensions, FYI. The first dimension if dynamic and the second is static.
|
You still can have a dynamic array, of dynamic arrays, where each dynamic array is another dynamic array, and keep going on. This is what I used to destruct my two dimensional arrays. For higher dimensional arrays, the destruction follows the same strategy.
Code:
/**
* General handler to assist object property applying and keep the code clear. This only need
* to be used with destructors/cleaners which does not support uninitialized handlers, requiring
* an if pre-checking.
*
* @param objectHandler the object handler to be called.
* @param objectIndentifation the object identification number to be destroyed.
*/
#define TRY_TO_APPLY(%1,%2) \
{ \
if( %2 ) \
{ \
%1( %2 ); \
} \
}
/**
* Same as TRY_TO_APPLY(2), but the second argument must to be a two Dimensional Dynamic Array.
*
* @param outerArray a Dynamic Array within several Dynamic Arrays.
* @param isToDestroyTheOuterArray whether to destroy or clear the `outerArray` provided.
*/
stock destroy_two_dimensional_array( Array:outerArray, bool:isToDestroyTheOuterArray = true )
{
if( outerArray )
{
new innerArray;
new size = ArraySize( outerArray );
for( new index = 0; index < size; index++ )
{
innerArray = ArrayGetCell( outerArray, index );
TRY_TO_APPLY( ArrayDestroy, Array:innerArray )
}
if( isToDestroyTheOuterArray )
{
TRY_TO_APPLY( ArrayDestroy, outerArray )
}
else
{
TRY_TO_APPLY( ArrayClear, outerArray )
}
}
}
__________________