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 2.0KB

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