cucon/stack.h: Stacks of Memory
[Linear Containers (lists, stacks, arrays)]

Data Structures

struct  cucon_stack
struct  cucon_stack_itr
struct  cucon_stack_it_s


#define cucon_stack_it_get_ptr(it)   CUCON_STACK_IT_GET(it, void *)
#define CUCON_STACK_SIZE(stack, elt_t)   (cucon_stack_size(stack)/sizeof(elt_t))
#define CUCON_STACK_TOP(stack, elt_t)   (*(elt_t*)cucon_stack_top(stack))
#define CUCON_STACK_PUSH(stack, elt_t, obj)   ((void)(*(elt_t*)cucon_stack_alloc((stack), sizeof(elt_t)) = (obj)))
#define CUCON_STACK_POP(stack, elt_t)   cucon_stack_free((stack), sizeof(elt_t))
#define CUCON_STACK_IT_ADVANCE(it, elt_t)   cucon_stack_it_advance(it, sizeof(elt_t))
#define CUCON_STACK_IT_GET(it, elt_t)   (*(elt_t*)cucon_stack_it_get(it))


typedef struct cucon_stack_mark * cucon_stack_mark_t
typedef struct cucon_stack_it_s cucon_stack_it_t


void cucon_stack_init (cucon_stack_t stack)
void cucon_stack_init_copy (cucon_stack_t dst, cucon_stack_t src)
cu_bool_t cucon_stack_is_empty (cucon_stack_t stack)
void cucon_stack_swap (cucon_stack_t stack0, cucon_stack_t stack1)
size_t cucon_stack_size (cucon_stack_t stack)
size_t cucon_stack_size_ptr (cucon_stack_t stack)
size_t cucon_stack_size_int (cucon_stack_t stack)
void * cucon_stack_at (cucon_stack_t stack, size_t pos)
void * cucon_stack_at_ptr (cucon_stack_t stack, size_t pos)
int cucon_stack_at_int (cucon_stack_t stack, size_t pos)
void * cucon_stack_top (cucon_stack_t stack)
void * cucon_stack_top_ptr (cucon_stack_t stack)
int cucon_stack_top_int (cucon_stack_t stack)
void * cucon_stack_continuous_top (cucon_stack_t stack, size_t size)
void * cucon_stack_alloc (cucon_stack_t stack, size_t size)
void cucon_stack_free (cucon_stack_t stack, size_t size)
void cucon_stack_free_ptr (cucon_stack_t stack)
void cucon_stack_push_ptr (cucon_stack_t stack, void *ptr)
void cucon_stack_push_int (cucon_stack_t stack, int i)
void * cucon_stack_pop_ptr (cucon_stack_t stack)
int cucon_stack_pop_int (cucon_stack_t stack)
cucon_stack_mark_t cucon_stack_mark (cucon_stack_t stack)
void cucon_stack_unwind_to_mark (cucon_stack_t sk, cucon_stack_mark_t mark)
void cucon_stack_itr_init (cucon_stack_itr_t itr, cucon_stack_t stack)
void * cucon_stack_itr_get (cucon_stack_itr_t itr, size_t size)
void * cucon_stack_itr_get_ptr (cucon_stack_itr_t itr)
void cucon_stack_itr_advance (cucon_stack_itr_t itr, size_t size)
cu_ptr_source_t cucon_stack_ptr_source (cucon_stack_t stack)
cucon_stack_it_t cucon_stack_begin (cucon_stack_t stack)
cu_bool_t cucon_stack_it_is_end (cucon_stack_it_t it)
void cuconP_stack_it_fix (cucon_stack_it_t *it)
void cucon_stack_it_advance (cucon_stack_it_t *it, size_t size)
void * cucon_stack_it_get (cucon_stack_it_t it)

Detailed Description

This is a stack in which you can push and pop objects of any size. Memory will be allocated in chunks of fixed size or the size of the object if it is bigger than the predefined size. This implementation is more low-level that the GNU obstacks. It does not take care of alignment, and it does not store object sizes on the stack. On the other hand, that makes it efficient.

See also:
cucon/frame.h: Constructive Stack

Define Documentation

elt_t   )     cucon_stack_it_advance(it, sizeof(elt_t))
#define CUCON_STACK_IT_GET ( it,
elt_t   )     (*(elt_t*)cucon_stack_it_get(it))
#define cucon_stack_it_get_ptr ( it   )     CUCON_STACK_IT_GET(it, void *)

Typedef Documentation

typedef struct cucon_stack_mark* cucon_stack_mark_t

An indicator of a level on a stack.

Function Documentation

void* cucon_stack_alloc ( cucon_stack_t  stack,
size_t  size 

Allocate size bytes of space on stack. If you need alignment for subsequent allocations, size must be padded to preserve alignment.

void* cucon_stack_at ( cucon_stack_t  stack,
size_t  pos 

Returns a pointer to an object pos bytes down the stack.

cucon_stack_it_t cucon_stack_begin ( cucon_stack_t  stack  ) 
void* cucon_stack_continuous_top ( cucon_stack_t  stack,
size_t  size 

Make sure at least size bytes from the top of the stack is continuous, reallocating if necessary, and return a pointer to the top of the stack.

void cucon_stack_free ( cucon_stack_t  stack,
size_t  size 

Free size bytes off the top of stack.

void cucon_stack_free_ptr ( cucon_stack_t  stack  ) 

Free sizeof(void *) from stack.

void cucon_stack_init ( cucon_stack_t  stack  ) 

Construct stack as an empty stack.

void cucon_stack_init_copy ( cucon_stack_t  dst,
cucon_stack_t  src 

Construct dst as a copy of src.

cu_bool_t cucon_stack_is_empty ( cucon_stack_t  stack  ) 

True iff stack is empty.

void cucon_stack_it_advance ( cucon_stack_it_t it,
size_t  size 
void* cucon_stack_it_get ( cucon_stack_it_t  it  ) 
cu_bool_t cucon_stack_it_is_end ( cucon_stack_it_t  it  ) 
void* cucon_stack_itr_get ( cucon_stack_itr_t  itr,
size_t  size 

Get the next size bytes stack fragment referred by itr and increment itr.

void* cucon_stack_itr_get_ptr ( cucon_stack_itr_t  itr  ) 

Get the next pointer at itr and increment itr by the pointer size.

void cucon_stack_itr_init ( cucon_stack_itr_t  itr,
cucon_stack_t  stack 

Initialise itr for iterating from top to bottom of stack.

cucon_stack_mark_t cucon_stack_mark ( cucon_stack_t  stack  ) 

A mark which can be used with cucon_stack_unwind_to_mark. Note that marks don't survive operations which re-allocate the stack, such as cucon_stack_continuous_top.

int cucon_stack_pop_int ( cucon_stack_t  stack  ) 

Pop an int off stack.

void* cucon_stack_pop_ptr ( cucon_stack_t  stack  ) 

Pop and return a pointer from the top of stack.

cu_ptr_source_t cucon_stack_ptr_source ( cucon_stack_t  stack  ) 

Assuming the elements of stack are pointers, returns a pointer source of all the elements.

void cucon_stack_push_int ( cucon_stack_t  stack,
int  i 

Push i onto stack.

void cucon_stack_push_ptr ( cucon_stack_t  stack,
void *  ptr 

Push ptr onto the top of stack.

size_t cucon_stack_size ( cucon_stack_t  stack  ) 

Number of bytes on the stack. Linear time! If you only need to know if the size is 0, use the faster cucon_stack_is_empty.

size_t cucon_stack_size_int ( cucon_stack_t  stack  ) 

The number of integers which fits in stack.

size_t cucon_stack_size_ptr ( cucon_stack_t  stack  ) 

Stack size in units of sizeof(void *). If you only need to known if the size is 0, use the faster cucon_stack_is_empty.

void cucon_stack_swap ( cucon_stack_t  stack0,
cucon_stack_t  stack1 

Swap the contents of stack0 and stack1.

void* cucon_stack_top ( cucon_stack_t  stack  ) 

Returns a pointer to the top object on stack.

int cucon_stack_top_int ( cucon_stack_t  stack  ) 

The top element of stack, assuming it is an int.

void* cucon_stack_top_ptr ( cucon_stack_t  stack  ) 

Returns the top object on stack, assuming it is a pointer.

void cucon_stack_unwind_to_mark ( cucon_stack_t  sk,
cucon_stack_mark_t  mark 

Unwind the stack to the state it had when mark was created from it.

cucon_stack_continuous_top must not have been called since mark was created.
Generated 2009-11-23 for culibs-0.25 using Doxygen. Maintained by Petter Urkedal.