/tags/rel-1-3-25/SWIG/Source/DOH/dohint.h
C++ Header | 135 lines | 80 code | 28 blank | 27 comment | 2 complexity | 2b29c632acd59302a7b51bbf49442229 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1 2/* ----------------------------------------------------------------------------- 3 * dohint.h 4 * 5 * This file describes internally managed objects. 6 * 7 * Author(s) : David Beazley (beazley@cs.uchicago.edu) 8 * 9 * Copyright (C) 1999-2000. The University of Chicago 10 * See the file LICENSE for information on usage and redistribution. 11 * 12 * $Header$ 13 * ----------------------------------------------------------------------------- */ 14 15#ifndef _DOHINT_H 16#define _DOHINT_H 17 18#include <stdlib.h> 19#include <stdio.h> 20#include <string.h> 21#include <assert.h> 22#include <ctype.h> 23#include <stdarg.h> 24 25#include "doh.h" 26 27/* Hash objects */ 28typedef struct { 29 DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */ 30 int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */ 31 int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */ 32 DOH *(*doh_keys)(DOH *obj); /* All keys as a list */ 33} DohHashMethods; 34 35/* List objects */ 36typedef struct { 37 DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */ 38 int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */ 39 int (*doh_delitem)(DOH *obj, int index); /* Delete item */ 40 int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */ 41 int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */ 42} DohListMethods; 43 44/* File methods */ 45typedef struct { 46 int (*doh_read)(DOH *obj, void *buffer, int nbytes); /* Read bytes */ 47 int (*doh_write)(DOH *obj, void *buffer, int nbytes); /* Write bytes */ 48 int (*doh_putc)(DOH *obj, int ch); /* Put character */ 49 int (*doh_getc)(DOH *obj); /* Get character */ 50 int (*doh_ungetc)(DOH *obj, int ch); /* Unget character */ 51 int (*doh_seek)(DOH *obj, long offset, int whence); /* Seek */ 52 long (*doh_tell)(DOH *obj); /* Tell */ 53 int (*doh_close)(DOH *obj); /* Close */ 54} DohFileMethods; 55 56/* String methods */ 57typedef struct { 58 int (*doh_replace)(DOH *obj, DOH *old, DOH *rep, int flags); 59 void (*doh_chop)(DOH *obj); 60} DohStringMethods; 61 62/* ----------------------------------------------------------------------------- 63 * DohObjInfo 64 * ----------------------------------------------------------------------------- */ 65 66typedef struct DohObjInfo { 67 char *objname; /* Object name */ 68 69 /* Basic object methods */ 70 void (*doh_del)(DOH *obj); /* Delete object */ 71 DOH *(*doh_copy)(DOH *obj); /* Copy and object */ 72 void (*doh_clear)(DOH *obj); /* Clear an object */ 73 74 /* I/O methods */ 75 DOH *(*doh_str)(DOH *obj); /* Make a full string */ 76 void *(*doh_data)(DOH *obj); /* Return raw data */ 77 int (*doh_dump)(DOH *obj, DOH *out); /* Serialize on out */ 78 79 /* Length and hash values */ 80 int (*doh_len)(DOH *obj); 81 int (*doh_hashval)(DOH *obj); 82 83 /* Compare */ 84 int (*doh_cmp)(DOH *obj1, DOH *obj2); 85 86 /* Iterators */ 87 DohIterator (*doh_first)(DOH *obj); 88 DohIterator (*doh_next)(DohIterator ); 89 90 /* Positional */ 91 void (*doh_setfile)(DOH *obj, DOHString_or_char *file); 92 DOH *(*doh_getfile)(DOH *obj); 93 void (*doh_setline)(DOH *obj, int line); 94 int (*doh_getline)(DOH *obj); 95 96 DohHashMethods *doh_hash; /* Hash methods */ 97 DohListMethods *doh_list; /* List methods */ 98 DohFileMethods *doh_file; /* File methods */ 99 DohStringMethods *doh_string; /* String methods */ 100 void *doh_reserved; /* Reserved */ 101 void *clientdata; /* User data */ 102} DohObjInfo; 103 104typedef struct { 105 void *data; /* Data pointer */ 106 DohObjInfo *type; 107 void *meta; /* Meta data */ 108 unsigned int flag_intern : 1; /* Interned object */ 109 unsigned int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */ 110 unsigned int flag_user : 1; /* User flag */ 111 unsigned int flag_usermark : 1; /* User marked */ 112 unsigned int refcount : 28; /* Reference count (max 16 million) */ 113} DohBase; 114 115/* Macros for decrefing and increfing (safe for null objects). */ 116 117#define Decref(a) if (a) ((DohBase *) a)->refcount-- 118#define Incref(a) if (a) ((DohBase *) a)->refcount++ 119#define Refcount(a) ((DohBase *) a)->refcount 120 121/* Macros for manipulating objects in a safe manner */ 122#define ObjData(a) ((DohBase *)a)->data 123#define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x 124#define ObjGetMark(a) ((DohBase *)a)->flag_marked 125#define ObjType(a) ((DohBase *)a)->type 126 127extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */ 128extern void DohObjFree(DOH *ptr); /* Free a DOH object */ 129 130#endif /* DOHINT_H */ 131 132 133 134 135