PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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. * dohint.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$
  12. * ----------------------------------------------------------------------------- */
  13. #ifndef _DOHINT_H
  14. #define _DOHINT_H
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <assert.h>
  19. #include <ctype.h>
  20. #include <stdarg.h>
  21. #include "doh.h"
  22. /* Hash objects */
  23. typedef struct {
  24. DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */
  25. int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */
  26. int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */
  27. DOH *(*doh_keys)(DOH *obj); /* All keys as a list */
  28. } DohHashMethods;
  29. /* List objects */
  30. typedef struct {
  31. DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */
  32. int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */
  33. int (*doh_delitem)(DOH *obj, int index); /* Delete item */
  34. int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
  35. int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */
  36. } DohListMethods;
  37. /* File methods */
  38. typedef struct {
  39. int (*doh_read)(DOH *obj, void *buffer, int nbytes); /* Read bytes */
  40. int (*doh_write)(DOH *obj, void *buffer, int nbytes); /* Write bytes */
  41. int (*doh_putc)(DOH *obj, int ch); /* Put character */
  42. int (*doh_getc)(DOH *obj); /* Get character */
  43. int (*doh_ungetc)(DOH *obj, int ch); /* Unget character */
  44. int (*doh_seek)(DOH *obj, long offset, int whence); /* Seek */
  45. long (*doh_tell)(DOH *obj); /* Tell */
  46. int (*doh_close)(DOH *obj); /* Close */
  47. } DohFileMethods;
  48. /* String methods */
  49. typedef struct {
  50. int (*doh_replace)(DOH *obj, DOH *old, DOH *rep, int flags);
  51. void (*doh_chop)(DOH *obj);
  52. } DohStringMethods;
  53. /* -----------------------------------------------------------------------------
  54. * DohObjInfo
  55. * ----------------------------------------------------------------------------- */
  56. typedef struct DohObjInfo {
  57. char *objname; /* Object name */
  58. /* Basic object methods */
  59. void (*doh_del)(DOH *obj); /* Delete object */
  60. DOH *(*doh_copy)(DOH *obj); /* Copy and object */
  61. void (*doh_clear)(DOH *obj); /* Clear an object */
  62. /* I/O methods */
  63. DOH *(*doh_str)(DOH *obj); /* Make a full string */
  64. void *(*doh_data)(DOH *obj); /* Return raw data */
  65. int (*doh_dump)(DOH *obj, DOH *out); /* Serialize on out */
  66. /* Length and hash values */
  67. int (*doh_len)(DOH *obj);
  68. int (*doh_hashval)(DOH *obj);
  69. /* Compare */
  70. int (*doh_cmp)(DOH *obj1, DOH *obj2);
  71. /* Iterators */
  72. DohIterator (*doh_first)(DOH *obj);
  73. DohIterator (*doh_next)(DohIterator );
  74. /* Positional */
  75. void (*doh_setfile)(DOH *obj, DOHString_or_char *file);
  76. DOH *(*doh_getfile)(DOH *obj);
  77. void (*doh_setline)(DOH *obj, int line);
  78. int (*doh_getline)(DOH *obj);
  79. DohHashMethods *doh_hash; /* Hash methods */
  80. DohListMethods *doh_list; /* List methods */
  81. DohFileMethods *doh_file; /* File methods */
  82. DohStringMethods *doh_string; /* String methods */
  83. void *doh_reserved; /* Reserved */
  84. void *clientdata; /* User data */
  85. } DohObjInfo;
  86. typedef struct {
  87. void *data; /* Data pointer */
  88. DohObjInfo *type;
  89. void *meta; /* Meta data */
  90. unsigned int flag_intern : 1; /* Interned object */
  91. unsigned int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */
  92. unsigned int flag_user : 1; /* User flag */
  93. unsigned int flag_usermark : 1; /* User marked */
  94. unsigned int refcount : 28; /* Reference count (max 16 million) */
  95. } DohBase;
  96. /* Macros for decrefing and increfing (safe for null objects). */
  97. #define Decref(a) if (a) ((DohBase *) a)->refcount--
  98. #define Incref(a) if (a) ((DohBase *) a)->refcount++
  99. #define Refcount(a) ((DohBase *) a)->refcount
  100. /* Macros for manipulating objects in a safe manner */
  101. #define ObjData(a) ((DohBase *)a)->data
  102. #define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x
  103. #define ObjGetMark(a) ((DohBase *)a)->flag_marked
  104. #define ObjType(a) ((DohBase *)a)->type
  105. extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
  106. extern void DohObjFree(DOH *ptr); /* Free a DOH object */
  107. #endif /* DOHINT_H */