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