Functions | |
Q_OBSTACK * | qObstackInit (void) |
Initialize object-stack. | |
bool | qObstackGrow (Q_OBSTACK *obstack, const void *object, size_t size) |
Stack object. | |
bool | qObstackGrowStr (Q_OBSTACK *obstack, const char *str) |
Stack string. | |
bool | qObstackGrowStrf (Q_OBSTACK *obstack, const char *format,…) |
Stack formatted string. | |
void * | qObstackFinish (Q_OBSTACK *obstack) |
Stack formatted string. | |
void * | qObstackGetFinal (Q_OBSTACK *obstack) |
Finalize objects and get merged single final object pointer. | |
size_t | qObstackGetSize (Q_OBSTACK *obstack) |
Get stacked objects size. | |
int | qObstackGetNum (Q_OBSTACK *obstack) |
Under-development. | |
bool | qObstackFree (Q_OBSTACK *obstack) |
Under-development. |
An qObstack is a pool of memory containing a stack of objects. An qObstack can contain any number of objects of any size.
[Code sample - String] Q_OBSTACK *obstack; char *final; char *tmp = "CDE"; // get new obstack obstack = qObstackInit(); // stack qObstackGrowStr(obstack, "AB"); // no need to supply size qObstackGrowStrf(obstack, "%s", tmp); // for formatted string qObstackGrow(obstack, "FGH", 3); // same effects as above but this can // be used for object or binary // final final = (char *)qObstackFinish(obstack); // print out printf("Final string = %sn", final); printf("Total Size = %d, Number of Objects = %dn", qObstackGetSize(obstack), qObstackGetNum(obstack)); qObstackFree(obstack); [Result] Final string = ABCDEFGH Total Size = 8, Number of Objects = 3
[Code sample - Object] struct sampleobj { int num; char str[10]; }; Q_OBSTACK *obstack; int i; // sample object struct sampleobj obj; struct sampleobj *final; // get new obstack obstack = qObstackInit(); // stack for(i = 0; i < 3; i++) { // filling object with sample data obj.num = i; sprintf(obj.str, "hello%d", i); // stack qObstackGrow(obstack, (void *)&obj, sizeof(struct sampleobj)); } // final final = (struct sampleobj *)qObstackFinish(obstack); // print out qContentType("text/plain"); for(i = 0; i < qObstackGetNum(obstack); i++) { printf("Object%d final = %d, %sn", i+1, final[i].num, final[i].str); } printf("Total Size = %d, Number of Objects = %dn", qObstackGetSize(obstack), qObstackGetNum(obstack)); qObstackFree(obstack); [Result] Object1 final = 0, hello0 Object2 final = 1, hello1 Object3 final = 2, hello2 Total Size = 48, Number of Objects = 3
Q_OBSTACK* qObstackInit | ( | void | ) |
Initialize object-stack.
// allocate memory Q_OBSTACK *obstack = qObstackInit(); qObstackFree(obstack);
bool qObstackGrow | ( | Q_OBSTACK * | obstack, | |
const void * | object, | |||
size_t | size | |||
) |
Stack object.
obstack | a pointer of Q_OBSTACK | |
object | a pointer of object data | |
size | size of object |
bool qObstackGrowStr | ( | Q_OBSTACK * | obstack, | |
const char * | str | |||
) |
Stack string.
obstack | a pointer of Q_OBSTACK | |
str | a pointer of string |
bool qObstackGrowStrf | ( | Q_OBSTACK * | obstack, | |
const char * | format, | |||
… | ||||
) |
Stack formatted string.
obstack | a pointer of Q_OBSTACK | |
format | string format |
void* qObstackFinish | ( | Q_OBSTACK * | obstack | ) |
Stack formatted string.
obstack | a pointer of Q_OBSTACK | |
format | string format |
void* qObstackGetFinal | ( | Q_OBSTACK * | obstack | ) |
Finalize objects and get merged single final object pointer.
obstack | a pointer of Q_OBSTACK |
size_t qObstackGetSize | ( | Q_OBSTACK * | obstack | ) |
Get stacked objects size.
obstack | a pointer of Q_OBSTACK |
int qObstackGetNum | ( | Q_OBSTACK * | obstack | ) |
Under-development.
bool qObstackFree | ( | Q_OBSTACK * | obstack | ) |
Under-development.
[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference] |