ZEDA  1.6.18
Macros
universal two-dimensional array operations.

Macros

#define zArray2Class(array_t, cell_t)
 generate two-dimensional array class. More...
 
#define zArray2Size(a, i)   (a)->size[i]
 
#define zArray2RowSize(a)   (a)->size[0]
 
#define zArray2ColSize(a)   (a)->size[1]
 
#define zArray2Buf(a)   ( (a)->buf )
 
#define zArray2PosIsValid(a, r, c)   ( (r) < zArray2RowSize(a) && (r) >= 0 && (c) < zArray2ColSize(a) && (c) >= 0 )
 
#define zArray2ElemSize(a)   sizeof(*zArray2Buf(a))
 
#define zArray2ElemNC(a, i, j)   ( &zArray2Buf(a)[(i)*zArray2ColSize(a) + (j)] )
 
#define zArray2Elem(a, i, j)   ( zArray2PosIsValid(a,i,j) ? zArray2ElemNC(a,i,j) : NULL )
 
#define zArray2SetElemNC(a, i, j, d)   memcpy( zArray2ElemNC(a,i,j), (d), zArray2ElemSize(a) )
 
#define zArray2SetElem(a, i, j, d)   ( zArray2PosIsValid(a,i,j) ? zArray2SetElemNC(a,i,j,d) : NULL )
 
#define zArray2Init(arr)
 
#define zArray2Alloc(arr, type, r, c)
 allocate an array. More...
 
#define zArray2Free(arr)
 free an array. More...
 

Detailed Description

Macro Definition Documentation

◆ zArray2Class

#define zArray2Class (   array_t,
  cell_t 
)
Value:
typedef struct{\
uint size[2];\
cell_t *buf;\
} array_t

generate two-dimensional array class.

A macro zArray2Class() can generate a new two-dimensional array class, which consists of the row and column sizes of the array and the pointer to the array buffer. array_t is the class name to be defined. cell_t is the class name of the data to be arrayed.

The row and column sizes of the array are acquired by zArray2Size(). zArray2RowSize() and zArray2ColSize() are also available. Each element can be accessed by zArray2Elem(). For a faster access to each element, zArray2ElemNC() is also available, which does not check the specified location.

The array can be freed by calling zArray2Free().

zArray2SetElem() is available in order to set each element, which works only if the specified location is valid. zArray2SetElemNC() is also available, which provides a faster access to each element without checking the validity of specified location.

◆ zArray2Size

#define zArray2Size (   a,
 
)    (a)->size[i]

◆ zArray2RowSize

#define zArray2RowSize (   a)    (a)->size[0]

◆ zArray2ColSize

#define zArray2ColSize (   a)    (a)->size[1]

◆ zArray2Buf

#define zArray2Buf (   a)    ( (a)->buf )

◆ zArray2PosIsValid

#define zArray2PosIsValid (   a,
  r,
 
)    ( (r) < zArray2RowSize(a) && (r) >= 0 && (c) < zArray2ColSize(a) && (c) >= 0 )

◆ zArray2ElemSize

#define zArray2ElemSize (   a)    sizeof(*zArray2Buf(a))

◆ zArray2ElemNC

#define zArray2ElemNC (   a,
  i,
 
)    ( &zArray2Buf(a)[(i)*zArray2ColSize(a) + (j)] )

◆ zArray2Elem

#define zArray2Elem (   a,
  i,
 
)    ( zArray2PosIsValid(a,i,j) ? zArray2ElemNC(a,i,j) : NULL )

◆ zArray2SetElemNC

#define zArray2SetElemNC (   a,
  i,
  j,
 
)    memcpy( zArray2ElemNC(a,i,j), (d), zArray2ElemSize(a) )

◆ zArray2SetElem

#define zArray2SetElem (   a,
  i,
  j,
 
)    ( zArray2PosIsValid(a,i,j) ? zArray2SetElemNC(a,i,j,d) : NULL )

◆ zArray2Init

#define zArray2Init (   arr)
Value:
do{\
zArray2RowSize(arr) = zArray2ColSize(arr) = 0;\
zArray2Buf(arr) = NULL;\
} while(0)
#define zArray2ColSize(a)
Definition: zeda_array.h:274

◆ zArray2Alloc

#define zArray2Alloc (   arr,
  type,
  r,
 
)
Value:
do{\
zArray2Init( arr );\
if( (r) > 0 && (c) > 0 && !( zArray2Buf(arr) = zAlloc(type,(r)*(c)) ) ){\
ZALLOCERROR();\
zArray2RowSize(arr) = 0;\
zArray2ColSize(arr) = 0;\
} else{\
zArray2RowSize(arr) = (r);\
zArray2ColSize(arr) = (c);\
}\
} while(0)
#define zAlloc(t, n)
Definition: zeda_misc.h:81
#define zArray2Buf(a)
Definition: zeda_array.h:275

allocate an array.

Parameters
arrarray class instance to be allocated.
typethe data type of the array cells.
nthe number of cells.

◆ zArray2Free

#define zArray2Free (   arr)
Value:
do{\
free( zArray2Buf(arr) );\
zArray2Init( arr );\
} while(0)
#define zArray2Buf(a)
Definition: zeda_array.h:275

free an array.

Parameters
arra pointer to the array to be freed.