libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmArray.h 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef cmArray_h
  2. #define cmArray_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //( { file_desc: "Dynamic array container class." kw:[container] }
  7. enum
  8. {
  9. kOkArRC = cmOkRC,
  10. kUnderflowArRC
  11. };
  12. typedef cmRC_t cmArRC_t;
  13. typedef cmHandle_t cmArrayH_t;
  14. extern cmArrayH_t cmArrayNullHandle;
  15. cmArRC_t cmArrayAlloc0( cmCtx_t* ctx, cmArrayH_t* hp, unsigned eleByteCnt, unsigned initCnt, unsigned expandCnt );
  16. // Defaults initCnt and expandCnt to 10.
  17. cmArRC_t cmArrayAlloc( cmCtx_t* ctx, cmArrayH_t* hp, unsigned eleByteCnt );
  18. cmArRC_t cmArrayRelease(cmArrayH_t* hp );
  19. cmArRC_t cmArrayIsValid(cmArrayH_t h );
  20. void cmArraySetExpandCount( cmArrayH_t h, unsigned expandCnt );
  21. unsigned cmArrayExpandCount( cmArrayH_t h );
  22. unsigned cmArrayCount( cmArrayH_t h );
  23. cmArRC_t cmArrayClear( cmArrayH_t h, bool releaseFl );
  24. // Returns a pointer to the first pushed element.
  25. // Set 'data' to NULL to create 'dataEleCnt' new zeroed elements.
  26. void* cmArrayPush( cmArrayH_t h, const void* data, unsigned dataEleCnt );
  27. // Decreaese the array count by 'eleCnt'.
  28. cmArRC_t cmArrayPop( cmArrayH_t h, unsigned eleCnt );
  29. // If 'data' is NULL then array[idx:idx+dataEleCnt] is zeroed.
  30. // Returns a ptr to the first set element.
  31. void* cmArraySet( cmArrayH_t h, unsigned index, const void* data, unsigned dataEleCnt );
  32. const void* cmArrayGet( cmArrayH_t h, unsigned index );
  33. #define cmArrayPtr(t,h,i) ((t*)cmArrayGet(h,i))
  34. // Return a ptr to the base of the array.
  35. #define cmArrayBase(t,h) ((t*)cmArrayGet(h,0))
  36. // Return a ptr to the ith element
  37. #define cmArrayEle(t,h,i) (*(t*)cmArrayGet(h,i))
  38. // Zero the ith element
  39. #define cmArrayClr(t,h,i) ((t*)cmArraySet(h,i,NULL,1))
  40. // Zero elements i:i+n-1
  41. #define cmArrayClrN(t,h,i,n) ((t*)cmArraySet(h,i,NULL,n))
  42. //)
  43. #ifdef __cplusplus
  44. }
  45. #endif
  46. #endif