2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-08-05 23:29:43 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bli
|
2012-08-06 08:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2014-06-30 11:44:28 +10:00
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
2017-06-06 12:13:45 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-08-05 23:29:43 +00:00
|
|
|
typedef struct BLI_Stack BLI_Stack;
|
|
|
|
|
2022-01-12 12:49:36 +01:00
|
|
|
BLI_Stack *BLI_stack_new_ex(size_t elem_size,
|
2014-06-30 11:44:28 +10:00
|
|
|
const char *description,
|
2022-01-12 12:49:36 +01:00
|
|
|
size_t chunk_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Create a new homogeneous stack with elements of 'elem_size' bytes.
|
|
|
|
*/
|
2022-01-12 12:49:36 +01:00
|
|
|
BLI_Stack *BLI_stack_new(size_t elem_size, const char *description) ATTR_WARN_UNUSED_RESULT
|
2014-07-15 20:37:06 +10:00
|
|
|
ATTR_NONNULL();
|
2012-08-05 23:29:43 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Free the stack's data and the stack itself
|
|
|
|
*/
|
2014-06-30 11:44:28 +10:00
|
|
|
void BLI_stack_free(BLI_Stack *stack) ATTR_NONNULL();
|
2012-08-05 23:29:43 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Push a new item onto the stack.
|
|
|
|
*
|
|
|
|
* \return a pointer #BLI_Stack.elem_size
|
|
|
|
* bytes of uninitialized memory (caller must fill in).
|
|
|
|
*/
|
2014-07-15 20:37:06 +10:00
|
|
|
void *BLI_stack_push_r(BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Copies the source value onto the stack
|
|
|
|
*
|
|
|
|
* \note This copies #BLI_Stack.elem_size bytes from \a src,
|
|
|
|
* (the pointer itself is not stored).
|
|
|
|
*
|
|
|
|
* \param src: source data to be copied to the stack.
|
|
|
|
*/
|
2014-07-15 20:37:06 +10:00
|
|
|
void BLI_stack_push(BLI_Stack *stack, const void *src) ATTR_NONNULL();
|
2012-08-05 23:29:43 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* A version of #BLI_stack_pop which fills in an array.
|
|
|
|
*
|
|
|
|
* \param dst: The destination array,
|
|
|
|
* must be at least (#BLI_Stack.elem_size * \a n) bytes long.
|
|
|
|
* \param n: The number of items to pop.
|
|
|
|
*
|
|
|
|
* \note The first item in the array will be last item added to the stack.
|
|
|
|
*/
|
2014-07-15 20:37:06 +10:00
|
|
|
void BLI_stack_pop_n(BLI_Stack *stack, void *dst, unsigned int n) ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* A version of #BLI_stack_pop_n which fills in an array (in the reverse order).
|
|
|
|
*
|
|
|
|
* \note The first item in the array will be first item added to the stack.
|
|
|
|
*/
|
2015-06-19 17:40:35 +10:00
|
|
|
void BLI_stack_pop_n_reverse(BLI_Stack *stack, void *dst, unsigned int n) ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Retrieves and removes the top element from the stack.
|
|
|
|
* The value is copies to \a dst, which must be at least \a elem_size bytes.
|
|
|
|
*
|
|
|
|
* Does not reduce amount of allocated memory.
|
|
|
|
*/
|
2014-06-30 11:44:28 +10:00
|
|
|
void BLI_stack_pop(BLI_Stack *stack, void *dst) ATTR_NONNULL();
|
2012-08-05 23:29:43 +00:00
|
|
|
|
2014-09-28 13:24:01 +10:00
|
|
|
void *BLI_stack_peek(BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Removes the top element from the stack.
|
|
|
|
*/
|
2014-09-28 13:24:01 +10:00
|
|
|
void BLI_stack_discard(BLI_Stack *stack) ATTR_NONNULL();
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Discards all elements without freeing.
|
|
|
|
*/
|
2015-06-03 18:06:47 +10:00
|
|
|
void BLI_stack_clear(BLI_Stack *stack) ATTR_NONNULL();
|
2014-09-28 13:24:01 +10:00
|
|
|
|
2014-07-15 20:37:06 +10:00
|
|
|
size_t BLI_stack_count(const BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
2012-08-05 23:29:43 +00:00
|
|
|
|
2021-12-09 20:01:44 +11:00
|
|
|
/**
|
|
|
|
* Returns true if the stack is empty, false otherwise
|
|
|
|
*/
|
2014-07-15 20:37:06 +10:00
|
|
|
bool BLI_stack_is_empty(const BLI_Stack *stack) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
|
|
|
|
2017-06-06 12:13:45 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|