1 /* ----------------------------------------------------------------------------- 2 * This file is part of SWIG, which is licensed as a whole under version 3 3 * (or any later version) of the GNU General Public License. Some additional 4 * terms also apply to certain portions of SWIG. The full details of the SWIG 5 * license and copyrights can be found in the LICENSE and COPYRIGHT files 6 * included with the SWIG source code as distributed by the SWIG developers 7 * and at http://www.swig.org/legal.html. 8 * 9 * dohint.h 10 * 11 * This file describes internally managed objects. 12 * ----------------------------------------------------------------------------- */ 13 14 #ifndef _DOHINT_H 15 #define _DOHINT_H 16 17 #include "doh.h" 18 19 #include <stdlib.h> 20 #include <stdio.h> 21 #include <string.h> 22 #include <assert.h> 23 #include <ctype.h> 24 #include <stdarg.h> 25 26 /* Hash objects */ 27 typedef struct { 28 DOH *(*doh_getattr) (DOH *obj, DOH *name); /* Get attribute */ 29 int (*doh_setattr) (DOH *obj, DOH *name, DOH *value); /* Set attribute */ 30 int (*doh_delattr) (DOH *obj, DOH *name); /* Del attribute */ 31 DOH *(*doh_keys) (DOH *obj); /* All keys as a list */ 32 } DohHashMethods; 33 34 /* List objects */ 35 typedef struct { 36 DOH *(*doh_getitem) (DOH *obj, int index); /* Get item */ 37 int (*doh_setitem) (DOH *obj, int index, DOH *value); /* Set item */ 38 int (*doh_delitem) (DOH *obj, int index); /* Delete item */ 39 int (*doh_insitem) (DOH *obj, int index, DOH *value); /* Insert item */ 40 int (*doh_delslice) (DOH *obj, int sindex, int eindex); /* Delete slice */ 41 } DohListMethods; 42 43 /* File methods */ 44 typedef struct { 45 int (*doh_read) (DOH *obj, void *buffer, int nbytes); /* Read bytes */ 46 int (*doh_write) (DOH *obj, const void *buffer, int nbytes); /* Write bytes */ 47 int (*doh_putc) (DOH *obj, int ch); /* Put character */ 48 int (*doh_getc) (DOH *obj); /* Get character */ 49 int (*doh_ungetc) (DOH *obj, int ch); /* Unget character */ 50 int (*doh_seek) (DOH *obj, long offset, int whence); /* Seek */ 51 long (*doh_tell) (DOH *obj); /* Tell */ 52 } DohFileMethods; 53 54 /* String methods */ 55 typedef struct { 56 int (*doh_replace) (DOH *obj, const DOHString_or_char *old, const DOHString_or_char *rep, int flags); 57 void (*doh_chop) (DOH *obj); 58 } DohStringMethods; 59 60 /* ----------------------------------------------------------------------------- 61 * DohObjInfo 62 * ----------------------------------------------------------------------------- */ 63 64 typedef struct DohObjInfo { 65 const char *objname; /* Object name */ 66 67 /* Basic object methods */ 68 void (*doh_del) (DOH *obj); /* Delete object */ 69 DOH *(*doh_copy) (DOH *obj); /* Copy and object */ 70 void (*doh_clear) (DOH *obj); /* Clear an object */ 71 72 /* I/O methods */ 73 DOH *(*doh_str) (DOH *obj); /* Make a full string */ 74 void *(*doh_data) (DOH *obj); /* Return raw data */ 75 int (*doh_dump) (DOH *obj, DOH *out); /* Serialize on out */ 76 77 /* Length and hash values */ 78 int (*doh_len) (DOH *obj); 79 int (*doh_hashval) (DOH *obj); 80 81 /* Compare */ 82 int (*doh_cmp) (DOH *obj1, DOH *obj2); 83 84 /* Equal */ 85 int (*doh_equal) (DOH *obj1, DOH *obj2); 86 87 /* Iterators */ 88 DohIterator (*doh_first) (DOH *obj); 89 DohIterator (*doh_next) (DohIterator); 90 91 /* Positional */ 92 void (*doh_setfile) (DOH *obj, DOHString_or_char *file); 93 DOH *(*doh_getfile) (DOH *obj); 94 void (*doh_setline) (DOH *obj, int line); 95 int (*doh_getline) (DOH *obj); 96 97 DohHashMethods *doh_hash; /* Hash methods */ 98 DohListMethods *doh_list; /* List methods */ 99 DohFileMethods *doh_file; /* File methods */ 100 DohStringMethods *doh_string; /* String methods */ 101 void *doh_reserved; /* Reserved */ 102 void *clientdata; /* User data */ 103 } DohObjInfo; 104 105 typedef struct { 106 void *data; /* Data pointer */ 107 DohObjInfo *type; 108 void *meta; /* Meta data */ 109 unsigned int flag_intern:1; /* Interned object */ 110 unsigned int flag_marked:1; /* Mark flag. Used to avoid recursive loops in places */ 111 unsigned int flag_user:1; /* User flag */ 112 unsigned int flag_usermark:1; /* User marked */ 113 unsigned int refcount:28; /* Reference count (max 16 million) */ 114 } DohBase; 115 116 /* Macros for decrefing and increfing (safe for null objects). */ 117 118 #define Decref(a) if (a) ((DohBase *) a)->refcount-- 119 #define Incref(a) if (a) ((DohBase *) a)->refcount++ 120 #define Refcount(a) ((DohBase *) a)->refcount 121 122 /* Macros for manipulating objects in a safe manner */ 123 #define ObjData(a) ((DohBase *)a)->data 124 #define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x 125 #define ObjGetMark(a) ((DohBase *)a)->flag_marked 126 #define ObjType(a) ((DohBase *)a)->type 127 128 extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */ 129 extern void DohObjFree(DOH *ptr); /* Free a DOH object */ 130 131 #endif /* DOHINT_H */ 132