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.

cmStack.h 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef cmStack_h
  2. #define cmStack_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkStRC = cmOkRC,
  9. kLHeapFailStRC,
  10. kInvalidIdxStRC,
  11. kUnderflowStRC
  12. };
  13. typedef cmRC_t cmStRC_t;
  14. typedef cmHandle_t cmStackH_t;
  15. extern cmStackH_t cmStackNullHandle;
  16. // Allocate a stack to hold fixed data elements of size 'eleByteCnt'.
  17. // The stack will be initialized with 'initCnt' empty slots. Once these
  18. // slots are filled 'expandCnt' additional slots will be added as necessary.
  19. cmStRC_t cmStackAlloc( cmCtx_t* ctx, cmStackH_t* hp, unsigned initCnt, unsigned expandCnt, unsigned eleByteCnt );
  20. cmStRC_t cmStackFree( cmStackH_t* hp );
  21. cmStRC_t cmStackIsValid( cmStackH_t h );
  22. // Return the current count of elements on the stack.
  23. unsigned cmStackCount( cmStackH_t h );
  24. // Empty the stack. Set release flag to also release any memory used by the data elements.
  25. void cmStackClear( cmStackH_t h, bool releaseFl );
  26. // Push 'dataEleCnt' elments onto the stack.
  27. cmStRC_t cmStackPush( cmStackH_t h, const void* data, unsigned dataEleCnt );
  28. // Remove 'eleCnt' elements from the stack.
  29. cmStRC_t cmStackPop( cmStackH_t h, unsigned eleCnt );
  30. // Set the value of 'dataEleCnt' elements on the stack.
  31. cmStRC_t cmStackSet( cmStackH_t h, unsigned index, const void* data, unsigned dataEleCnt );
  32. // Copy 'dataEleCnt' elements into the buffer pointed to by 'data'.
  33. cmStRC_t cmStackGetN( cmStackH_t h, unsigned index, void* data, unsigned dataEleCnt );
  34. // Return a pointer to a single element on the stack.
  35. const void* cmStackGet( cmStackH_t h, unsigned index );
  36. // Convert the internal representation of the stack to a linear array and return
  37. // a pointer to the array base.
  38. void* cmStackFlatten( cmStackH_t h );
  39. // Stack test function.
  40. void cmStackTest( cmCtx_t* ctx );
  41. #define cmStackEle(h,t,i) (*(t*)cmStackGet(h,i))
  42. #ifdef __cplusplus
  43. }
  44. #endif
  45. #endif