|
qgrow_t * | qgrow (int options) |
| Initialize grow.
|
|
bool | qgrow_add (qgrow_t *grow, const void *data, size_t size) |
| qgrow->add(): Stack object
|
|
bool | qgrow_addstr (qgrow_t *grow, const char *str) |
| qgrow->addstr(): Stack string
|
|
bool | qgrow_addstrf (qgrow_t *grow, const char *format,...) |
| qgrow->addstrf(): Stack formatted string
|
|
size_t | qgrow_size (qgrow_t *grow) |
| qgrow->size(): Returns the number of elements in this grow.
|
|
size_t | qgrow_datasize (qgrow_t *grow) |
| qgrow->datasize(): Returns the sum of total element size in this grow.
|
|
void * | qgrow_toarray (qgrow_t *grow, size_t *size) |
| qgrow->toarray(): Returns the serialized chunk containing all the elements in this grow.
|
|
char * | qgrow_tostring (qgrow_t *grow) |
| qgrow->tostring(): Returns a string representation of this grow, containing string representation of each element.
|
|
void | qgrow_clear (qgrow_t *grow) |
| qgrow->clear(): Removes all of the elements from this grow.
|
|
bool | qgrow_debug (qgrow_t *grow, FILE *out) |
| qgrow->debug(): Print out stored elements for debugging purpose.
|
|
void | qgrow_free (qgrow_t *grow) |
| qgrow->free(): De-allocate grow
|
|
Grow container that handles growable objects.
qgrow container is a grow implementation. It implements a growable array of objects and it extends qlist container that allow a linked-list to be treated as a grow.
[Code sample - Object]
qgrow_t *grow =
qgrow(QGROW_THREADSAFE);
grow->addstr(grow, "AB");
grow->addstrf(grow, "%d", 12);
grow->addstr(grow, "CD");
char *final = grow->tostring(grow);
printf("Number of elements = %zu\n", grow->size(grow));
printf("Final string = %s\n", final);
free(final);
grow->free(grow);
[Result]
Number of elements = 3
Final string = AB12CD
qgrow_t * qgrow(int options)
Initialize grow.
[Code sample - Object]
struct sampleobj {
int num;
char str[10];
};
int i;
struct sampleobj obj;
for(i = 0; i < 3; i++) {
obj.num = i;
sprintf(obj.str, "hello%d", i);
grow->add(grow, (void *)&obj, sizeof(struct sampleobj));
}
struct sampleobj *final;
final = (struct sampleobj *)grow->toarray(grow, NULL);
printf("Number of Objects = %zu\n", grow->size(grow));
for(i = 0; i < grow->size(grow); i++) {
printf("Object%d %d, %s\n", i+1, final[i].num, final[i].str);
}
free(final);
grow->free(grow);
[Result]
Number of Objects = 3
Object1 0, hello0
Object2 1, hello1
Object3 2, hello2
Definition in file qgrow.c.