Pajdeg  0.2.2
Pajdeg
Files | Typedefs | Functions

Simple stack implementation tailored for Pajdeg's purposes. More...

Files

file  pd_stack.h
 

Typedefs

typedef struct pd_stackpd_stack
 

Functions

void pd_stack_set_global_preserve_flag (PDBool preserve)
 

Pushing onto stack

void pd_stack_push_key (pd_stack *stack, char *key)
 
void pd_stack_push_identifier (pd_stack *stack, PDID identifier)
 
void pd_stack_push_freeable (pd_stack *stack, void *info)
 
void pd_stack_push_stack (pd_stack *stack, pd_stack pstack)
 
void pd_stack_push_object (pd_stack *stack, void *ob)
 
void pd_stack_unshift_stack (pd_stack *stack, pd_stack sstack)
 
pd_stack pd_stack_copy (pd_stack stack)
 

Popping from stack

void pd_stack_destroy (pd_stack *stack)
 
char * pd_stack_pop_key (pd_stack *stack)
 
PDID pd_stack_pop_identifier (pd_stack *stack)
 
pd_stack pd_stack_pop_stack (pd_stack *stack)
 
void * pd_stack_pop_object (pd_stack *stack)
 
void * pd_stack_pop_freeable (pd_stack *stack)
 
PDSize pd_stack_pop_size (pd_stack *stack)
 
PDInteger pd_stack_pop_int (pd_stack *stack)
 
void pd_stack_assert_expected_key (pd_stack *stack, const char *key)
 
void pd_stack_assert_expected_int (pd_stack *stack, PDInteger i)
 
PDInteger pd_stack_peek_int (pd_stack stack)
 

Convenience features

PDInteger pd_stack_get_count (pd_stack stack)
 
void pd_stack_pop_into (pd_stack *dest, pd_stack *source)
 
pd_stack pd_stack_get_dict_key (pd_stack dictStack, const char *key, PDBool remove)
 
PDBool pd_stack_get_next_dict_key (pd_stack *iterStack, char **key, char **value)
 
pd_stack pd_stack_get_arr (pd_stack arrStack)
 
void pd_stack_replace_info_object (pd_stack stack, char type, void *info)
 
pd_stack pd_stack_create_from_definition (const void **defs)
 
#define pd_stack_for_each(stack, iter)   for (iter = stack; iter; iter = iter->prev)
 

Debugging

void pd_stack_print (pd_stack stack)
 
void pd_stack_show (pd_stack stack)
 

Detailed Description

Simple stack implementation tailored for Pajdeg's purposes.

The pd_stack works like any other stack, except it has some amount of awareness about certain object types.

Macro Definition Documentation

#define pd_stack_for_each (   stack,
  iter 
)    for (iter = stack; iter; iter = iter->prev)

Non-destructive stack iteration.

This simply constructs a for loop that iterates over and puts the pd_stack entries of the stack into the iter stack one at a time.

Parameters
stackThe stack to iterate.
iterThe iteration pd_stack variable.

Typedef Documentation

typedef struct pd_stack* pd_stack

A simple stack implementation.

The pd_stack is tailored to handle some common types used in Pajdeg.

Function Documentation

void pd_stack_assert_expected_int ( pd_stack stack,
PDInteger  i 
)

Pop the next key, verify that its integer value is equal to the given integer, and then discard it.

Throws assertion if any of this is not the case.

Parameters
stackThe stack.
iExpected integer value.
void pd_stack_assert_expected_key ( pd_stack stack,
const char *  key 
)

Pop the next key, verify that it is equal to the given key, and then discard it.

Throws assertion if any of this is not the case.

Parameters
stackThe stack.
keyExpected key.
pd_stack pd_stack_copy ( pd_stack  stack)

Copy a stack in its entirety, strdup()ing as necessary to prevent double-free() calls when destroyed.

In other words, this creates a stack which is entirely isolated from the original, which may be destroyed without incident.

Parameters
stackThe stack to copy.
Returns
A copy of the stack.
pd_stack pd_stack_create_from_definition ( const void **  defs)

Set up a stack with NULL terminated list of values, put in backward.

Parameters
defsNULL terminated list of values.
Returns
Stack with each value pushed as an identifier.
void pd_stack_destroy ( pd_stack stack)

Destroy a stack (getting rid of every item according to its type).

Parameters
stackThe stack.
pd_stack pd_stack_get_arr ( pd_stack  arrStack)

Convert a complex array stack or a dictionary entry containing a complex array object into a simple array stack.

Note
Arrays are most often listed in reverse order in stacks.
Warning
The returned stack must not be modified or destroyed. It is still a part of arrStack.
Parameters
arrStackThe array stack or DE.
Returns
A simplified array stack, where each entry is a stack containing an (AE) identifier followed by the entry.
PDInteger pd_stack_get_count ( pd_stack  stack)

Get the number of elements in the stack.

Parameters
stackThe stack.
Returns
Element count.
pd_stack pd_stack_get_dict_key ( pd_stack  dictStack,
const char *  key,
PDBool  remove 
)

Dictionary get function.

Parameters
dictStackThe dictionary stack.
keyThe key.
removeIf true, the entry for the key is removed from the dictionary stack.
Returns
The pd_stack for the given dictionary entry.
PDBool pd_stack_get_next_dict_key ( pd_stack iterStack,
char **  key,
char **  value 
)

Non-destructive stack iteration.

Converts the value of the dictionary entry into a string representation.

Warning
In order to use this function, a supplementary pd_stack must be set to the dictionary stack, and then used as the iterStack argument. Passing the master dictionary will result in the (memory / information) loss of the stack.
Note
Value must be freed, key must not.
Parameters
iterStackThe iteration stack.
keyPointer to a C string which should be pointed at the next key in the dictionary. Must not be pre-allocated. Must not be freed.
valuePointer to the value string. Must not be pre-allocated. Must be freed.
Returns
true if key and value were set, false if not.
PDInteger pd_stack_peek_int ( pd_stack  stack)

Look at the next PDInteger on the stack without popping it. Throws assertion if the next item is not a key.

Parameters
stackThe stack.
void* pd_stack_pop_freeable ( pd_stack stack)

Pop a freeable off of the stack. Throws assertion if the next item is not a freeable.

Parameters
stackThe stack.
PDID pd_stack_pop_identifier ( pd_stack stack)

Pop an identifier off of the stack. Throws assertion if the next item is not an identifier.

Parameters
stackThe stack.
PDInteger pd_stack_pop_int ( pd_stack stack)

Pop and convert key into an PDInteger value. Throws assertion if the next item is not a key.

Parameters
stackThe stack.
void pd_stack_pop_into ( pd_stack dest,
pd_stack source 
)

Pop a value off of source and push it onto dest.

Parameters
destThe destination stack.
sourceThe source stack. Must not be NULL.
char* pd_stack_pop_key ( pd_stack stack)

Pop a key off of the stack. Throws assertion if the next item is not a key.

Parameters
stackThe stack.
void* pd_stack_pop_object ( pd_stack stack)

Pop a PDType object off of the stack. Throws assertion if the next item is not a PD object.

Parameters
stackThe stack.
PDSize pd_stack_pop_size ( pd_stack stack)

Pop and convert key into a size_t value. Throws assertion if the next item is not a key.

Parameters
stackThe stack.
pd_stack pd_stack_pop_stack ( pd_stack stack)

Pop a stack off of the stack. Throws assertion if the next item is not a stack.

Parameters
stackThe stack.
void pd_stack_print ( pd_stack  stack)

Print out a stack (including pointer data).

Parameters
stackThe stack.
void pd_stack_push_freeable ( pd_stack stack,
void *  info 
)

Push a freeable, arbitrary object.

Parameters
stackThe stack.
infoThe object. Freed on stack destruction.
void pd_stack_push_identifier ( pd_stack stack,
PDID  identifier 
)

Push an identifier onto a stack.

Parameters
stackThe stack.
identifierThe identifier. Can be anything. Never touched.
void pd_stack_push_key ( pd_stack stack,
char *  key 
)

Push a key (a string value) onto a stack.

Parameters
stackThe stack.
keyThe key. It is taken as is and freed on stack destruction.
void pd_stack_push_object ( pd_stack stack,
void *  ob 
)

Push a PDType object.

Parameters
stackThe stack.
obThe object. It is retained on push and released on pop, or destroy.
void pd_stack_push_stack ( pd_stack stack,
pd_stack  pstack 
)

Push a stack onto the stack.

Note
This is not an append operation; the pushed stack becomes a single entry that is a stack.
Parameters
stackThe stack.
pstackThe stack to push. It is destroyed on stack destruction.
void pd_stack_replace_info_object ( pd_stack  stack,
char  type,
void *  info 
)

Replace info object in stack object with a new info object of the given type.

Parameters
stackThe stack.
typeThe new type.
infoThe new info object.
void pd_stack_set_global_preserve_flag ( PDBool  preserve)

Globally turn on or off destructive operations in stacks

Parameters
preserveWhether preserve should be enabled or not.
Note
Nests truths.
void pd_stack_show ( pd_stack  stack)

Show a stack (like printing, but in a more overviewable format).

Parameters
stackThe stack.
void pd_stack_unshift_stack ( pd_stack stack,
pd_stack  sstack 
)

Unshift (put in from the start) a stack onto a stack.

The difference between this and pushing a stack is demonstrated by the following:

  1. 1 push [a,b,c] onto [1,2,3] -> [1,2,3,[a,b,c]]
  2. 1 unshift [a,b,c] onto [1,2,3] -> [[a,b,c],1,2,3]
Note
This is only here to deal with reversed dictionaries/arrays; support for unshifting was never intended.
Parameters
stackThe stack.
sstackThe stack to unshift. It is destroyed on stack destruction.