109#include "qinternal.h"
110#include "containers/qstack.h"
130 qstack_t *stack = (qstack_t *) malloc(
sizeof(qstack_t));
136 memset((
void *) stack, 0,
sizeof(qstack_t));
137 stack->list =
qlist(options);
138 if (stack->list == NULL) {
178 return stack->list->setsize(stack->list, max);
196 return stack->list->addfirst(stack->list, data, size);
218 return stack->list->addfirst(stack->list, str, strlen(str) + 1);
234 return stack->list->addfirst(stack->list, &num,
sizeof(num));
250 return stack->list->popfirst(stack->list, size);
269 char *str = stack->list->popfirst(stack->list, &strsize);
271 str[strsize - 1] =
'\0';
293 int64_t *pnum = stack->list->popfirst(stack->list, NULL);
321 return stack->list->popat(stack->list, index, size);
337void *
qstack_get(qstack_t *stack,
size_t *size,
bool newmem) {
338 return stack->list->getfirst(stack->list, size, newmem);
357 char *str = stack->list->getfirst(stack->list, &strsize,
true);
359 str[strsize - 1] =
'\0';
381 int64_t *pnum = stack->list->getfirst(stack->list, NULL,
true);
409void *
qstack_getat(qstack_t *stack,
int index,
size_t *size,
bool newmem) {
410 return stack->list->getat(stack->list, index, size, newmem);
421 return stack->list->size(stack->list);
430 stack->list->clear(stack->list);
442 return stack->list->debug(stack->list, out);
453 stack->list->free(stack->list);
qlist_t * qlist(int options)
Create new qlist_t linked-list container.
void * qstack_popat(qstack_t *stack, int index, size_t *size)
qstack->popat(): Returns and remove the element at the specified position in this stack.
void qstack_clear(qstack_t *stack)
qstack->clear(): Removes all of the elements from this stack.
bool qstack_pushint(qstack_t *stack, int64_t num)
qstack->pushint(): Pushes a integer onto the top of this stack.
size_t qstack_setsize(qstack_t *stack, size_t max)
qstack->setsize(): Sets maximum number of elements allowed in this stack.
void qstack_free(qstack_t *stack)
qstack->free(): Free qstack_t
int64_t qstack_popint(qstack_t *stack)
qstack->popint(): Removes a integer at the top of this stack and returns that element.
bool qstack_pushstr(qstack_t *stack, const char *str)
qstack->pushstr(): Pushes a string onto the top of this stack.
size_t qstack_size(qstack_t *stack)
qstack->size(): Returns the number of elements in this stack.
qstack_t * qstack(int options)
Create a new stack container.
void * qstack_pop(qstack_t *stack, size_t *size)
qstack->pop(): Removes a element at the top of this stack and returns that element.
void * qstack_get(qstack_t *stack, size_t *size, bool newmem)
qstack->get(): Returns an element at the top of this stack without removing it.
char * qstack_getstr(qstack_t *stack)
qstack->getstr(): Returns an string at the top of this stack without removing it.
void * qstack_getat(qstack_t *stack, int index, size_t *size, bool newmem)
qstack->getat(): Returns an element at the specified position in this stack without removing it.
char * qstack_popstr(qstack_t *stack)
qstack->popstr(): Removes a element at the top of this stack and returns that element.
int64_t qstack_getint(qstack_t *stack)
qstack->getint(): Returns an integer at the top of this stack without removing it.
bool qstack_debug(qstack_t *stack, FILE *out)
qstack->debug(): Print out stored elements for debugging purpose.
bool qstack_push(qstack_t *stack, const void *data, size_t size)
qstack->push(): Pushes an element onto the top of this stack.