FMI Library: part of JModelica.org
Macros
A basic stack

Macros

#define jm_stack(T)   jm_mangle(jm_stack, T)
 A basic stack of items. More...
 
#define jm_stack_alloc(T)   jm_mangle(jm_stack_alloc, T)
 Allocates a stack with the given reserved memory. More...
 
#define jm_stack_free(T)   jm_mangle(jm_stack_free, T)
 Release memory allocated for a stack. More...
 
#define jm_stack_init(T)   jm_mangle(jm_stack_init, T)
 Initializes a jm_stack allocated on stack. More...
 
#define jm_stack_free_data(T)   jm_mangle(jm_stack_free_data, T)
 Releases memory allocated for stack data. More...
 
#define jm_stack_get_size(T)   jm_mangle(jm_stack_get_size, T)
 Get the number of elements in the stack. More...
 
#define jm_stack_reserve(T)   jm_mangle(jm_stack_reserve, T)
 Preallocate memory for the stack (to speed up consequent push). More...
 
#define jm_stack_push(T)   jm_mangle(jm_stack_push, T)
 Put an element on the stack. More...
 
#define jm_stack_is_empty(T)   jm_mangle(jm_stack_is_empty, T)
 
#define jm_stack_pop(T)   jm_mangle(jm_stack_pop, T)
 
#define jm_stack_top(T)   jm_mangle(jm_stack_top, T)
 
#define jm_stack_foreach(T)   jm_mangle(jm_stack_foreach, T)
 
#define JM_STACK_MINIMAL_CAPACITY   JM_VECTOR_MINIMAL_CAPACITY
 
#define JM_STACK_MAX_MEMORY_CHUNK   JM_VECTOR_MAX_MEMORY_CHUNK
 
#define jm_stack_declare_template(T)
 

Detailed Description

Macro Definition Documentation

#define jm_stack (   T)    jm_mangle(jm_stack, T)

A basic stack of items.

Stack is implemented on top of jm_vector right now. There is a couple of extra methonds that are convenient.

Definition at line 41 of file jm_stack.h.

#define jm_stack_alloc (   T)    jm_mangle(jm_stack_alloc, T)

Allocates a stack with the given reserved memory.

1 jm_stack(T)* jm_stack_alloc(T)(size_t capacity,jm_callbacks*c );
Parameters
capacity- initial stack capacity, can be 0
c- jm_callbacks callbacks, can be zero
Returns
Newly allocated stack

Definition at line 52 of file jm_stack.h.

#define jm_stack_free (   T)    jm_mangle(jm_stack_free, T)

Release memory allocated for a stack.

1 extern void jm_stack_free(T)(jm_stack(T)* a);

Definition at line 60 of file jm_stack.h.

#define jm_stack_init (   T)    jm_mangle(jm_stack_init, T)

Initializes a jm_stack allocated on stack.

Parameters
a- pointer to the stack to be initialized;
c- jm_callbacks callbacks, can be zero
1 void jm_stack_init(T)(jm_stack(T)* a, jm_callbacks* c)

Definition at line 71 of file jm_stack.h.

#define jm_stack_free_data (   T)    jm_mangle(jm_stack_free_data, T)

Releases memory allocated for stack data.

This only needs to be called both for stack allocated jm_stack structs.

1 inline void jm_stack_free_data(T)(jm_stack(T)* a)
Parameters
a- pointer to the stack.

Definition at line 83 of file jm_stack.h.

#define jm_stack_get_size (   T)    jm_mangle(jm_stack_get_size, T)

Get the number of elements in the stack.

1 inline size_t jm_stack_get_size(T)(jm_stack(T)* a)

Definition at line 92 of file jm_stack.h.

#define jm_stack_reserve (   T)    jm_mangle(jm_stack_reserve, T)

Preallocate memory for the stack (to speed up consequent push).

Returns
The actually reserved space. Can be smaller than "capacity" if memory allocation failed. Can be larger than "capacity" if more memory was previously allocated. size_t jm_stack_reserve(T)(jm_stack(T)* a, size_t capacity)

Definition at line 101 of file jm_stack.h.

#define jm_stack_push (   T)    jm_mangle(jm_stack_push, T)

Put an element on the stack.

Returns
A pointer to the inserted element or zero pointer if failed.
1 T* jm_stack_push_back(jm_stack(T)* a, T item);

Definition at line 111 of file jm_stack.h.

#define jm_stack_is_empty (   T)    jm_mangle(jm_stack_is_empty, T)

jm_stack_is_empty returns 1 if the stack is empty and 0 otherwize. int jm_stack_is_empty(jm_stack(T)*)

Definition at line 117 of file jm_stack.h.

#define jm_stack_pop (   T)    jm_mangle(jm_stack_pop, T)

jm_stack_pop gets the stack head and moves to the next element. Popping an empty stack gives assertion failure. T jm_stack_pop(jm_stack(T)* a)

Definition at line 123 of file jm_stack.h.

#define jm_stack_top (   T)    jm_mangle(jm_stack_top, T)

jm_stack_top gets the stack top. Call on an empty stack gives assertion failure. T jm_stack_top(jm_stack(T)* a)

Definition at line 129 of file jm_stack.h.

#define jm_stack_foreach (   T)    jm_mangle(jm_stack_foreach, T)

jm_stack_foreach calls f for each element in the stack. "data" parameter is forwarded to the function as the second argument. void jm_stack_foreach(T)(jm_stack(T)* a, void (f)(T, void), void * data)

Definition at line 136 of file jm_stack.h.

#define JM_STACK_MINIMAL_CAPACITY   JM_VECTOR_MINIMAL_CAPACITY

minimal number of items always allocated for the stack

Definition at line 140 of file jm_stack.h.

#define JM_STACK_MAX_MEMORY_CHUNK   JM_VECTOR_MAX_MEMORY_CHUNK

maximum memory chunk (in items) to be allocated in push.

Definition at line 143 of file jm_stack.h.

#define jm_stack_declare_template (   T)

Declare stack for the specific type.

Definition at line 146 of file jm_stack.h.