Simple stack implementation tailored for Pajdeg's purposes.
More...
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.
#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
-
stack | The stack to iterate. |
iter | The iteration pd_stack variable. |
A simple stack implementation.
The pd_stack is tailored to handle some common types used in Pajdeg.
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
-
stack | The stack. |
i | Expected 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
-
stack | The stack. |
key | Expected key. |
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
-
- 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
-
defs | NULL 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
-
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
-
arrStack | The array stack or DE. |
- Returns
- A simplified array stack, where each entry is a stack containing an (AE) identifier followed by the entry.
Get the number of elements in the stack.
- Parameters
-
- Returns
- Element count.
Dictionary get function.
- Parameters
-
dictStack | The dictionary stack. |
key | The key. |
remove | If 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
-
iterStack | The iteration stack. |
key | Pointer to a C string which should be pointed at the next key in the dictionary. Must not be pre-allocated. Must not be freed. |
value | Pointer to the value string. Must not be pre-allocated. Must be freed. |
- Returns
- true if key and value were set, false if not.
Look at the next PDInteger on the stack without popping it. Throws assertion if the next item is not a key.
- Parameters
-
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
-
Pop an identifier off of the stack. Throws assertion if the next item is not an identifier.
- Parameters
-
Pop and convert key into an PDInteger value. Throws assertion if the next item is not a key.
- Parameters
-
Pop a value off of source and push it onto dest.
- Parameters
-
dest | The destination stack. |
source | The 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
-
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
-
Pop and convert key into a size_t value. Throws assertion if the next item is not a key.
- Parameters
-
Pop a stack off of the stack. Throws assertion if the next item is not a stack.
- Parameters
-
Print out a stack (including pointer data).
- Parameters
-
void pd_stack_push_freeable |
( |
pd_stack * |
stack, |
|
|
void * |
info |
|
) |
| |
Push a freeable, arbitrary object.
- Parameters
-
stack | The stack. |
info | The object. Freed on stack destruction. |
void pd_stack_push_identifier |
( |
pd_stack * |
stack, |
|
|
PDID |
identifier |
|
) |
| |
Push an identifier onto a stack.
- Parameters
-
stack | The stack. |
identifier | The 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
-
stack | The stack. |
key | The 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
-
stack | The stack. |
ob | The object. It is retained on push and released on pop, or destroy. |
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
-
stack | The stack. |
pstack | The 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
-
stack | The stack. |
type | The new type. |
info | The new info object. |
void pd_stack_set_global_preserve_flag |
( |
PDBool |
preserve | ) |
|
Globally turn on or off destructive operations in stacks
- Parameters
-
preserve | Whether preserve should be enabled or not. |
- Note
- Nests truths.
Show a stack (like printing, but in a more overviewable format).
- Parameters
-
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 push [a,b,c] onto [1,2,3] -> [1,2,3,[a,b,c]]
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
-
stack | The stack. |
sstack | The stack to unshift. It is destroyed on stack destruction. |