typedstream.h
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:4k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. /* GNU Objective-C Typed Streams interface.
  2.    Copyright (C) 1993, 1995 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU CC is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  11. License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU CC; see the file COPYING.  If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.  */
  16. /* As a special exception, if you link this library with files compiled
  17.    with GCC to produce an executable, this does not cause the resulting
  18.    executable to be covered by the GNU General Public License.  This
  19.    exception does not however invalidate any other reasons why the
  20.    executable file might be covered by the GNU General Public License. */
  21. #ifndef __typedstream_INCLUDE_GNU
  22. #define __typedstream_INCLUDE_GNU
  23. #include "objc/objc.h"
  24. #include "objc/hash.h"
  25. #include <stdio.h>
  26. typedef int (*objc_typed_read_func)(void*, char*, int);
  27. typedef int (*objc_typed_write_func)(void*, const char*, int);
  28. typedef int (*objc_typed_flush_func)(void*);
  29. typedef int (*objc_typed_eof_func)(void*);
  30. #define OBJC_READONLY   0x01
  31. #define OBJC_WRITEONLY  0x02
  32. #define OBJC_MANAGED_STREAM  0x01
  33. #define OBJC_FILE_STREAM     0x02
  34. #define OBJC_MEMORY_STREAM   0x04
  35. #define OBJC_TYPED_STREAM_VERSION 0x01
  36. typedef struct objc_typed_stream {
  37.   void* physical;
  38.   cache_ptr object_table; /* read/written objects */
  39.   cache_ptr stream_table; /* other read/written but shared things.. */
  40.   cache_ptr class_table; /* class version mapping */
  41.   cache_ptr object_refs; /* forward references */
  42.   int mode; /* OBJC_READONLY or OBJC_WRITEONLY */
  43.   int type; /* MANAGED, FILE, MEMORY etc bit string */
  44.   int version; /* version used when writing */
  45.   int writing_root_p;
  46.   objc_typed_read_func read;
  47.   objc_typed_write_func write;
  48.   objc_typed_eof_func eof;
  49.   objc_typed_flush_func flush;
  50. } TypedStream;
  51. /* opcode masks */
  52. #define _B_VALUE   0x1fU
  53. #define _B_CODE    0xe0U
  54. #define _B_SIGN    0x10U
  55. #define _B_NUMBER  0x0fU
  56. /* standard opcodes */
  57. #define _B_INVALID 0x00U
  58. #define _B_SINT    0x20U
  59. #define _B_NINT    0x40U
  60. #define _B_SSTR    0x60U
  61. #define _B_NSTR    0x80U
  62. #define _B_RCOMM   0xa0U
  63. #define _B_UCOMM   0xc0U
  64. #define _B_EXT     0xe0U
  65. /* eXtension opcodes */
  66. #define _BX_OBJECT  0x00U
  67. #define _BX_CLASS   0x01U
  68. #define _BX_SEL     0x02U
  69. #define _BX_OBJREF  0x03U
  70. #define _BX_OBJROOT 0x04U
  71. #define _BX_EXT     0x1fU
  72. /*
  73. ** Read and write objects as specified by TYPE.  All the `last'
  74. ** arguments are pointers to the objects to read/write.  
  75. */
  76. int objc_write_type (TypedStream* stream, const char* type, const void* data);
  77. int objc_read_type (TypedStream* stream, const char* type, void* data);
  78. int objc_write_types (TypedStream* stream, const char* type, ...);
  79. int objc_read_types (TypedStream* stream, const char* type, ...);
  80. int objc_write_object_reference (TypedStream* stream, id object);
  81. int objc_write_root_object (TypedStream* stream, id object);
  82. long objc_get_stream_class_version (TypedStream* stream, Class class);
  83. /*
  84. ** Convenience functions
  85. */
  86. int objc_write_array (TypedStream* stream, const char* type,
  87.       int count, const void* data);
  88. int objc_read_array (TypedStream* stream, const char* type,
  89.      int count, void* data);
  90. int objc_write_object (TypedStream* stream, id object);
  91. int objc_read_object (TypedStream* stream, id* object);
  92. /*
  93. ** Open a typed stream for reading or writing.  MODE may be either of
  94. ** OBJC_READONLY or OBJC_WRITEONLY.  
  95. */
  96. TypedStream* objc_open_typed_stream (FILE* physical, int mode);
  97. TypedStream* objc_open_typed_stream_for_file (const char* file_name, int mode);
  98. void objc_close_typed_stream (TypedStream* stream);
  99. BOOL objc_end_of_typed_stream (TypedStream* stream);
  100. void objc_flush_typed_stream (TypedStream* stream);
  101. #endif /* not __typedstream_INCLUDE_GNU */