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.
parserutils_error parserutils_stack_destroy (parserutils_stack *stack)
 Destroy a stack instance.
parserutils_error parserutils_stack_push (parserutils_stack *stack, const void *item)
 Push an item onto the stack.
parserutils_error parserutils_stack_pop (parserutils_stack *stack, void *item)
 Pop an item off a stack.
void * parserutils_stack_get_current (parserutils_stack *stack)
 Retrieve a pointer to the current item on the stack.
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_size Length, in bytes, of an item in the stack
chunk_size Number of stack slots in a chunk
stack Pointer 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:
stack The 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:
stack The 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, and parserutils_stack::items.

parserutils_error parserutils_stack_pop ( parserutils_stack stack,
void *  item 
)

Pop an item off a stack.

Parameters:
stack The stack to pop from
item Pointer 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:
stack The stack to push onto
item The 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.


Generated on Wed Jul 29 11:59:21 2015 for Libparserutils by  doxygen 1.5.6