base/libs/qdecoder/qObstack.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#include "qDecoder.h"

Include dependency graph for qObstack.c:

Go to the source code of this file.

FunctionsTitleTestFour

void * qObstackFinish (Q_OBSTACK *obstack)
bool qObstackFree (Q_OBSTACK *obstack)
void * qObstackGetFinal (Q_OBSTACK *obstack)
int qObstackGetNum (Q_OBSTACK *obstack)
size_t qObstackGetSize (Q_OBSTACK *obstack)
bool qObstackGrow (Q_OBSTACK *obstack, const void *object, size_t size)
bool qObstackGrowStr (Q_OBSTACK *obstack, const char *str)
bool qObstackGrowStrf (Q_OBSTACK *obstack, const char *format,...)
Q_OBSTACKqObstackInit (void)


Detailed Description

qDecoder implementation of GNU obstack

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 = %s\n", final);
   printf("Total Size = %d, Number of Objects = %d\n", 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, %s\n", i+1, final[i].num, final[i].str);
   }
   printf("Total Size = %d, Number of Objects = %d\n", 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

Definition in file qObstack.c.


Generated on Sun Apr 30 07:00:46 2017 for JSOC_Documentation by  doxygen 1.5.7.1