|
qLibc
|
Linked-list-table implementation. More...
Go to the source code of this file.
Functions | |
| qlisttbl_t * | qlisttbl (int options) |
| Create a new Q_LIST linked-list container. | |
| bool | qlisttbl_put (qlisttbl_t *tbl, const char *name, const void *data, size_t size) |
| qlisttbl->put(): Put an element to this table. | |
| bool | qlisttbl_putstr (qlisttbl_t *tbl, const char *name, const char *str) |
| qlisttbl->putstr(): Put a string into this table. | |
| bool | qlisttbl_putstrf (qlisttbl_t *tbl, const char *name, const char *format,...) |
| qlisttbl->putstrf(): Put a formatted string into this table. | |
| bool | qlisttbl_putint (qlisttbl_t *tbl, const char *name, int64_t num) |
| qlisttbl->putint(): Put an integer into this table as a string. | |
| void * | qlisttbl_get (qlisttbl_t *tbl, const char *name, size_t *size, bool newmem) |
| qlisttbl->get(): Finds an object with given name. | |
| char * | qlisttbl_getstr (qlisttbl_t *tbl, const char *name, bool newmem) |
| qlisttbl->getstr(): Finds an object with given name and returns as string type. | |
| int64_t | qlisttbl_getint (qlisttbl_t *tbl, const char *name) |
| qlisttbl->getint(): Finds an object with given name and returns as integer type. | |
| qlisttbl_data_t * | qlisttbl_getmulti (qlisttbl_t *tbl, const char *name, bool newmem, size_t *numobjs) |
| qlisttbl->getmulti(): Finds all objects with the given name and returns an array of objects. | |
| void | qlisttbl_freemulti (qlisttbl_data_t *objs) |
| qlisttbl->freemulti(): Deallocate object array returned by getmulti(). | |
| size_t | qlisttbl_remove (qlisttbl_t *tbl, const char *name) |
| qlisttbl->remove(): Remove matched objects with given name. | |
| bool | qlisttbl_removeobj (qlisttbl_t *tbl, const qlisttbl_obj_t *obj) |
| qlisttbl->removeobj(): Remove objects with given object pointer. | |
| bool | qlisttbl_getnext (qlisttbl_t *tbl, qlisttbl_obj_t *obj, const char *name, bool newmem) |
| qlisttbl->getnext(): Get next element. | |
| size_t | qlisttbl_size (qlisttbl_t *tbl) |
| qlisttbl->size(): Returns the number of elements in this table. | |
| void | qlisttbl_sort (qlisttbl_t *tbl) |
| qlisttbl->sort(): Sort keys in this table. | |
| void | qlisttbl_clear (qlisttbl_t *tbl) |
| qlisttbl->clear(): Removes all of the elements from this table. | |
| bool | qlisttbl_save (qlisttbl_t *tbl, const char *filepath, char sepchar, bool encode) |
| qlisttbl->save(): Save qlisttbl as plain text format Dumping direction is always forward(from the top to the bottom) to preserve the order when we load the file again. | |
| ssize_t | qlisttbl_load (qlisttbl_t *tbl, const char *filepath, char sepchar, bool decode) |
| qlisttbl->load(): Load and append entries from given filepath Loading direction is always appending at the bottom of the table to preserve the order as it was. | |
| bool | qlisttbl_debug (qlisttbl_t *tbl, FILE *out) |
| qlisttbl->debug(): Prints stored elements for debugging purposes. | |
| void | qlisttbl_lock (qlisttbl_t *tbl) |
| qlisttbl->lock(): Enter critical section. | |
| void | qlisttbl_unlock (qlisttbl_t *tbl) |
| qlisttbl->unlock(): Leave critical section. | |
| void | qlisttbl_free (qlisttbl_t *tbl) |
| qlisttbl->free(): Free qlisttbl_t | |
Linked-list-table implementation.
qlisttbl container is a Linked-List-Table implementation that maps keys to values. Keys are strings, and values are any non-null objects. These elements are stored sequentially in a Doubly-Linked-List data structure.
Compared to Hash-Table, List-Table is efficient when you need to keep duplicated keys since Hash-Table only keep unique keys. Of course, qlisttbl supports both unique keys and key duplication.
Definition in file qlisttbl.c.
| qlisttbl_t * qlisttbl | ( | int | options | ) |
Create a new Q_LIST linked-list container.
| options | combination of initialization options |
| errno | will be set in error condition.
|
Definition at line 149 of file qlisttbl.c.
| bool qlisttbl_put | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| const void * | data, | ||
| size_t | size ) |
qlisttbl->put(): Put an element to this table.
| tbl | qlisttbl container pointer. |
| name | element name. |
| data | a pointer which points data memory. |
| size | size of the data. |
| errno | will be set in error condition.
|
Definition at line 247 of file qlisttbl.c.
| bool qlisttbl_putstr | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| const char * | str ) |
qlisttbl->putstr(): Put a string into this table.
| tbl | qlisttbl container pointer. |
| name | element name. |
| str | string data. |
| errno | will be set in error condition.
|
Definition at line 293 of file qlisttbl.c.
| bool qlisttbl_putstrf | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| const char * | format, | ||
| ... ) |
qlisttbl->putstrf(): Put a formatted string into this table.
| tbl | qlisttbl container pointer. |
| name | element name. |
| format | formatted value string. |
| errno | will be set in error condition.
|
Definition at line 310 of file qlisttbl.c.
| bool qlisttbl_putint | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| int64_t | num ) |
qlisttbl->putint(): Put an integer into this table as a string.
| tbl | qlisttbl container pointer. |
| name | element name. |
| num | number data. |
| errno | will be set in error condition.
|
Definition at line 340 of file qlisttbl.c.
| void * qlisttbl_get | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| size_t * | size, | ||
| bool | newmem ) |
qlisttbl->get(): Finds an object with given name.
If there are duplicate keys in the table, this will return the first matched one from the bottom (or the top if QLISTTBL_LOOKUPFORWARD option was given). So if there are duplicated keys, it'll return recently inserted one.
| tbl | qlisttbl container pointer. |
| name | element name. |
| size | if size is not NULL, data size will be stored. |
| newmem | whether or not to allocate memory for the data. |
| errno | will be set in error condition.
|
Definition at line 385 of file qlisttbl.c.
| char * qlisttbl_getstr | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| bool | newmem ) |
qlisttbl->getstr(): Finds an object with given name and returns as string type.
| tbl | qlisttbl container pointer. |
| name | element name. |
| newmem | whether or not to allocate memory for the data. |
| errno | will be set in error condition.
|
Definition at line 434 of file qlisttbl.c.
| int64_t qlisttbl_getint | ( | qlisttbl_t * | tbl, |
| const char * | name ) |
qlisttbl->getint(): Finds an object with given name and returns as integer type.
| tbl | qlisttbl container pointer. |
| name | element name. |
| errno | will be set in error condition.
|
Definition at line 451 of file qlisttbl.c.
| qlisttbl_data_t * qlisttbl_getmulti | ( | qlisttbl_t * | tbl, |
| const char * | name, | ||
| bool | newmem, | ||
| size_t * | numobjs ) |
qlisttbl->getmulti(): Finds all objects with the given name and returns an array of objects.
If there are duplicate keys in the table, this returns all matching ones. The order of returned objects depends on the setnextdir() setting. By default, the order is the same (forward) as listed in the table.
| tbl | qlisttbl container pointer. |
| name | element name. |
| newmem | whether or not to allocate memory for the data. |
| numobjs | the number of returned objects will be stored here. (can be NULL) |
| errno | will be set in error condition.
|
Definition at line 496 of file qlisttbl.c.
| void qlisttbl_freemulti | ( | qlisttbl_data_t * | objs | ) |
qlisttbl->freemulti(): Deallocate object array returned by getmulti().
| objs | pointer of array of qlisttbl_data_t. |
Definition at line 564 of file qlisttbl.c.
| size_t qlisttbl_remove | ( | qlisttbl_t * | tbl, |
| const char * | name ) |
qlisttbl->remove(): Remove matched objects with given name.
| tbl | qlisttbl container pointer. |
| name | element name. |
Definition at line 583 of file qlisttbl.c.
| bool qlisttbl_removeobj | ( | qlisttbl_t * | tbl, |
| const qlisttbl_obj_t * | obj ) |
qlisttbl->removeobj(): Remove objects with given object pointer.
This call is useful when you want to remove an element while traversing a table using getnext(). The address pointed to by obj may be different from the actual object in the table, but that is OK because we will recalculate the actual object address by following its links.
| tbl | qlisttbl container pointer. |
| obj | object to remove. |
| errno | will be set in error condition.
|
Definition at line 625 of file qlisttbl.c.
| bool qlisttbl_getnext | ( | qlisttbl_t * | tbl, |
| qlisttbl_obj_t * | obj, | ||
| const char * | name, | ||
| bool | newmem ) |
qlisttbl->getnext(): Get next element.
Default searching direction is backward, from the bottom to top unless QLISTTBL_LOOKUPFORWARD option was specified.
| tbl | qlisttbl container pointer. |
| obj | found data will be stored in this object |
| name | element name. If the key name is NULL, search all objects in the table. |
| newmem | whether or not to allocate memory for the data. |
| errno | will be set in error condition.
|
Definition at line 715 of file qlisttbl.c.
| size_t qlisttbl_size | ( | qlisttbl_t * | tbl | ) |
qlisttbl->size(): Returns the number of elements in this table.
| tbl | qlisttbl container pointer. |
Definition at line 786 of file qlisttbl.c.
| void qlisttbl_sort | ( | qlisttbl_t * | tbl | ) |
qlisttbl->sort(): Sort keys in this table.
| tbl | qlisttbl container pointer. |
Definition at line 812 of file qlisttbl.c.
| void qlisttbl_clear | ( | qlisttbl_t * | tbl | ) |
qlisttbl->clear(): Removes all of the elements from this table.
| tbl | qlisttbl container pointer. |
Definition at line 847 of file qlisttbl.c.
| bool qlisttbl_save | ( | qlisttbl_t * | tbl, |
| const char * | filepath, | ||
| char | sepchar, | ||
| bool | encode ) |
qlisttbl->save(): Save qlisttbl as plain text format Dumping direction is always forward(from the top to the bottom) to preserve the order when we load the file again.
| tbl | qlisttbl container pointer. |
| filepath | save file path |
| sepchar | separator character between name and value. normally '=' is used. |
| encode | flag for encoding data . false can be used if the all data are string or integer type and has no new line. otherwise true must be set. |
Definition at line 879 of file qlisttbl.c.
| ssize_t qlisttbl_load | ( | qlisttbl_t * | tbl, |
| const char * | filepath, | ||
| char | sepchar, | ||
| bool | decode ) |
qlisttbl->load(): Load and append entries from given filepath Loading direction is always appending at the bottom of the table to preserve the order as it was.
| tbl | qlisttbl container pointer. |
| filepath | save file path |
| sepchar | separator character between name and value. normally '=' is used |
| decode | flag for decoding data |
Definition at line 924 of file qlisttbl.c.
| bool qlisttbl_debug | ( | qlisttbl_t * | tbl, |
| FILE * | out ) |
qlisttbl->debug(): Prints stored elements for debugging purposes.
| tbl | qlisttbl container pointer. |
| out | output stream such as stdout or stderr. |
| errno | will be set in error condition.
|
Definition at line 975 of file qlisttbl.c.
| void qlisttbl_lock | ( | qlisttbl_t * | tbl | ) |
qlisttbl->lock(): Enter critical section.
| tbl | qlisttbl container pointer. |
Definition at line 1002 of file qlisttbl.c.
| void qlisttbl_unlock | ( | qlisttbl_t * | tbl | ) |
qlisttbl->unlock(): Leave critical section.
| tbl | qlisttbl container pointer. |
Definition at line 1011 of file qlisttbl.c.
| void qlisttbl_free | ( | qlisttbl_t * | tbl | ) |
qlisttbl->free(): Free qlisttbl_t
| tbl | qlisttbl container pointer. |
Definition at line 1020 of file qlisttbl.c.