libcfe-tables  2.9.85
some useful C-functions
tables.h
Go to the documentation of this file.
1 /* kate: indent-mode cstyle; tab-width 4; indent-width 4; */
2 #ifndef XTABLES_H
3 #define XTABLES_H
4 
5 #include <cfe-tables/typedef.h>
6 #include <stdint.h>
7 #include <cfe/cfe_value.h>
8 
26 table_t *table_new(const char *name, size_t soe, table_init_t init_func, table_compare_t comp_func, table_get_record_number_by_pointer_t get_record_func, table_free_entry_t entry_free_func, table_malloc_func_t malloc_func, table_realloc_func_t realloc_func, table_free_func_t free_func);
27 
35 void *table_get_record(const table_t *table, rec_t n);
36 
44 void *table_allocate_record(const table_t *table);
45 
53 void *table_allocate_record_with_size(const table_t *table, size_t size);
54 
55 /* functions to set the inform callback funtions and user data */
57 void table_set_inform_remove(table_t *table, table_alter_t remove);
58 void table_set_inform_change(table_t *table, table_alter_t change);
59 void table_set_inform_user_data(table_t *table, void *user_data);
60 
61 /* Set the data retrieval functions for this table */
63 
64 /* Data retrieval. */
65 cfe_value_t *table_get_value_by_number(const table_t *table, int field, rec_t n);
66 cfe_value_t *table_get_value_by_record(const table_t *table, int field, void *record);
67 
77 rec_t table_store_start(const char *type, table_t *t, rec_t pos);
78 
87 rec_t table_store_return(table_t *t, rec_t pos, void *ptr);
88 
95 
104 int8_t table_check_type(const table_t *t, const char *type);
105 
115 int8_t table_validate(const table_t *t, rec_t i, const char *type);
116 
125 int8_t table_unique(table_t *t);
126 
134 int8_t table_diff(const table_t *t1, table_t *t2);
135 
147 int8_t table_sort(table_t *t);
148 
155 
162 void table_record_changed(const table_t *table, rec_t pos);
163 
170 void table_record_inserted(const table_t *table, rec_t pos);
171 
178 void table_record_removed(const table_t *table, rec_t pos);
179 
188 int table_entry_free(table_t *t, rec_t i);
189 
197 void table_entry_swap(table_t *t, rec_t i, rec_t j);
198 
206 void table_entry_move(table_t *t, rec_t from, rec_t to);
207 
216 
224 int table_entry_free_move_by_ptr(table_t *t, void *ptr);
225 
234 int table_entry_free_block_move(table_t *t, rec_t first, rec_t last);
235 
243 int table_free(table_t *t);
244 
251 void *table_malloc_wrapper(const table_t *t, size_t size);
252 
260 void *table_realloc_wrapper(const table_t *t, void *ptr, size_t size);
261 
267 void table_free_wrapper(const table_t *t, void *);
268 
273 char *libcfe_tables_version(void);
274 
279 #define INIT_TABLE_TYPE_DEF(NAME) \
280 table_t * NAME##_table_init(void); \
281 table_t * NAME##_table_init_with_allocator(table_malloc_func_t malloc_func, table_realloc_func_t realloc_func, table_free_func_t free_func);
282 
288 #define ADD_FIELD(ID, FUNC) get_functions[ID] = (table_get_function_t)(FUNC);
289 
296 #define INIT_TABLE_TYPE(NAME, TYPE) INIT_TABLE_TYPE_WITH_FIELDS(NAME, TYPE, 0, (void)0;)
297 
305 #define INIT_TABLE_TYPE_WITH_FIELDS(NAME, TYPE, N_F, FIELDS) \
306 table_t * NAME##_table_init(void) \
307 { \
308  return NAME##_table_init_with_allocator(table_malloc_wrapper, table_realloc_wrapper, table_free_wrapper); \
309 } \
310 table_t * NAME##_table_init_with_allocator(table_malloc_func_t malloc_func, table_realloc_func_t realloc_func, table_free_func_t free_func) \
311 { \
312  table_t *t = table_new(#NAME, sizeof(TYPE), NAME##_table_init, NAME##_table_compare, NAME##_table_get_record, NAME##_table_entry_free, malloc_func, realloc_func, free_func); \
313  table_get_function_t *get_functions = (table_get_function_t *)malloc(N_F * sizeof(table_get_function_t)); \
314  FIELDS \
315  table_set_get_functions(t, get_functions); \
316  return t; \
317 }
318 
326 #define TABLE_STORE_START(TABLE_TYPE, TABLE, P) \
327 P = table_store_start(#TABLE_TYPE, (table_t *)TABLE, (rec_t)P); \
328 if(P == RECORD_INVALID) \
329 { \
330 return RECORD_INVALID; \
331 }
332 
339 #define TABLE_STORE_RETURN(TABLE, P, PTR) return table_store_return((table_t *)TABLE, (rec_t)P, (void *)PTR);
340 
341 #endif /* XTABLES_H */
int8_t table_sort(table_t *t)
rec_t table_get_num_records(const table_t *t)
void table_set_get_functions(table_t *table, table_get_function_t *array)
int table_entry_free_move_by_ptr(table_t *t, void *ptr)
void table_set_inform_add(table_t *table, table_alter_t add)
int table_entry_free_block_move(table_t *t, rec_t first, rec_t last)
void table_set_inform_user_data(table_t *table, void *user_data)
int(* table_compare_t)(void *, void *)
Definition: typedef.h:19
void(* table_alter_t)(const table_t *, rec_t, void *user_data)
Definition: typedef.h:29
cfe_value_t *(* table_get_function_t)(const table_t *, void *)
Definition: typedef.h:32
table_t *(* table_init_t)(void)
Type specific initialize function.
Definition: typedef.h:18
int table_entry_free_move(table_t *t, rec_t i)
int table_free(table_t *t)
void * table_get_record(const table_t *table, rec_t n)
void * table_realloc_wrapper(const table_t *t, void *ptr, size_t size)
void(* table_free_func_t)(const table_t *, void *)
Definition: typedef.h:26
int table_entry_free(table_t *t, rec_t i)
char * libcfe_tables_version(void)
cfe_value_t * table_get_value_by_number(const table_t *table, int field, rec_t n)
void * table_malloc_wrapper(const table_t *t, size_t size)
void table_record_removed(const table_t *table, rec_t pos)
int8_t table_check_type(const table_t *t, const char *type)
void * table_allocate_record_with_size(const table_t *table, size_t size)
rec_t table_store_return(table_t *t, rec_t pos, void *ptr)
void(* table_free_entry_t)(void *)
Type specific function to free the memory used inside a record.
Definition: typedef.h:21
void table_set_inform_change(table_t *table, table_alter_t change)
void *(* table_malloc_func_t)(const table_t *, size_t)
Definition: typedef.h:24
struct _table table_t
Table type.
Definition: typedef.h:14
void table_free_wrapper(const table_t *t, void *)
int8_t table_validate(const table_t *t, rec_t i, const char *type)
int8_t table_diff(const table_t *t1, table_t *t2)
rec_t table_get_record_number_by_pointer(const table_t *t, void *r)
void table_set_inform_remove(table_t *table, table_alter_t remove)
int8_t table_unique(table_t *t)
void table_entry_move(table_t *t, rec_t from, rec_t to)
uint32_t rec_t
Type to identify a record number.
Definition: typedef.h:15
void table_record_inserted(const table_t *table, rec_t pos)
table_t * table_new(const char *name, size_t soe, table_init_t init_func, table_compare_t comp_func, table_get_record_number_by_pointer_t get_record_func, table_free_entry_t entry_free_func, table_malloc_func_t malloc_func, table_realloc_func_t realloc_func, table_free_func_t free_func)
void table_entry_swap(table_t *t, rec_t i, rec_t j)
void table_record_changed(const table_t *table, rec_t pos)
void * table_allocate_record(const table_t *table)
rec_t(* table_get_record_number_by_pointer_t)(const table_t *, void *)
Type specific function to get the record number of a give record.
Definition: typedef.h:20
rec_t table_store_start(const char *type, table_t *t, rec_t pos)
void *(* table_realloc_func_t)(const table_t *, void *, size_t)
Definition: typedef.h:25
cfe_value_t * table_get_value_by_record(const table_t *table, int field, void *record)