Libparserutils
Data Structures | Functions
stack.c File Reference
#include <inttypes.h>
#include <string.h>
#include <parserutils/utils/stack.h>
#include <stdio.h>

Go to the source code of this file.

Data Structures

struct  parserutils_stack
 Stack object. More...
 

Functions

parserutils_error parserutils_stack_create (size_t item_size, size_t chunk_size, parserutils_stack **stack)
 Create a stack. More...
 
parserutils_error parserutils_stack_destroy (parserutils_stack *stack)
 Destroy a stack instance. More...
 
parserutils_error parserutils_stack_push (parserutils_stack *stack, const void *item)
 Push an item onto the stack. More...
 
parserutils_error parserutils_stack_pop (parserutils_stack *stack, void *item)
 Pop an item off a stack. More...
 
void * parserutils_stack_get_current (parserutils_stack *stack)
 Retrieve a pointer to the current item on the stack. More...
 
void parserutils_stack_dump (parserutils_stack *stack, const char *prefix, void(*printer)(void *item))
 

Function Documentation

parserutils_error parserutils_stack_create ( size_t  item_size,
size_t  chunk_size,
parserutils_stack **  stack 
)

Create a stack.

Parameters
item_sizeLength, in bytes, of an item in the stack
chunk_sizeNumber of stack slots in a chunk
stackPointer to location to receive stack instance
Returns
PARSERUTILS_OK on success, PARSERUTILS_BADPARM on bad parameters PARSERUTILS_NOMEM on memory exhaustion

Definition at line 35 of file stack.c.

References parserutils_stack::chunk_size, parserutils_stack::current_item, parserutils_stack::item_size, parserutils_stack::items, parserutils_stack::items_allocated, PARSERUTILS_BADPARM, PARSERUTILS_NOMEM, and PARSERUTILS_OK.

parserutils_error parserutils_stack_destroy ( parserutils_stack stack)

Destroy a stack instance.

Parameters
stackThe stack to destroy
Returns
PARSERUTILS_OK on success, appropriate error otherwise.

Definition at line 69 of file stack.c.

References parserutils_stack::items, PARSERUTILS_BADPARM, and PARSERUTILS_OK.

void parserutils_stack_dump ( parserutils_stack stack,
const char *  prefix,
void(*)(void *item)  printer 
)
void* parserutils_stack_get_current ( parserutils_stack stack)

Retrieve a pointer to the current item on the stack.

Parameters
stackThe stack to inspect
Returns
Pointer to item on stack, or NULL if none

Definition at line 151 of file stack.c.

References parserutils_stack::current_item, parserutils_stack::item_size, parserutils_stack::items, and parserutils_stack_dump().

parserutils_error parserutils_stack_pop ( parserutils_stack stack,
void *  item 
)

Pop an item off a stack.

Parameters
stackThe stack to pop from
itemPointer to location to receive popped item, or NULL
Returns
PARSERUTILS_OK on success, appropriate error otherwise.

Definition at line 126 of file stack.c.

References parserutils_stack::current_item, parserutils_stack::item_size, parserutils_stack::items, PARSERUTILS_BADPARM, PARSERUTILS_INVALID, and PARSERUTILS_OK.

parserutils_error parserutils_stack_push ( parserutils_stack stack,
const void *  item 
)

Push an item onto the stack.

Parameters
stackThe stack to push onto
itemThe item to push
Returns
PARSERUTILS_OK on success, appropriate error otherwise

Definition at line 87 of file stack.c.

References parserutils_stack::chunk_size, parserutils_stack::current_item, parserutils_stack::item_size, parserutils_stack::items, parserutils_stack::items_allocated, PARSERUTILS_BADPARM, PARSERUTILS_INVALID, PARSERUTILS_NOMEM, and PARSERUTILS_OK.