FMI Library: part of JModelica.org
jm_named_ptr.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Modelon AB
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the BSD style license.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  FMILIB_License.txt file for more details.
11 
12  You should have received a copy of the FMILIB_License.txt file
13  along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15 
16 #ifndef JM_NAMED_PTR_H
17 #define JM_NAMED_PTR_H
18 
19 #include "jm_vector.h"
20 #include "jm_callbacks.h"
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
36 typedef struct jm_named_ptr jm_named_ptr;
37 
39 struct jm_named_ptr {
42 };
43 
60 jm_named_ptr jm_named_alloc(jm_string name, size_t size, size_t nameoffset, jm_callbacks* c);
61 
63 jm_named_ptr jm_named_alloc_v(jm_vector(char)* name, size_t size, size_t nameoffset, jm_callbacks* c);
64 
66 static void jm_named_free(jm_named_ptr np, jm_callbacks* c) { c->free(np.ptr); }
67 
69 
70 
71 #define jm_diff_named(a, b) strcmp(a.name,b.name)
72 
74 
75 
81  jm_vector_foreach_c(jm_named_ptr)(v, (void (*)(jm_named_ptr, void*))jm_named_free,v->callbacks);
82  jm_vector_free_data(jm_named_ptr)(v);
83 }
84 
91  jm_vector_foreach_c(jm_named_ptr)(v,(void (*)(jm_named_ptr, void*))jm_named_free,v->callbacks);
92  jm_vector_free(jm_named_ptr)(v);
93 }
95 #ifdef __cplusplus
96 }
97 #endif
98 
99 /* JM_NAMED_PTR_H */
100 #endif
size_t jm_callbacks * c
void * jm_voidp
A void pointer.
Definition: jm_types.h:35
#define jm_vector_foreach_c(T)
Definition: jm_vector.h:271
#define jm_vector_free(T)
Definition: jm_vector.h:68
#define jm_vector_free_data(T)
Definition: jm_vector.h:90
jm_vector_declare_template(jm_named_ptr) jm_define_comp_f(jm_compare_named
Helper to construct comparison operation.
jm_vector(JM_TEMPLATE_INSTANCE_TYPE)*jm_vector_alloc(JM_TEMPLATE_INSTANCE_TYPE)(size_t size
jm_string name
Object pointer.
Definition: jm_named_ptr.h:41
struct jm_named_ptr jm_named_ptr
Name and object pointer pair.
Definition: jm_named_ptr.h:36
v size
return v
static jm_diff_named void jm_named_vector_free_data(jm_vector(jm_named_ptr)*v)
Release the data allocated by the items in a vector and then clears the memory used by the vector as ...
Definition: jm_named_ptr.h:80
static void jm_named_vector_free(jm_vector(jm_named_ptr)*v)
Release the data allocated by the items in a vector and then clears the memory used by the vector as ...
Definition: jm_named_ptr.h:90
#define jm_define_comp_f(F, T, COMPAR_OP)
A conveniece macro for comparison function definition.
Definition: jm_vector.h:140
Name and object pointer pair.
Definition: jm_named_ptr.h:39
const char * jm_string
A constant string.
Definition: jm_types.h:33
#define jm_diff_named(a, b)
The callbacks struct is sent to all the modules in the library.
Definition: jm_callbacks.h:73
jm_voidp ptr
Definition: jm_named_ptr.h:40
static void jm_named_free(jm_named_ptr np, jm_callbacks *c)
Free the memory allocated for the object pointed by jm_named_ptr.
Definition: jm_named_ptr.h:66
jm_named_ptr jm_named_alloc(jm_string name, size_t size, size_t nameoffset, jm_callbacks *c)
Allocate memory for the object and the name string and sets pointer to it packed together with the na...
jm_named_ptr jm_named_alloc_v(jm_vector(char)*name, size_t size, size_t nameoffset, jm_callbacks *c)
Same as jm_named_alloc() but name is given as a jm_vector(char) pointer.
jm_free_f free
Free-allocated memory.
Definition: jm_callbacks.h:81