FMI Library: part of JModelica.org
|
Macros | |
#define | jm_mangle_ex(name, type) name## _ ##type |
jm_mange macro is used to construct names for the template instances Extra level (jm_mange_ex) is needed to force argument expansion (pre-scan) More... | |
#define | jm_mangle(name, type) jm_mangle_ex(name,type) |
#define | jm_vector(T) jm_mangle(jm_vector, T) |
jm_vector(T) is the type name (i.e., to be used as jm_vector(int) vi;) More... | |
#define | JM_VECTOR_MINIMAL_CAPACITY 16 |
#define | JM_VECTOR_MAX_MEMORY_CHUNK 1024 |
#define | jm_vector_declare_template(T) |
#define | jm_vector_ptr2index(T) jm_mangle(jm_vector_ptr2index, T) |
Functions | |
jm_vector_declare_template (char) static jm_string jm_vector_char2string(jm_vector(char)*v) | |
jm_vector_declare_template (int) jm_vector_declare_template(double) jm_vector_declare_template(jm_voidp) jm_vector_declare_template(size_t) jm_vector_declare_template(jm_string) jm_vector_declare_template(jm_name_ID_map_t) jm_define_comp_f(jm_compare_voidp | |
int jm_diff | jm_define_comp_f (jm_compare_int, int, jm_diff) jm_define_comp_f(jm_compare_char |
int jm_diff jm_diff | jm_define_comp_f (jm_compare_double, double, jm_diff) jm_define_comp_f(jm_compare_size_t |
int jm_diff jm_diff jm_diff | jm_define_comp_f (jm_compare_string, jm_string, strcmp) jm_define_comp_f(jm_compare_name |
jm_vector (JM_TEMPLATE_INSTANCE_TYPE)*jm_vector_alloc(JM_TEMPLATE_INSTANCE_TYPE)(size_t size | |
if (c) cc | |
if (reserve< size) reserve | |
if (reserve > JM_VECTOR_MINIMAL_CAPACITY) | |
if (!v) return 0 | |
void jm_vector_free() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a) |
size_t jm_vector_init() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a, size_t initSize, jm_callbacks *c) |
size_t jm_vector_resize() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a, size_t size) |
size_t jm_vector_copy() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*destination, jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*source) |
JM_TEMPLATE_INSTANCE_TYPE *jm_vector_insert() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a, size_t index, JM_TEMPLATE_INSTANCE_TYPE item) |
JM_TEMPLATE_INSTANCE_TYPE *jm_vector_push_back() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a, JM_TEMPLATE_INSTANCE_TYPE item) |
void jm_vector_foreach_c() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a, void(*f)(JM_TEMPLATE_INSTANCE_TYPE, void *), void *data) |
void jm_vector_foreach() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*a, void(*f)(JM_TEMPLATE_INSTANCE_TYPE)) |
void jm_vector_qsort() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*v, jm_compare_ft f) |
static size_t jm_vector_ptr2index() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*v, JM_TEMPLATE_INSTANCE_TYPE *itemp) |
size_t jm_vector_bsearch_index() | JM_TEMPLATE_INSTANCE_TYPE (jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*v, JM_TEMPLATE_INSTANCE_TYPE *key, jm_compare_ft f) |
Variables | |
int jm_diff | char |
int jm_diff jm_diff | size_t |
int jm_diff jm_diff jm_diff | jm_name_ID_map_t |
int jm_diff jm_diff jm_diff | jm_diff_name |
size_t | capacity = JM_VECTOR_MINIMAL_CAPACITY |
size_t jm_callbacks * | c |
jm_callbacks * | cc = jm_get_default_callbacks() |
reserve = capacity | |
else | |
v | callbacks = cc |
v | items = &(v->preallocated[0]) |
v | size = size |
return | v |
Vector handling functions. | |||||||
Allocates a vector on heap with the specified size and specified number of preallocated items (can be larger than size). extern jm_vector(T)* jm_vector_alloc(T)(size_t size, size_t capacity, jm_callbacks*c ); Note that there is no need to call jm_vector_init for a vector allocated with this function.
| |||||||
typedef int(* | jm_compare_ft) (const void *, const void *) | ||||||
Function type for item comparison. Can be generated with jm_define_comp_f. More... | |||||||
#define | jm_vector_alloc(T) jm_mangle(jm_vector_alloc, T) | ||||||
#define | jm_vector_free(T) jm_mangle(jm_vector_free, T) | ||||||
#define | jm_vector_init(T) jm_mangle(jm_vector_init, T) | ||||||
jm_vector_init initializes a vector allocated on stack. More... | |||||||
#define | jm_vector_free_data(T) jm_mangle(jm_vector_free_data, T) | ||||||
#define | jm_vector_get_size(T) jm_mangle(jm_vector_get_size, T) | ||||||
#define | jm_vector_get_item(T) jm_mangle(jm_vector_get_item, T) | ||||||
#define | jm_vector_get_itemp(T) jm_mangle(jm_vector_get_itemp, T) | ||||||
#define | jm_vector_get_last(T) jm_mangle(jm_vector_get_last, T) | ||||||
#define | jm_vector_get_lastp(T) jm_mangle(jm_vector_get_lastp, T) | ||||||
#define | jm_define_comp_f(F, T, COMPAR_OP) | ||||||
A conveniece macro for comparison function definition. More... | |||||||
#define | jm_diff(first, second) (int)(first-second) | ||||||
#define | jm_vector_find(T) jm_mangle(jm_vector_find, T) | ||||||
jm_vector_find functions use linear search to find items in a vector. JM_COMPAR_OP is used for comparison. More... | |||||||
#define | jm_vector_find_index(T) jm_mangle(jm_vector_find_index, T) | ||||||
#define | jm_vector_qsort(T) jm_mangle(jm_vector_qsort, T) | ||||||
#define | jm_vector_bsearch(T) jm_mangle(jm_vector_bsearch, T) | ||||||
#define | jm_vector_bsearch_index(T) jm_mangle(jm_vector_bsearch_index, T) | ||||||
#define | jm_vector_set_item(T) jm_mangle(jm_vector_set_item, T) | ||||||
#define | jm_vector_zero(T) jm_mangle(jm_vector_zero, T) | ||||||
#define | jm_vector_resize(T) jm_mangle(jm_vector_resize, T) | ||||||
#define | jm_vector_reserve(T) jm_mangle(jm_vector_reserve, T) | ||||||
#define | jm_vector_copy(T) jm_mangle(jm_vector_copy, T) | ||||||
#define | jm_vector_clone(T) jm_mangle(jm_vector_clone, T) | ||||||
#define | jm_vector_append(T) jm_mangle(jm_vector_append, T) | ||||||
#define | jm_vector_insert(T) jm_mangle(jm_vector_insert, T) | ||||||
#define | jm_vector_remove_item(T) jm_mangle(jm_vector_remove_item, T) | ||||||
#define | jm_vector_resize1(T) jm_mangle(jm_vector_resize1, T) | ||||||
#define | jm_vector_push_back(T) jm_mangle(jm_vector_push_back, T) | ||||||
#define | jm_vector_foreach(T) jm_mangle(jm_vector_foreach, T) | ||||||
#define | jm_vector_foreach_c(T) jm_mangle(jm_vector_foreach_c, T) | ||||||
#define jm_mangle_ex | ( | name, | |
type | |||
) | name## _ ##type |
jm_mange macro is used to construct names for the template instances Extra level (jm_mange_ex) is needed to force argument expansion (pre-scan)
Definition at line 44 of file jm_vector.h.
#define jm_mangle | ( | name, | |
type | |||
) | jm_mangle_ex(name,type) |
Definition at line 45 of file jm_vector.h.
#define jm_vector | ( | T | ) | jm_mangle(jm_vector, T) |
jm_vector(T) is the type name (i.e., to be used as jm_vector(int) vi;)
Definition at line 48 of file jm_vector.h.
#define jm_vector_alloc | ( | T | ) | jm_mangle(jm_vector_alloc, T) |
Definition at line 62 of file jm_vector.h.
#define jm_vector_free | ( | T | ) | jm_mangle(jm_vector_free, T) |
jm_vector_free releases the memory allocated by jm_vector_alloc. extern void jm_vector_free(T)(jm_vector(T)* a);
Definition at line 68 of file jm_vector.h.
#define jm_vector_init | ( | T | ) | jm_mangle(jm_vector_init, T) |
jm_vector_init initializes a vector allocated on stack.
Input: a - pointer to the vector to be initialized; size - initial size of the vector, can be 0 c - jm_callbacks callbacks, can be zero Returns: size of the vector (can be zero for non-zero size if memory allocation failed) Note that for initSize < JM_VECTOR_MINIMAL_CAPACITY no heap memory allocation is needed size_t jm_vector_init(T)(jm_vector(T)* a, size_t initSize, jm_callbacks* c)
Definition at line 82 of file jm_vector.h.
#define jm_vector_free_data | ( | T | ) | jm_mangle(jm_vector_free_data, T) |
jm_vector_free_data releases memory allocated for vector data This only needs to be called for stack allocated vectors (jm_vector_free does the job for heap vectors automatically) inline void jm_vector_free_data(T)(jm_vector(T)* a)
Definition at line 90 of file jm_vector.h.
#define jm_vector_get_size | ( | T | ) | jm_mangle(jm_vector_get_size, T) |
jm_vector_get_size get the vector size inline size_t jm_vector_get_size(T)(jm_vector(T)* a)
Definition at line 96 of file jm_vector.h.
#define jm_vector_get_item | ( | T | ) | jm_mangle(jm_vector_get_item, T) |
jm_vector_get_item returns the specified item. Range checking is done with an assert. inline T jm_vector_get_item(jm_vector(T)* a, size_t index)
Definition at line 102 of file jm_vector.h.
#define jm_vector_get_itemp | ( | T | ) | jm_mangle(jm_vector_get_itemp, T) |
jm_vector_get_itemp returns a pointer to the specified item. Range checking is done with an assert. inline T* jm_vector_get_itemp(jm_vector(T)* a, size_t index)
Definition at line 108 of file jm_vector.h.
#define jm_vector_get_last | ( | T | ) | jm_mangle(jm_vector_get_last, T) |
jm_vector_get_lastp returns a pointer to the last item in the vector. It is an error to call this if size=0 inline T jm_vector_get_last(jm_vector(T)* a)
Definition at line 115 of file jm_vector.h.
#define jm_vector_get_lastp | ( | T | ) | jm_mangle(jm_vector_get_lastp, T) |
jm_vector_get_lastp returns a pointer to the last item in the vector. Zero pointer is returned if size=0 inline T* jm_vector_get_lastp(jm_vector(T)* a)
Definition at line 121 of file jm_vector.h.
#define jm_define_comp_f | ( | F, | |
T, | |||
COMPAR_OP | |||
) |
A conveniece macro for comparison function definition.
#define jm_define_comp_f(F, T, COMPAR_OP) is a conveniece macro for comparison function definition to be used in sort/search operations. Here F - is the defined function name; T - type of the argument; COMPAR_OP(A,B) is a macro that returns an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. If two members compare as equal, their order in the sorted array is undefined. Default definition below is jm_diff and is implemented as (int)(first-second)
Definition at line 140 of file jm_vector.h.
#define jm_diff | ( | first, | |
second | |||
) | (int)(first-second) |
Definition at line 145 of file jm_vector.h.
#define jm_vector_find | ( | T | ) | jm_mangle(jm_vector_find, T) |
jm_vector_find functions use linear search to find items in a vector. JM_COMPAR_OP is used for comparison.
T* jm_vector_find(T)(jm_vector(T)* a, T item, jm_compare_ft f)
size_t jm_vector_find_index(T)(jm_vector(T)* a, T item, jm_compare_ft f)
a | - the vector; |
item | - the searched item; |
Return: T* jm_vector_find(T)(jm_vector(T)* a, T item, jm_compare_ft f) returns a pointer to the found item or NULL if not found size_t jm_vector_find_index(T)(jm_vector(T)* a, T item, jm_compare_ft f) return the index of the found item or size of the vector if not found.
Definition at line 161 of file jm_vector.h.
#define jm_vector_find_index | ( | T | ) | jm_mangle(jm_vector_find_index, T) |
Definition at line 162 of file jm_vector.h.
#define jm_vector_qsort | ( | T | ) | jm_mangle(jm_vector_qsort, T) |
Definition at line 170 of file jm_vector.h.
#define jm_vector_bsearch | ( | T | ) | jm_mangle(jm_vector_bsearch, T) |
jm_vector_bsearch uses standard binary search (bsearch) to find elements in a sorted vector. It returns the index of an item in the vector or vector's size if not found. JM_COMPAR_OP is used for comparison.
T* jm_vector_bsearch(T)(jm_vector(T)* v, T* key, jm_compare_ft f) size_t jm_vector_bsearch_index(T)(jm_vector(T)* v, T* key, jm_compare_ft f)
Definition at line 180 of file jm_vector.h.
#define jm_vector_bsearch_index | ( | T | ) | jm_mangle(jm_vector_bsearch_index, T) |
Definition at line 181 of file jm_vector.h.
#define jm_vector_set_item | ( | T | ) | jm_mangle(jm_vector_set_item, T) |
jm_vector_set_item sets the specified item. Range checking is done with an assert. void jm_vector_set_item(T)(jm_vector(T)* a, size_t index, T item)
Definition at line 187 of file jm_vector.h.
#define jm_vector_zero | ( | T | ) | jm_mangle(jm_vector_zero, T) |
jm_vector_zero sets all elements in the vector to zero void jm_vector_zero(T)(jm_vector(T)* a);
Definition at line 193 of file jm_vector.h.
#define jm_vector_resize | ( | T | ) | jm_mangle(jm_vector_resize, T) |
jm_vector_resize resizes the vector Input: a - the vector size - new size Return: size of the vector after operation. Can be less than size if memory allocation failed. Note: resizing to smaller vector does not release memory. size_t jm_vector_resize(T)(jm_vector(T)* a, size_t size)
Definition at line 205 of file jm_vector.h.
#define jm_vector_reserve | ( | T | ) | jm_mangle(jm_vector_reserve, T) |
jm_vector_reserve preallocates memory for the vector (to speed up consequent push_back) Returns: the actually reserved space. Can be smaller than requested "capacity" if memory allocation failed. Can be larger than "capacity" if more memory was previously allocated. size_t jm_vector_reserve(T)(jm_vector(T)* a, size_t capacity)
Definition at line 213 of file jm_vector.h.
#define jm_vector_copy | ( | T | ) | jm_mangle(jm_vector_copy, T) |
jm_vector_copy copies source vector into destination. Returns the number of elements actually copied (may be less than the source size if allocation failed). size_t jm_vector_copy(T)(jm_vector(T)* destination, jm_vector(T)* source)
Definition at line 220 of file jm_vector.h.
#define jm_vector_clone | ( | T | ) | jm_mangle(jm_vector_clone, T) |
jm_vector_clone creates a copy of the provided vector on heap and returns it. Allocated capacity matches the size of the given vector. Returns the vector pointer or zero if memory allocation failed. jm_vector(T)* jm_vector_clone(T)(jm_vector(T)* source)
Definition at line 227 of file jm_vector.h.
#define jm_vector_append | ( | T | ) | jm_mangle(jm_vector_append, T) |
jm_vector_append appends source vector into destination. Returns the number of elements actually appended (may be less than the source size if allocation failed). size_t jm_vector_append(T)(jm_vector(T)* destination, jm_vector(T)* source)
Definition at line 234 of file jm_vector.h.
#define jm_vector_insert | ( | T | ) | jm_mangle(jm_vector_insert, T) |
jm_vector_insert inserts an element at a given location. Returns a pointer to the inserted element or zero pointer if failed T* jm_vector_insert(T)(jm_vector(T)* a, size_t index, T item)
Definition at line 241 of file jm_vector.h.
#define jm_vector_remove_item | ( | T | ) | jm_mangle(jm_vector_remove_item, T) |
jm_vector_remove_item removes an item from the vector. Vector size is reduced by 1. Supplying index > size gives assertion fault. void jm_vector_remove_item(T)(jm_vector(T)* v, size_t index)
Definition at line 248 of file jm_vector.h.
#define jm_vector_resize1 | ( | T | ) | jm_mangle(jm_vector_resize1, T) |
T* jm_vector_resize1(jm_vector(T)* a) Increase the size of the vector by 1 and return a pointer to the last item. Return 0 if memory allocation failed.
Definition at line 255 of file jm_vector.h.
#define jm_vector_push_back | ( | T | ) | jm_mangle(jm_vector_push_back, T) |
jm_vector_push_back Returns a pointer to the inserted element or zero pointer if failed. T* jm_vector_push_back(jm_vector(T)* a, T item)
Definition at line 262 of file jm_vector.h.
#define jm_vector_foreach | ( | T | ) | jm_mangle(jm_vector_foreach, T) |
jm_vector_foreach calls f for each element in the vector. "contect" parameter is passed directly to the function as the second argument for the second version. void jm_vector_foreach(T)(jm_vector(T)* a, void (f)(T)) void jm_vector_foreach_c(T)(jm_vector(T) a, void (f)(T, void), void * context)
Definition at line 270 of file jm_vector.h.
#define jm_vector_foreach_c | ( | T | ) | jm_mangle(jm_vector_foreach_c, T) |
Definition at line 271 of file jm_vector.h.
#define JM_VECTOR_MINIMAL_CAPACITY 16 |
number of items always allocated on the stack
Definition at line 276 of file jm_vector.h.
#define JM_VECTOR_MAX_MEMORY_CHUNK 1024 |
maximum memory chunk (in items) to be allocated in push_back.
Definition at line 279 of file jm_vector.h.
#define jm_vector_declare_template | ( | T | ) |
Declare the struct and functions for the specified type.
Definition at line 282 of file jm_vector.h.
#define jm_vector_ptr2index | ( | T | ) | jm_mangle(jm_vector_ptr2index, T) |
Definition at line 202 of file jm_vector_template.h.
typedef int(* jm_compare_ft) (const void *, const void *) |
Function type for item comparison. Can be generated with jm_define_comp_f.
Definition at line 127 of file jm_vector.h.
jm_vector_declare_template | ( | char | ) |
Definition at line 352 of file jm_vector.h.
jm_vector_declare_template | ( | int | ) |
jm_vector | ( | JM_TEMPLATE_INSTANCE_TYPE | ) |
if | ( | c | ) |
if | ( | ) |
if | ( | reserve | , |
JM_VECTOR_MINIMAL_CAPACITY | |||
) |
Definition at line 48 of file jm_vector_template.h.
if | ( | ! | v | ) |
void jm_vector_free() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a | ) |
Definition at line 66 of file jm_vector_template.h.
size_t jm_vector_init() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a, |
size_t | initSize, | ||
jm_callbacks * | c | ||
) |
Definition at line 72 of file jm_vector_template.h.
size_t jm_vector_resize() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a, |
size_t | size | ||
) |
Definition at line 86 of file jm_vector_template.h.
size_t jm_vector_copy() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | destination, |
jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | source | ||
) |
Definition at line 109 of file jm_vector_template.h.
JM_TEMPLATE_INSTANCE_TYPE* jm_vector_insert() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a, |
size_t | index, | ||
JM_TEMPLATE_INSTANCE_TYPE | item | ||
) |
Definition at line 125 of file jm_vector_template.h.
JM_TEMPLATE_INSTANCE_TYPE* jm_vector_push_back() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a, |
JM_TEMPLATE_INSTANCE_TYPE | item | ||
) |
Definition at line 160 of file jm_vector_template.h.
void jm_vector_foreach_c() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a, |
void(*)(JM_TEMPLATE_INSTANCE_TYPE, void *) | f, | ||
void * | data | ||
) |
Definition at line 182 of file jm_vector_template.h.
void jm_vector_foreach() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | a, |
void(*)(JM_TEMPLATE_INSTANCE_TYPE) | f | ||
) |
Definition at line 189 of file jm_vector_template.h.
void jm_vector_qsort() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | v, |
jm_compare_ft | f | ||
) |
Definition at line 196 of file jm_vector_template.h.
|
static |
Definition at line 204 of file jm_vector_template.h.
size_t jm_vector_bsearch_index() JM_TEMPLATE_INSTANCE_TYPE | ( | jm_vector(JM_TEMPLATE_INSTANCE_TYPE)* | v, |
JM_TEMPLATE_INSTANCE_TYPE * | key, | ||
jm_compare_ft | f | ||
) |
Definition at line 212 of file jm_vector_template.h.
int jm_diff char |
Definition at line 369 of file jm_vector.h.
Definition at line 371 of file jm_vector.h.
Definition at line 375 of file jm_vector.h.
Definition at line 375 of file jm_vector.h.
v capacity = JM_VECTOR_MINIMAL_CAPACITY |
Definition at line 37 of file jm_vector_template.h.
Definition at line 37 of file jm_vector_template.h.
else cc = jm_get_default_callbacks() |
Definition at line 39 of file jm_vector_template.h.
reserve = capacity |
Definition at line 46 of file jm_vector_template.h.
else |
Definition at line 55 of file jm_vector_template.h.
Definition at line 60 of file jm_vector_template.h.
Definition at line 61 of file jm_vector_template.h.
v size = size |
Definition at line 62 of file jm_vector_template.h.
return v |
Definition at line 63 of file jm_vector_template.h.