View Single Post
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 01-19-2017 , 14:58   Re: [ TUT ]Dynamic Array
Reply With Quote #12

Quote:
Originally Posted by fysiks View Post
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 )         }     } }
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline