varstring_xsb.h

00001 /* File:      varstring.h
00002 ** Author(s): kifer
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1999
00006 ** 
00007 ** XSB is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XSB; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: varstring_xsb.h,v 1.8 2005/07/07 18:59:43 dwarren Exp $
00022 ** 
00023 */
00024 
00025 
00026 #ifndef VARSTRING_INCLUDED
00027 #include "export.h"
00028 
00029 struct varstr;
00030 typedef struct varstr VarString;
00031 
00032 struct varstr_ops {
00033   void (*set)(VarString*,char*);       /* copy a char* to VarString; increase
00034                                           or shrink space, if needed        */ 
00035   void (*setv)(VarString*,VarString*); /* like set; 2nd arg is a VarString* */
00036   void (*append)(VarString*,char*);    /* append a char* to VarString;
00037                                           increase space, if needed         */
00038   void (*prepend)(VarString*,char*);   /* like append, but prepend instead  */
00039   void (*appendv)(VarString*,VarString*);  /* append 2nd VarString to 1st   */
00040   void (*appendc)(VarString*,char);    /* append char to VarString   */
00041   void (*prependv)(VarString*,VarString*); /* prepend 2nd VarString to 1st  */
00042   int  (*compare)(VarString*,VarString*);  /* like strcmp for VarStrings    */
00043   int  (*strcmp)(VarString*,char*);        /* compare VarString to a char*  */
00044 
00045   /* append block of N chars; don't NULL-terminate */
00046   void (*appendblk)(VarString*,char*,int); 
00047   /* append block of N chars; don't NULL-terminate */
00048   void (*prependblk)(VarString*,char*,int);
00049   void (*null_terminate)(VarString*);  /* Null-terminate VarString           */
00050   void (*ensure_size)(VarString*,int); /* Make sure size is at least N       */
00051   void (*shrink)(VarString*,int);      /* 2nd arg becomes the increment.
00052                                           Space shrinks to the minimum needed
00053                                           to accommodate existing data       */
00054   void  (*destroy)(VarString*);        /* release the space, uninitialize    */
00055 };
00056 
00057 
00058 
00059 /* All attributes are read-only;
00060    it is not recommended to refer to private attrs */
00061 struct varstr {
00062   /* PRIVATE */
00063   int   size;                  /* size of the allocated chunk                */
00064   int   increment;             /* increment by which to incr string size     */
00065   
00066   /* PUBLIC */
00067   int   length;                /* memory currently allocated for the string  */
00068   char  *string;               /* memory currently allocated for the string  */
00069 
00070   struct varstr_ops *op;       /* structure that defines valid VarString ops */
00071 };
00072 
00073 
00074 extern DllExport void call_conv varstring_init(VarString *vstr);
00075 extern DllExport void call_conv varstring_create(VarString **vstr);
00076 extern DllExport struct varstr_ops VarStrOps;
00077 
00078 /* calling sequence shortcuts; all expect a VarString pointer */
00079 #define XSB_StrSet(vstr,str)           (vstr)->op->set(vstr,str)
00080 #define XSB_StrSetV(vstr1,vstr2)       (vstr1)->op->setv(vstr1,vstr2)
00081 #define XSB_StrAppend(vstr,str)        (vstr)->op->append(vstr,str)
00082 #define XSB_StrPrepend(vstr,str)       (vstr)->op->prepend(vstr,str)
00083 #define XSB_StrAppendV(vstr1,vstr2)    (vstr1)->op->appendv(vstr1,vstr2)
00084 #define XSB_StrAppendC(vstr,code)      (vstr)->op->appendc(vstr,code)
00085 #define XSB_StrPrependV(vstr1,vstr2)   (vstr)->op->prependv(vstr1,vstr2)
00086 #define XSB_StrCompare(vstr1,vstr2)    (vstr1)->op->compare(vstr1,vstr2)
00087 #define XSB_StrCmp(vstr,str)           (vstr)->op->strcmp(vstr,str)
00088 #define XSB_StrAppendBlk(vstr,blk,sz)  (vstr)->op->appendblk(vstr,blk,sz)
00089 #define XSB_StrPrependBlk(vstr,blk,sz) (vstr)->op->prependblk(vstr,blk,sz)
00090 #define XSB_StrNullTerminate(vstr)     (vstr)->op->null_terminate(vstr)
00091 #define XSB_StrEnsureSize(vstr,size)   (vstr)->op->ensure_size(vstr,size)
00092 #define XSB_StrShrink(vstr,incr)       (vstr)->op->shrink(vstr,incr)
00093 /* destruction is necessary for automatic VarString's */
00094 #define XSB_StrDestroy(vstr)           (vstr)->op->destroy(vstr)
00095 
00096 
00097 /* XSB_StrDefine doesn't work in a DLL under Windows for some reason.
00098    Can't resolve VarStrOps. So, then use XSB_StrCreate() and XSB_StrInit()
00099 */
00100 #define XSB_StrDefine(vstr)          VarString vstr = {0,0,0,NULL,&VarStrOps}
00101 /* Allocates space vor VarString, assigns the pointer to vstr, then initializes
00102    the VarString */
00103 #define XSB_StrCreate(vstr)          varstring_create(vstr)
00104 /* Assumes vstr points to an uninitialized VarString. Initializes it. */
00105 #define XSB_StrInit(vstr)            varstring_init(vstr)
00106 
00107 
00108 #define VARSTRING_INCLUDED
00109 
00110 #endif

Generated on Wed Jul 26 13:30:43 2006 for XSB by  doxygen 1.4.5