|
librdesc
|
Generic dynamic stack interface. More...
#include <stddef.h>Go to the source code of this file.
Functions | |
| void | rdesc_stack_init (struct rdesc_stack **stack, size_t element_size) |
| Initializes a new stack with the specified element size. | |
| void | rdesc_stack_destroy (struct rdesc_stack *stack) |
| Frees all memory allocated by the stack. | |
| void | rdesc_stack_reset (struct rdesc_stack **stack) |
| Clears the stack and resets capacity to initial size. | |
| void * | rdesc_stack_at (struct rdesc_stack *stack, size_t index) |
| Returns pointer to the element at the specified index. | |
| void * | rdesc_stack_multipush (struct rdesc_stack **stack, void *elements, size_t count) |
| Pushes multiple elements onto the stack. | |
| void * | rdesc_stack_push (struct rdesc_stack **stack, void *element) |
| Pushes a single element onto the stack. | |
| void * | rdesc_stack_multipop (struct rdesc_stack **stack, size_t count) |
| Pops multiple elements from the stack, and returns pointer to the element that was at the bottom of the popped range. | |
| void * | rdesc_stack_pop (struct rdesc_stack **stack) |
| Removes and returns the top element from the stack. | |
| void * | rdesc_stack_top (struct rdesc_stack *stack) |
| Returns the top element without removing it. | |
| size_t | rdesc_stack_len (const struct rdesc_stack *stack) |
| Returns the current number of elements in the stack. | |
Generic dynamic stack interface.
This header defines the function signatures required to manipulate the parser's stack. The stack is a generic, type-agnostic container that stores fixed-size elements and provides dynamic growth/shrink capabilities.
If you have defined a custom struct rdesc_stack, you must provide implementations for all functions declared in this file. The parser engine relies on these exact signatures.
The stack owns all memory it allocates. Pointers returned by stack operations (push, pop, top, at) remain valid until the next stack-modifying operation (push, pop, reset, destroy).
| void * rdesc_stack_at | ( | struct rdesc_stack * | stack, |
| size_t | index | ||
| ) |
Returns pointer to the element at the specified index.
| void rdesc_stack_destroy | ( | struct rdesc_stack * | stack | ) |
Frees all memory allocated by the stack.
| void rdesc_stack_init | ( | struct rdesc_stack ** | stack, |
| size_t | element_size | ||
| ) |
Initializes a new stack with the specified element size.
| stack | Pointer to stack pointer (will be allocated) |
| element_size | Size of each element in bytes |
| void * rdesc_stack_multipop | ( | struct rdesc_stack ** | stack, |
| size_t | count | ||
| ) |
Pops multiple elements from the stack, and returns pointer to the element that was at the bottom of the popped range.
| void * rdesc_stack_multipush | ( | struct rdesc_stack ** | stack, |
| void * | elements, | ||
| size_t | count | ||
| ) |
Pushes multiple elements onto the stack.
elements is array of elements to copy, or NULL to allocate uninitialized space.
element SHALL NOT point to the stack. | void * rdesc_stack_pop | ( | struct rdesc_stack ** | stack | ) |
Removes and returns the top element from the stack.
Equivalent to rdesc_stack_multipop(stack, 1).
| void * rdesc_stack_push | ( | struct rdesc_stack ** | stack, |
| void * | element | ||
| ) |
Pushes a single element onto the stack.
Equivalent to rdesc_stack_multipush(stack, element, 1).
| void rdesc_stack_reset | ( | struct rdesc_stack ** | stack | ) |
Clears the stack and resets capacity to initial size.