Arrays |
Array dimensions are defined by an ix_array and dimension_count in the _array_t structure
#define MB_MAX_DIMENSIONS 4 int ix_array[MB_MAX_DIMENSIONS] = { ix1, ix2, ix3, ix4 };
The dimension_count defines how many of the dimensions in th ix_array are being used. This is defined when using the DIM array statement.
DIM arr_name( ix4, ix3, ix2, ix1 ) AS type
Not all the dimensions are required when defining an array. When omitting dimensions, they are omitted from left to right. For a 1D vector, only the first dimension in ix_array is used and the dimension_count is set to 1.
These are the possibilities with MB_MAX_DIMENSIONS = 4
DIM array_1d( ix1 ) -> ix_array[] = { ix1, 0, 0, 0 } / dimension_count = 1 DIM array_2d( ix2, ix1 ) -> ix_array[] = { ix1, ix2, 0, 0 } / dimension_count = 1 DIM array_2d( ix3, ix2, ix1 ) -> ix_array[] = { ix1, ix2, ix3, 0 } / dimension_count = 1 DIM array_2d( ix4, ix3, ix2, ix1 ) -> ix_array[] = { ix1, ix2, ix3, ix4 } / dimension_count = 1
When specifying indexes as part of an API function call, they are specified from left to right. For example;
mb_ix( 3, 4, 60 ) is the same as DIM ix( 60, 4, 3 )
Also, note that all API calls are base 0 while any MyBASIC2 statements depends on the OPTION BASE setting.
The following API calls are provided to get array properties and data:
MBAPI mb_data_e mb_get_array_type( LPARRAY pArr ); MBAPI int mb_get_array_element_count( LPARRAY pArr ); MBAPI int mb_get_array_element_size( LPARRAY pArr ); MBAPI int mb_get_array_dimensions( LPARRAY pArr, LPIXARRAY ix_array _DNULL ); MBAPI void* mb_get_array_element_ptr( LPARRAY pArr, LPIXARRAY ix_array ); MBAPI bool_t mb_check_array_dimensions( LPARRAY pArr, mb_data_e eType, int ix1, int ix2 _D0, int ix3 _D0, int ix4 _D0 );
MBAPI int mb_get_array_index( LPARRAY pArr, LPIXARRAY ix_array ); MBAPI bool_t mb_set_array( LPARRAY pArr, LPIXARRAY ix_array, mb_value_t val ); MBAPI bool_t mb_set_array_array( LPARRAY pArrDst, LPIXARRAY ix_array_dst, LPARRAY pArrSrc, LPIXARRAY ix_array_src ); MBAPI bool_t mb_get_array_element( LPARRAY pArr, LPIXARRAY ix_array, mb_value_t* val ); MBAPI bool_t mb_set_array_element( LPARRAY pArr, LPIXARRAY ix_array, mb_value_t val );
LPIXARRAY mb_ix_set( LPIXARRAY lpIx, int ix1 _D0, int ix2 _D0, int ix3 _D0, int ix4 _D0 ); LPIXARRAY mb_ix( int ix1 _D0, int ix2 _D0, int ix3 _D0, int ix4 _D0 );
|