|
libcfe-tables
2.9.85
some useful C-functions
|
Go to the source code of this file.
Macros | |
| #define | INIT_TABLE_TYPE_DEF(NAME) |
| #define | ADD_FIELD(ID, FUNC) get_functions[ID] = (table_get_function_t)(FUNC); |
| #define | INIT_TABLE_TYPE(NAME, TYPE) INIT_TABLE_TYPE_WITH_FIELDS(NAME, TYPE, 0, (void)0;) |
| #define | INIT_TABLE_TYPE_WITH_FIELDS(NAME, TYPE, N_F, FIELDS) |
| #define | TABLE_STORE_START(TABLE_TYPE, TABLE, P) |
| #define | TABLE_STORE_RETURN(TABLE, P, PTR) return table_store_return((table_t *)TABLE, (rec_t)P, (void *)PTR); |
| #define ADD_FIELD | ( | ID, | |
| FUNC | |||
| ) | get_functions[ID] = (table_get_function_t)(FUNC); |
| #define INIT_TABLE_TYPE | ( | NAME, | |
| TYPE | |||
| ) | INIT_TABLE_TYPE_WITH_FIELDS(NAME, TYPE, 0, (void)0;) |
Shorthand for macro INIT_TABLE_TYPE_WITH_FIELDS.
| [in] | NAME | Name this new table type. |
| [in] | TYPE | type of record. |
| #define INIT_TABLE_TYPE_DEF | ( | NAME | ) |
This creates a *_table_init and *_table_init_with_allocator function definition for a new (custom) table type.
| [in] | NAME | Name this new table type. |
| #define INIT_TABLE_TYPE_WITH_FIELDS | ( | NAME, | |
| TYPE, | |||
| N_F, | |||
| FIELDS | |||
| ) |
This creates a *_table_init and *_table_init_with_allocator functions for a new (custom) table type.
| [in] | NAME | Name this new table type. |
| [in] | TYPE | type of record. |
| [in] | N_F | Number of fields to add in the next argument |
| [in] | FIELDS | N_F amount of ADD_FIELD statements. |
| #define TABLE_STORE_RETURN | ( | TABLE, | |
| P, | |||
| PTR | |||
| ) | return table_store_return((table_t *)TABLE, (rec_t)P, (void *)PTR); |
Helper macro to call at end of a custom *_table_store function. Internally it calls table_store_return. It will call return, so no code should follow this macro.
| [in] | TABLE | Pointer to the table. |
| [in] | P | Position of the insert. |
| [in] | PTR | Pointer to the record that needs to be inserted. |
| #define TABLE_STORE_START | ( | TABLE_TYPE, | |
| TABLE, | |||
| P | |||
| ) |
Helper macro to be called at the start of a custom *_table_store function. Internally it calls table_store_start and checks the return value.
| [in] | TABLE_TYPE | unique (to this table type) character sequence to identify this type of table. |
| [in] | TABLE | Pointer to the table. |
| [in] | P | Desired position where insert. |
return -1 in case of an error, ex. not enough memory. | char* libcfe_tables_version | ( | void | ) |
Gives the version of the API.
| void* table_allocate_record | ( | const table_t * | table | ) |
Allocate space for a record. The size of the allocated memory is taken from the soe parameter given to table_new.
| [in] | table | The table where the record is for. |
| void* table_allocate_record_with_size | ( | const table_t * | table, |
| size_t | size | ||
| ) |
Allocate space for a record.
| [in] | table | The table where the record is for. |
| [in] | size | The size of the allocate memory. |
| int8_t table_check_type | ( | const table_t * | t, |
| const char * | type | ||
| ) |
Check if the table type matches the given type string. The string should be unique to a table type.
| [in] | t | Pointer to the table. |
| [in] | type | string which is unique to this type of table. |
Removes all entries in the second table which have an exact match in the first table. table one and two must be sorted tables and of the same type (or at least the should use the same compare function).
| [in] | t1 | Pointer to the first table. |
| [in] | t2 | Pointer to the second table. |
Free the memory used by a record, also calls the type specific free function to free memory allocation inside the record. The following records are not moved. So if the number is not the last record, it will leave a gap in the table. If this is a GTK Tree View (if enabled by defining _ENABLE_GTK) then the view is informed of the removal of the record.
| [in] | t | Pointer to the table. |
| [in] | i | Number of the record that should be freed. |
Remove all records from first to last (including first and last). The following records are moved forward to fill the gap. If this is a GTK Tree View (if enabled by defining _ENABLE_GTK) then the view is informed of the removal of the record and the change of the other, moved, records.
| [in] | t | Pointer to the table. |
| [in] | first | First record to remove. |
| [in] | last | Last record to remove. |
Same as table_entry_free(table_t *, rec_t), except that the following records are moved to fill the resulting gap. If this is a GTK Tree View (if enabled by defining _ENABLE_GTK) then the view is informed of the removal of the record and the change of the other, moved, records.
| [in] | t | Pointer to the table. |
| [in] | i | Number of the record that should be freed. |
| int table_entry_free_move_by_ptr | ( | table_t * | t, |
| void * | ptr | ||
| ) |
Same as table_entry_free_move(table_t *, rec_t), except that the pointer to the record is given instead of the position. This table is search to the first matching pointer.
| [in] | t | Pointer to the table. |
| [in] | ptr | Pointer to the record that should be freed. |
Move the record at the given position to the new position. It will free the new position if it already contains a record. If this is a GTK Tree View (if enabled by defining _ENABLE_GTK) then the view is informed of the change of the new position and the removal of the record at the old position.
| [in] | t | Pointer to the table. |
| [in] | from | Number of original position record. |
| [in] | to | Number of new position record. |
Swap the two given records if position. If this is a GTK Tree View (if enabled by defining _ENABLE_GTK) then the view is informed of the change of the two record.
| [in] | t | Pointer to the table. |
| [in] | i | Number of the first record. |
| [in] | j | Number of the second record. |
| int table_free | ( | table_t * | t | ) |
Free the complete table and set all values to zero(0) or NULL and erase the type. This results in a uninitialized table, and therefore this table cannot be used until it is recreated first. The table_entry_free(table_t *, rec_t) function is called to free the records.
| [in] | t | Pointer to the table. |
| void table_free_wrapper | ( | const table_t * | t, |
| void * | |||
| ) |
Wrapper for the standard free function, this is the default free function.
| [in] | t | Pointer to the table (unused). |
| [in] | ptr | Pointer to the current allocated memory. |
Returns the number of records in a table.
| [in] | t | Pointer to the table. |
Return a pointer to the record at the n-th postion in the table.
| [in] | table | Pointer to a table instance to get the record from. |
| [in] | n | Record number to return. |
n is not a valid record number. Get the record number corresponding to the given record, the record is retrieved by using the type specific get_record function
| [in] | t | Pointer to the table. |
| [in] | r | Record. |
| cfe_value_t* table_get_value_by_record | ( | const table_t * | table, |
| int | field, | ||
| void * | record | ||
| ) |
| void* table_malloc_wrapper | ( | const table_t * | t, |
| size_t | size | ||
| ) |
Wrapper for the standard malloc function, this is the default malloc function.
| [in] | t | Pointer to the table (unused). |
| [in] | size | Size of the requested memory block. |
| 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 | ||
| ) |
Create a new table instance. This function allocates the memory and initialize the table so it is ready to use. To destroy the table instance when finished, call table_free on it and after that call free on the pointer to also free the allocate memory.
| [in] | name | Name of the this table type. |
| [in] | soe | Size of a table record. |
| [in] | init_func | Pointer to the tables type specific init function. |
| [in] | comp_func | Pointer to the tables type specific compare function. |
| [in] | get_record_func | Pointer to the tables type specific get record function. |
| [in] | entry_free_func | Pointer to the tables type specific entr free function. |
| [in] | malloc_func | Function to use for data allocation. |
| [in] | realloc_func | Function to use for data reallocation. |
| [in] | free_func | Function to use for data deallocation. |
| void* table_realloc_wrapper | ( | const table_t * | t, |
| void * | ptr, | ||
| size_t | size | ||
| ) |
Wrapper for the standard realloc function, this is the default realloc function.
| [in] | t | Pointer to the table (unused). |
| [in] | ptr | Pointer to the current allocated memory. |
| [in] | size | Size of the requested memory block. |
Call this function to inform that a record has been changed. Then the appropriate callback function will be called.
| [in] | table | Pointer to the table. |
| [in] | pos | Number of the changes record. |
Call this function to inform that a record has been inserted into the table. Then the appropriate callback function will be called.
| [in] | table | Pointer to the table. |
| [in] | pos | Number of the new record. |
Call this function to inform that a record has been removed from the table. Then the appropriate callback function will be called.
| [in] | table | Pointer to the table. |
| [in] | pos | Number of the old, already removed, record. |
| void table_set_get_functions | ( | table_t * | table, |
| table_get_function_t * | array | ||
| ) |
| void table_set_inform_add | ( | table_t * | table, |
| table_alter_t | add | ||
| ) |
| void table_set_inform_change | ( | table_t * | table, |
| table_alter_t | change | ||
| ) |
| void table_set_inform_remove | ( | table_t * | table, |
| table_alter_t | remove | ||
| ) |
| void table_set_inform_user_data | ( | table_t * | table, |
| void * | user_data | ||
| ) |
| int8_t table_sort | ( | table_t * | t | ) |
Sorts the table using the type specific compare function.
| [in] | t | Pointer to the table. |
Helper function, this should be called at the end of a custom *_table_store function. It stores the record at the given position, increase the index counter and informs the GTK Tree View (if enabled by defining _ENABLE_GTK) of the insert.
| [in] | t | Pointer to the table. |
| [in] | pos | Position of the new record (there is no check if this position is free or the next available free position). |
| [in] | ptr | Pointer to the record, the pointer is stored at the given position in the table. |
Helper function, this should be called at the start of a custom *_table_store function. It validates the table, resize the table (if necessary) and moves the records if the inserted position is not at the end of the table. It also informs the GTK Tree View (if enabled by defining _ENABLE_GTK) of moves.
| [in] | type | string which is unique to this type of table. |
| [in] | t | Pointer to the table. |
| [in] | pos | Desired position of the new record. |
| int8_t table_unique | ( | table_t * | t | ) |
Remove repeated series of the same record in a sorted table. It compares records with the type specific compare function. If two consecutive records are considered equal, then the later record is removed. This will continue until each next record is considered different than the previous one. The table should be sorted by the table_sort(table_t *) function first.
| [in] | t | Pointer to the table. |
Check if the table is a valide instance and that it contains at least the requested number of records. The string should be unique to a table type.
| [in] | t | Pointer to the table. |
| [in] | i | requested record. |
| [in] | type | string which is unique to this type of table. |