~ubuntu-branches/ubuntu/karmic/gnustep-base/karmic

« back to all changes in this revision

Viewing changes to Headers/Foundation/NSCoder.h

  • Committer: Bazaar Package Importer
  • Author(s): Eric Heintzmann
  • Date: 2005-04-17 00:14:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050417001438-enf0y07c9tku85z1
Tags: 1.10.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Interface for NSCoder for GNUStep
 
2
   Copyright (C) 1995, 1996 Free Software Foundation, Inc.
 
3
 
 
4
   Written by:  Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
 
5
   Date: 1995
 
6
   
 
7
   This file is part of the GNUstep Base Library.
 
8
   
 
9
   This library is free software; you can redistribute it and/or
 
10
   modify it under the terms of the GNU Library General Public
 
11
   License as published by the Free Software Foundation; either
 
12
   version 2 of the License, or (at your option) any later version.
 
13
   
 
14
   This library is distributed in the hope that it will be useful,
 
15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
   Library General Public License for more details.
 
18
   
 
19
   You should have received a copy of the GNU Library General Public
 
20
   License along with this library; if not, write to the Free
 
21
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
 
22
   */ 
 
23
 
 
24
#ifndef __NSCoder_h_GNUSTEP_BASE_INCLUDE
 
25
#define __NSCoder_h_GNUSTEP_BASE_INCLUDE
 
26
 
 
27
#include <Foundation/NSObject.h>
 
28
#include <Foundation/NSGeometry.h>
 
29
#include <Foundation/NSZone.h>
 
30
 
 
31
@class NSMutableData, NSData, NSString;
 
32
 
 
33
/**
 
34
 *  <p>Top-level class defining methods for use when archiving (encoding)
 
35
 *  objects to a byte array or file, and when restoring (decoding) objects.
 
36
 *  Generally only subclasses of this class are used directly - [NSArchiver],
 
37
 *  [NSUnarchiver], [NSKeyedArchiver], [NSKeyedUnarchiver], or [NSPortCoder].
 
38
 *  </p>
 
39
 *  <p><code>NSPortCoder</code> is used within the distributed objects
 
40
 *  framework.  For archiving to/from disk, the <em>Keyed...</em> classes are
 
41
 *  preferred for new implementations, since they provide greater
 
42
 *  forward/backward compatibility in the face of class changes.</p>
 
43
 */
 
44
@interface NSCoder : NSObject
 
45
// Encoding Data
 
46
 
 
47
/**
 
48
 *  Encodes array of count structures or objects of given type, which may be
 
49
 *  obtained through the '<code>@encode(...)</code>' compile-time operator.
 
50
 *  Usually this is used for primitives though it can be used for objects as
 
51
 *  well.
 
52
 */
 
53
- (void) encodeArrayOfObjCType: (const char*)type
 
54
                         count: (unsigned)count
 
55
                            at: (const void*)array;
 
56
 
 
57
/**
 
58
 *  Can be ignored.
 
59
 */
 
60
- (void) encodeBycopyObject: (id)anObject;
 
61
/**
 
62
 *  Can be ignored.
 
63
 */
 
64
- (void) encodeByrefObject: (id)anObject;
 
65
 
 
66
/**
 
67
 *  Stores bytes directly into archive.  
 
68
 */
 
69
- (void) encodeBytes: (void*)d length: (unsigned)l;
 
70
 
 
71
/**
 
72
 *  Encode object if it is/will be encoded unconditionally by this coder,
 
73
 *  otherwise store a nil.
 
74
 */
 
75
- (void) encodeConditionalObject: (id)anObject;
 
76
 
 
77
/**
 
78
 *  Encode an instance of [NSData].
 
79
 */
 
80
- (void) encodeDataObject: (NSData*)data;
 
81
 
 
82
/**
 
83
 *  Encodes a generic object.  This will usually result in an
 
84
 *  [(NSCoding)-encodeWithCoder:] message being sent to anObject so it
 
85
 *  can encode itself.
 
86
 */
 
87
- (void) encodeObject: (id)anObject;
 
88
 
 
89
/**
 
90
 *  Encodes a property list by calling [NSSerializer -serializePropertyList:],
 
91
 *  then encoding the resulting [NSData] object.
 
92
 */
 
93
- (void) encodePropertyList: (id)plist;
 
94
 
 
95
/**
 
96
 *  Encodes a point structure.
 
97
 */
 
98
- (void) encodePoint: (NSPoint)point;
 
99
 
 
100
/**
 
101
 *  Encodes a rectangle structure.
 
102
 */
 
103
- (void) encodeRect: (NSRect)rect;
 
104
 
 
105
/**
 
106
 *  Store object and objects it refers to in archive (i.e., complete object
 
107
 *  graph).
 
108
 */
 
109
- (void) encodeRootObject: (id)rootObject;
 
110
 
 
111
/**
 
112
 *  Encodes a size structure.
 
113
 */
 
114
- (void) encodeSize: (NSSize)size;
 
115
 
 
116
/**
 
117
 *  Encodes structure or object of given type, which may be obtained
 
118
 *  through the '<code>@encode(...)</code>' compile-time operator.  Usually
 
119
 *  this is used for primitives though it can be used for objects as well.
 
120
 */
 
121
- (void) encodeValueOfObjCType: (const char*)type
 
122
                            at: (const void*)address;
 
123
 
 
124
/**
 
125
 *  Multiple version of [-encodeValueOfObjCType:at:].
 
126
 */
 
127
- (void) encodeValuesOfObjCTypes: (const char*)types,...;
 
128
 
 
129
// Decoding Data
 
130
 
 
131
/**
 
132
 *  Decodes array of count structures or objects of given type, which may be
 
133
 *  obtained through the '<code>@encode(...)</code>' compile-time operator.
 
134
 *  Usually this is used for primitives though it can be used for objects as
 
135
 *  well.  Objects will be retained and you must release them.
 
136
 */
 
137
- (void) decodeArrayOfObjCType: (const char*)type
 
138
                         count: (unsigned)count
 
139
                            at: (void*)address;
 
140
 
 
141
/**
 
142
 *  Retrieve bytes directly from archive.
 
143
 */
 
144
- (void*) decodeBytesWithReturnedLength: (unsigned*)l;
 
145
 
 
146
/**
 
147
 *  Decode an instance of [NSData].
 
148
 */
 
149
- (NSData*) decodeDataObject;
 
150
 
 
151
/**
 
152
 *  Decodes a generic object.  Usually the class will be read from the
 
153
 *  archive, an object will be created through an <code>alloc</code> call,
 
154
 *  then that class will be sent an [(NSCoding)-initWithCoder:] message.
 
155
 */
 
156
- (id) decodeObject;
 
157
 
 
158
/**
 
159
 *  Decodes a property list from the archive previously stored through a call
 
160
 *  to [-encodePropertyList:].
 
161
 */
 
162
- (id) decodePropertyList;
 
163
 
 
164
/**
 
165
 *  Decodes a point structure.
 
166
 */
 
167
- (NSPoint) decodePoint;
 
168
 
 
169
/**
 
170
 *  Decodes a rectangle structure.
 
171
 */
 
172
- (NSRect) decodeRect;
 
173
 
 
174
/**
 
175
 *  Decodes a size structure.
 
176
 */
 
177
- (NSSize) decodeSize;
 
178
 
 
179
/**
 
180
 *  Decodes structure or object of given type, which may be obtained
 
181
 *  through the '<code>@encode(...)</code>' compile-time operator.  Usually
 
182
 *  this is used for primitives though it can be used for objects as well,
 
183
 *  in which case you are responsible for releasing them.
 
184
 */
 
185
- (void) decodeValueOfObjCType: (const char*)type
 
186
                            at: (void*)address;
 
187
 
 
188
/**
 
189
 *  Multiple version of [-decodeValueOfObjCType:at:].
 
190
 */
 
191
- (void) decodeValuesOfObjCTypes: (const char*)types,...;
 
192
 
 
193
// Managing Zones
 
194
 
 
195
/**
 
196
 *  Returns zone being used to allocate memory for decoded objects.
 
197
 */
 
198
- (NSZone*) objectZone;
 
199
 
 
200
/**
 
201
 *  Sets zone to use for allocating memory for decoded objects.
 
202
 */
 
203
- (void) setObjectZone: (NSZone*)zone;
 
204
 
 
205
// Getting a Version
 
206
 
 
207
/**
 
208
 *  Returns *Step version, which is not the release version, but a large number,
 
209
 *  by specification &lt;1000 for pre-OpenStep.  This implementation returns
 
210
 *  a number based on the GNUstep major, minor, and subminor versions.
 
211
 */
 
212
- (unsigned int) systemVersion;
 
213
 
 
214
/**
 
215
 *  Returns current version of class (when encoding) or version of decoded
 
216
 *  class (decoded).  Version comes from [NSObject -getVersion].
 
217
 *  
 
218
 */
 
219
- (unsigned int) versionForClassName: (NSString*)className;
 
220
 
 
221
#ifndef STRICT_OPENSTEP
 
222
/*
 
223
 * Include GSConfig.h for typedefs/defines of uint8_t, int32_t int64_t
 
224
 */
 
225
#include <GSConfig.h>
 
226
 
 
227
 
 
228
/** <override-subclass />
 
229
 * Returns a flag indicating whether the receiver supported keyed coding.
 
230
 * the default implementation returns NO.  Subclasses supporting keyed
 
231
 * coding must override this to return YES.
 
232
 */
 
233
- (BOOL) allowsKeyedCoding;
 
234
 
 
235
/** <override-subclass />
 
236
 * Returns a class indicating whether an encoded value corresponding
 
237
 * to aKey exists.
 
238
 */
 
239
- (BOOL) containsValueForKey: (NSString*)aKey;
 
240
 
 
241
/** <override-subclass />
 
242
 * Returns a boolean value associated with aKey.  This value must previously
 
243
 * have been encoded using -encodeBool:forKey:
 
244
 */
 
245
- (BOOL) decodeBoolForKey: (NSString*)aKey;
 
246
 
 
247
/** <override-subclass />
 
248
 * Returns a pointer to a byte array associated with aKey.<br />
 
249
 * Returns the length of the data in aLength.<br />
 
250
 * This value must previously have been encoded using
 
251
 * -encodeBytes:length:forKey:
 
252
 */
 
253
- (const uint8_t*) decodeBytesForKey: (NSString*)aKey
 
254
                      returnedLength: (unsigned*)alength;
 
255
 
 
256
/** <override-subclass />
 
257
 * Returns a double value associated with aKey.  This value must previously
 
258
 * have been encoded using -encodeDouble:forKey: or -encodeFloat:forKey:
 
259
 */
 
260
- (double) decodeDoubleForKey: (NSString*)aKey;
 
261
 
 
262
/** <override-subclass />
 
263
 * Returns a float value associated with aKey.  This value must previously
 
264
 * have been encoded using -encodeFloat:forKey: or -encodeDouble:forKey:<br />
 
265
 * Precision may be lost (or an exception raised if the value will not fit
 
266
 * in a float) if the value was encoded using -encodeDouble:forKey:,
 
267
 */
 
268
- (float) decodeFloatForKey: (NSString*)aKey;
 
269
 
 
270
/** <override-subclass />
 
271
 * Returns an integer value associated with aKey.  This value must previously
 
272
 * have been encoded using -encodeInt:forKey:, -encodeInt32:forKey:, or
 
273
 * -encodeInt64:forKey:.<br />
 
274
 * An exception will be raised if the value does not fit in an integer.
 
275
 */
 
276
- (int) decodeIntForKey: (NSString*)aKey;
 
277
 
 
278
/** <override-subclass />
 
279
 * Returns a 32-bit integer value associated with aKey.  This value must
 
280
 * previously have been encoded using -encodeInt:forKey:,
 
281
 * -encodeInt32:forKey:, or -encodeInt64:forKey:.<br />
 
282
 * An exception will be raised if the value does not fit in a 32-bit integer.
 
283
 */
 
284
- (int32_t) decodeInt32ForKey: (NSString*)aKey;
 
285
 
 
286
/** <override-subclass />
 
287
 * Returns a 64-bit integer value associated with aKey.  This value must
 
288
 * previously have been encoded using -encodeInt:forKey:,
 
289
 * -encodeInt32:forKey:, or -encodeInt64:forKey:.
 
290
 */
 
291
- (int64_t) decodeInt64ForKey: (NSString*)aKey;
 
292
 
 
293
/** <override-subclass />
 
294
 * Returns an object value associated with aKey.  This value must
 
295
 * previously have been encoded using -encodeObject:forKey: or
 
296
 * -encodeConditionalObject:forKey:
 
297
 */
 
298
- (id) decodeObjectForKey: (NSString*)aKey;
 
299
 
 
300
/** <override-subclass />
 
301
 * Encodes aBool and associates the encoded value with aKey.
 
302
 */
 
303
- (void) encodeBool: (BOOL) aBool forKey: (NSString*)aKey;
 
304
 
 
305
/** <override-subclass />
 
306
 * Encodes the data of the specified length and pointed to by aPointer,
 
307
 * and associates the encoded value with aKey.
 
308
 */
 
309
- (void) encodeBytes: (const uint8_t*)aPointer
 
310
              length: (unsigned)length
 
311
              forKey: (NSString*)aKey;
 
312
 
 
313
/** <override-subclass />
 
314
 * Encodes anObject and associates the encoded value with aKey, but only
 
315
 * if anObject has already been encoded using -encodeObject:forKey:
 
316
 */
 
317
- (void) encodeConditionalObject: (id)anObject forKey: (NSString*)aKey;
 
318
 
 
319
/** <override-subclass />
 
320
 * Encodes aDouble and associates the encoded value with aKey.
 
321
 */
 
322
- (void) encodeDouble: (double)aDouble forKey: (NSString*)aKey;
 
323
 
 
324
/** <override-subclass />
 
325
 * Encodes aFloat and associates the encoded value with aKey.
 
326
 */
 
327
- (void) encodeFloat: (float)aFloat forKey: (NSString*)aKey;
 
328
 
 
329
/** <override-subclass />
 
330
 * Encodes anInteger and associates the encoded value with aKey.
 
331
 */
 
332
- (void) encodeInt: (int)anInteger forKey: (NSString*)aKey;
 
333
 
 
334
/** <override-subclass />
 
335
 * Encodes anInteger and associates the encoded value with aKey.
 
336
 */
 
337
- (void) encodeInt32: (int32_t)anInteger forKey: (NSString*)aKey;
 
338
 
 
339
/** <override-subclass />
 
340
 * Encodes anInteger and associates the encoded value with aKey.
 
341
 */
 
342
- (void) encodeInt64: (int64_t)anInteger forKey: (NSString*)aKey;
 
343
 
 
344
/** <override-subclass />
 
345
 * Encodes anObject and associates the encoded value with aKey.
 
346
 */
 
347
- (void) encodeObject: (id)anObject forKey: (NSString*)aKey;
 
348
#endif
 
349
@end
 
350
 
 
351
#ifndef NO_GNUSTEP
 
352
 
 
353
/**
 
354
 *  GNUstep extensions to [NSCoder], supporting compatibility with libObjects.
 
355
 */
 
356
@interface NSCoder (GNUstep)
 
357
/* Compatibility with libObjects */
 
358
- (void) decodeArrayOfObjCType: (const char*)type
 
359
                         count: (unsigned)count
 
360
                            at: (void*)buf
 
361
                      withName: (id*)name;
 
362
- (void) decodeIndent;
 
363
- (void) decodeObjectAt: (id*)anObject
 
364
               withName: (id*)name;
 
365
- (void) decodeValueOfCType: (const char*)type
 
366
                         at: (void*)buf
 
367
                   withName: (id*)name;
 
368
- (void) decodeValueOfObjCType: (const char*)type
 
369
                            at: (void*)buf
 
370
                      withName: (id*)name;
 
371
- (void) encodeArrayOfObjCType: (const char*)type
 
372
                         count: (unsigned)count
 
373
                            at: (const void*)buf
 
374
                      withName: (id)name;
 
375
- (void) encodeIndent;
 
376
- (void) encodeObjectAt: (id*)anObject
 
377
               withName: (id)name;
 
378
- (void) encodeValueOfCType: (const char*)type
 
379
                         at: (const void*)buf
 
380
                   withName: (id)name;
 
381
- (void) encodeValueOfObjCType: (const char*)type
 
382
                            at: (const void*)buf
 
383
                      withName: (id)name;
 
384
@end
 
385
 
 
386
#endif /* NO_GNUSTEP */
 
387
 
 
388
#endif  /* __NSCoder_h_GNUSTEP_BASE_INCLUDE */