libcm/cmArray.h

67 lines
1.9 KiB
C
Raw Normal View History

2013-03-21 15:16:10 +00:00
#ifndef cmArray_h
#define cmArray_h
#ifdef __cplusplus
extern "C" {
#endif
//( { file_desc: "Dynamic array container class." kw:[container] }
2013-03-21 15:16:10 +00:00
enum
{
kOkArRC = cmOkRC,
kUnderflowArRC
};
typedef cmRC_t cmArRC_t;
typedef cmHandle_t cmArrayH_t;
extern cmArrayH_t cmArrayNullHandle;
cmArRC_t cmArrayAlloc0( cmCtx_t* ctx, cmArrayH_t* hp, unsigned eleByteCnt, unsigned initCnt, unsigned expandCnt );
// Defaults initCnt and expandCnt to 10.
cmArRC_t cmArrayAlloc( cmCtx_t* ctx, cmArrayH_t* hp, unsigned eleByteCnt );
2013-03-21 15:16:10 +00:00
cmArRC_t cmArrayRelease(cmArrayH_t* hp );
cmArRC_t cmArrayIsValid(cmArrayH_t h );
void cmArraySetExpandCount( cmArrayH_t h, unsigned expandCnt );
unsigned cmArrayExpandCount( cmArrayH_t h );
2013-03-21 15:16:10 +00:00
unsigned cmArrayCount( cmArrayH_t h );
cmArRC_t cmArrayClear( cmArrayH_t h, bool releaseFl );
2013-03-22 01:37:10 +00:00
// Returns a pointer to the first pushed element.
// Set 'data' to NULL to create 'dataEleCnt' new zeroed elements.
2013-03-21 15:16:10 +00:00
void* cmArrayPush( cmArrayH_t h, const void* data, unsigned dataEleCnt );
2013-03-22 01:37:10 +00:00
// Decreaese the array count by 'eleCnt'.
2013-03-21 15:16:10 +00:00
cmArRC_t cmArrayPop( cmArrayH_t h, unsigned eleCnt );
2013-03-22 01:37:10 +00:00
2013-03-21 15:16:10 +00:00
// If 'data' is NULL then array[idx:idx+dataEleCnt] is zeroed.
2013-03-22 01:37:10 +00:00
// Returns a ptr to the first set element.
2013-03-21 15:16:10 +00:00
void* cmArraySet( cmArrayH_t h, unsigned index, const void* data, unsigned dataEleCnt );
const void* cmArrayGet( cmArrayH_t h, unsigned index );
#define cmArrayPtr(t,h,i) ((t*)cmArrayGet(h,i))
2013-04-16 14:36:39 +00:00
// Return a ptr to the base of the array.
#define cmArrayBase(t,h) ((t*)cmArrayGet(h,0))
2013-04-16 14:36:39 +00:00
// Return a ptr to the ith element
2013-03-21 15:16:10 +00:00
#define cmArrayEle(t,h,i) (*(t*)cmArrayGet(h,i))
2013-04-16 14:36:39 +00:00
// Zero the ith element
2013-03-21 15:16:10 +00:00
#define cmArrayClr(t,h,i) ((t*)cmArraySet(h,i,NULL,1))
2013-04-16 14:36:39 +00:00
// Zero elements i:i+n-1
2013-03-21 15:16:10 +00:00
#define cmArrayClrN(t,h,i,n) ((t*)cmArraySet(h,i,NULL,n))
//)
2013-03-21 15:16:10 +00:00
#ifdef __cplusplus
}
#endif
#endif