~ubuntu-branches/ubuntu/warty/swig1.3/warty

« back to all changes in this revision

Viewing changes to Source/DOH/Include/dohobj.h

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

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