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

« back to all changes in this revision

Viewing changes to Headers/gnustep/base/NSObject.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 NSObject for GNUStep
2
 
   Copyright (C) 1995, 1996, 1998 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 __NSObject_h_GNUSTEP_BASE_INCLUDE
25
 
#define __NSObject_h_GNUSTEP_BASE_INCLUDE
26
 
 
27
 
/*
28
 
 *      Check consistency of definitions for system compatibility.
29
 
 */
30
 
#if     defined(STRICT_OPENSTEP)
31
 
#define NO_GNUSTEP      1
32
 
#elif   defined(STRICT_MACOS_X)
33
 
#define NO_GNUSTEP      1
34
 
#else
35
 
#undef  NO_GNUSTEP
36
 
#endif
37
 
 
38
 
#include <Foundation/NSObjCRuntime.h>
39
 
#include <base/preface.h>
40
 
#include <GSConfig.h>
41
 
#include <objc/objc.h>
42
 
#include <objc/Protocol.h>
43
 
#include <Foundation/NSZone.h>
44
 
 
45
 
@class NSArchiver;
46
 
@class NSArray;
47
 
@class NSCoder;
48
 
@class NSDictionary;
49
 
@class NSPortCoder;
50
 
@class NSMethodSignature;
51
 
@class NSMutableString;
52
 
@class NSRecursiveLock;
53
 
@class NSString;
54
 
@class NSInvocation;
55
 
@class Protocol;
56
 
 
57
 
@protocol NSObject
58
 
- (Class) class;
59
 
- (Class) superclass;
60
 
- (BOOL) isEqual: anObject;
61
 
- (BOOL) isKindOfClass: (Class)aClass;
62
 
- (BOOL) isMemberOfClass: (Class)aClass;
63
 
- (BOOL) isProxy;
64
 
- (unsigned) hash;
65
 
- self;
66
 
- performSelector: (SEL)aSelector;
67
 
- performSelector: (SEL)aSelector withObject: anObject;
68
 
- performSelector: (SEL)aSelector withObject: object1 withObject: object2;
69
 
- (BOOL) respondsToSelector: (SEL)aSelector;
70
 
- (BOOL) conformsToProtocol: (Protocol *)aProtocol;
71
 
- retain;
72
 
- autorelease;
73
 
- (oneway void) release;
74
 
- (unsigned) retainCount;
75
 
- (NSZone*) zone;
76
 
- (NSString*) description;
77
 
@end
78
 
 
79
 
@protocol NSCopying
80
 
- (id) copyWithZone: (NSZone *)zone;
81
 
@end
82
 
 
83
 
@protocol NSMutableCopying
84
 
- (id) mutableCopyWithZone: (NSZone *)zone;
85
 
@end
86
 
 
87
 
@protocol NSCoding
88
 
- (void) encodeWithCoder: (NSCoder*)aCoder;
89
 
- (id) initWithCoder: (NSCoder*)aDecoder;
90
 
@end
91
 
 
92
 
 
93
 
@interface NSObject <NSObject>
94
 
{
95
 
  Class isa;
96
 
}
97
 
 
98
 
#ifndef NO_GNUSTEP
99
 
#if     GS_WITH_GC
100
 
+ (BOOL) requiresTypedMemory;
101
 
#endif
102
 
#endif
103
 
+ (void) initialize;
104
 
+ (id) allocWithZone: (NSZone*)z;
105
 
+ (id) alloc;
106
 
+ (id) new;
107
 
- (id) copy;
108
 
- (void) dealloc;
109
 
- (id) init;
110
 
- (id) mutableCopy;
111
 
 
112
 
+ (Class) class;
113
 
+ (Class) superclass;
114
 
 
115
 
+ (BOOL) instancesRespondToSelector: (SEL)aSelector;
116
 
 
117
 
+ (IMP) instanceMethodForSelector: (SEL)aSelector;
118
 
- (IMP) methodForSelector: (SEL)aSelector;
119
 
+ (NSMethodSignature*) instanceMethodSignatureForSelector: (SEL)aSelector;
120
 
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
121
 
 
122
 
- (NSString*) description;
123
 
+ (NSString*) description;
124
 
 
125
 
+ (void) poseAsClass: (Class)aClassObject;
126
 
 
127
 
- (void) doesNotRecognizeSelector: (SEL)aSelector;
128
 
 
129
 
- (void) forwardInvocation: (NSInvocation*)anInvocation;
130
 
 
131
 
- (id) awakeAfterUsingCoder: (NSCoder*)aDecoder;
132
 
- (Class) classForArchiver;
133
 
- (Class) classForCoder;
134
 
- (Class) classForPortCoder;
135
 
- (id) replacementObjectForArchiver: (NSArchiver*)anArchiver;
136
 
- (id) replacementObjectForCoder: (NSCoder*)anEncoder;
137
 
- (id) replacementObjectForPortCoder: (NSPortCoder*)aCoder;
138
 
 
139
 
 
140
 
+ (id) setVersion: (int)aVersion;
141
 
+ (int) version;
142
 
 
143
 
@end
144
 
 
145
 
GS_EXPORT NSObject *
146
 
NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone);
147
 
GS_EXPORT void
148
 
NSDeallocateObject(NSObject *anObject);
149
 
GS_EXPORT NSObject *
150
 
NSCopyObject(NSObject *anObject, unsigned extraBytes, NSZone *zone);
151
 
 
152
 
GS_EXPORT BOOL
153
 
NSShouldRetainWithZone(NSObject *anObject, NSZone *requestedZone);
154
 
GS_EXPORT unsigned
155
 
NSExtraRefCount(id anObject);
156
 
GS_EXPORT void
157
 
NSIncrementExtraRefCount(id anObject);
158
 
GS_EXPORT BOOL
159
 
NSDecrementExtraRefCountWasZero(id anObject);
160
 
 
161
 
typedef enum _NSComparisonResult 
162
 
{
163
 
  NSOrderedAscending = -1, NSOrderedSame, NSOrderedDescending
164
 
165
 
NSComparisonResult;
166
 
 
167
 
enum {NSNotFound = 0x7fffffff};
168
 
 
169
 
#ifndef NO_GNUSTEP
170
 
 
171
 
@interface NSObject (NEXTSTEP)
172
 
- error:(const char *)aString, ...;
173
 
- notImplemented:(SEL)aSel;
174
 
/* - (const char *) name;
175
 
   Removed because OpenStep has -(NSString*)name; */
176
 
@end
177
 
 
178
 
/* Global lock to be used by classes when operating on any global
179
 
   data that invoke other methods which also access global; thus,
180
 
   creating the potential for deadlock. */
181
 
GS_EXPORT NSRecursiveLock *gnustep_global_lock;
182
 
 
183
 
/*
184
 
 * The GNUDescriptionDestination protocol declares methods used to
185
 
 * append a property-list description string to some output destination
186
 
 * so that property-lists can be converted to strings in a stream avoiding
187
 
 * the use of ridiculous amounts of memory for deeply nested data structures.
188
 
 */
189
 
@protocol       GNUDescriptionDestination
190
 
- (void) appendFormat: (NSString*)str, ...;
191
 
- (void) appendString: (NSString*)str;
192
 
@end
193
 
 
194
 
@interface NSObject (GNU)
195
 
- (NSComparisonResult) compare: (id)anObject;
196
 
/*
197
 
 * Default description methods -
198
 
 * [descriptionWithLocale:] calls [description]
199
 
 * [descriptionWithLocale:indent:] calls [descriptionWithLocale:]
200
 
 * [descriptionWithLocale:indent:to:] calls [descriptionWithLocale:indent:]
201
 
 * So - to have working descriptions, it is only necessary to implement the
202
 
 * [description] method, and to have efficient property-list generation, it
203
 
 * is necessary to override [descriptionWithLocale:indent:to:]
204
 
 */
205
 
- (NSString*) descriptionWithLocale: (NSDictionary*)aLocale;
206
 
+ (NSString*) descriptionWithLocale: (NSDictionary*)aLocale;
207
 
- (NSString*) descriptionWithLocale: (NSDictionary*)aLocale
208
 
                             indent: (unsigned)level;
209
 
+ (NSString*) descriptionWithLocale: (NSDictionary*)aLocale
210
 
                             indent: (unsigned)level;
211
 
- (void) descriptionWithLocale: (NSDictionary*)aLocale
212
 
                        indent: (unsigned)level
213
 
                            to: (id<GNUDescriptionDestination>)output;
214
 
+ (void) descriptionWithLocale: (NSDictionary*)aLocale
215
 
                        indent: (unsigned)level
216
 
                            to: (id<GNUDescriptionDestination>)output;
217
 
- (Class) transmuteClassTo: (Class)aClassObject;
218
 
- subclassResponsibility: (SEL)aSel;
219
 
- shouldNotImplement: (SEL)aSel;
220
 
+ (Class) autoreleaseClass;
221
 
+ (void) setAutoreleaseClass: (Class)aClass;
222
 
+ (void) enableDoubleReleaseCheck: (BOOL)enable;
223
 
- read: (TypedStream*)aStream;
224
 
- write: (TypedStream*)aStream;
225
 
/*
226
 
 * If the 'deallocActivationsActive' flag is set, the _dealloc method will be
227
 
 * called during the final release of an object, and the dealloc method will
228
 
 * then be called only if _dealloc returns YES.
229
 
 * You can override the _dealloc implementation to perform some action before
230
 
 * an object is deallocated (or disable deallocation by returning NO).
231
 
 * The default implementation simply returns YES.
232
 
 */
233
 
- (BOOL) deallocNotificationsActive;
234
 
- (void) setDeallocNotificationsActive: (BOOL)flag;
235
 
- (BOOL) _dealloc;
236
 
@end
237
 
 
238
 
#endif
239
 
 
240
 
/*
241
 
 *      Protocol for garbage collection finalization - same as libFoundation
242
 
 *      for compatibility.
243
 
 */
244
 
@protocol       GCFinalization
245
 
- (void) gcFinalize;
246
 
@end
247
 
 
248
 
#include <Foundation/NSDate.h>
249
 
@interface NSObject (TimedPerformers)
250
 
+ (void) cancelPreviousPerformRequestsWithTarget: (id)obj
251
 
                                        selector: (SEL)s
252
 
                                          object: (id)arg;
253
 
- (void) performSelector: (SEL)s
254
 
              withObject: (id)arg
255
 
              afterDelay: (NSTimeInterval)seconds;
256
 
- (void) performSelector: (SEL)s
257
 
              withObject: (id)arg
258
 
              afterDelay: (NSTimeInterval)seconds
259
 
                 inModes: (NSArray*)modes;
260
 
@end
261
 
 
262
 
/*
263
 
 *      RETAIN(), RELEASE(), and AUTORELEASE() are placeholders for the
264
 
 *      future day when we have garbage collecting.
265
 
 */
266
 
#ifndef GS_WITH_GC
267
 
#define GS_WITH_GC      0
268
 
#endif
269
 
#if     GS_WITH_GC
270
 
 
271
 
#ifndef RETAIN
272
 
#define RETAIN(object)          ((id)object)
273
 
#endif
274
 
#ifndef RELEASE
275
 
#define RELEASE(object)         
276
 
#endif
277
 
#ifndef AUTORELEASE
278
 
#define AUTORELEASE(object)     ((id)object)
279
 
#endif
280
 
 
281
 
#ifndef TEST_RETAIN
282
 
#define TEST_RETAIN(object)     ((id)object)
283
 
#endif
284
 
#ifndef TEST_RELEASE
285
 
#define TEST_RELEASE(object)
286
 
#endif
287
 
#ifndef TEST_AUTORELEASE
288
 
#define TEST_AUTORELEASE(object)        ((id)object)
289
 
#endif
290
 
 
291
 
#ifndef ASSIGN
292
 
#define ASSIGN(object,value)    (object = value)
293
 
#endif
294
 
#ifndef ASSIGNCOPY
295
 
#define ASSIGNCOPY(object,value)        (object = [value copy])
296
 
#endif
297
 
#ifndef DESTROY
298
 
#define DESTROY(object)         (object = nil)
299
 
#endif
300
 
 
301
 
#ifndef CREATE_AUTORELEASE_POOL
302
 
#define CREATE_AUTORELEASE_POOL(X)      
303
 
#endif
304
 
 
305
 
#ifndef RECREATE_AUTORELEASE_POOL
306
 
#define RECREATE_AUTORELEASE_POOL(X)
307
 
#endif
308
 
 
309
 
#define IF_NO_GC(X)     
310
 
 
311
 
#else
312
 
 
313
 
/*
314
 
 *      Basic retain, release, and autorelease operations.
315
 
 */
316
 
#ifndef RETAIN
317
 
#define RETAIN(object)          [object retain]
318
 
#endif
319
 
#ifndef RELEASE
320
 
#define RELEASE(object)         [object release]
321
 
#endif
322
 
#ifndef AUTORELEASE
323
 
#define AUTORELEASE(object)     [object autorelease]
324
 
#endif
325
 
 
326
 
/*
327
 
 *      Tested retain, release, and autorelease operations - only invoke the
328
 
 *      objective-c method if the receiver is not nil.
329
 
 */
330
 
#ifndef TEST_RETAIN
331
 
#define TEST_RETAIN(object)     (object != nil ? [object retain] : nil)
332
 
#endif
333
 
#ifndef TEST_RELEASE
334
 
#define TEST_RELEASE(object)    ({ if (object) [object release]; })
335
 
#endif
336
 
#ifndef TEST_AUTORELEASE
337
 
#define TEST_AUTORELEASE(object)        ({ if (object) [object autorelease]; })
338
 
#endif
339
 
 
340
 
/*
341
 
 *      ASSIGN(object,value) assigns the value to the object with
342
 
 *      appropriate retain and release operations.
343
 
 */
344
 
#ifndef ASSIGN
345
 
#define ASSIGN(object,value)    ({\
346
 
id __value = (id)(value); \
347
 
id __object = (id)(object); \
348
 
if (__value != __object) \
349
 
  { \
350
 
    if (__value != nil) \
351
 
      { \
352
 
        [__value retain]; \
353
 
      } \
354
 
    object = __value; \
355
 
    if (__object != nil) \
356
 
      { \
357
 
        [__object release]; \
358
 
      } \
359
 
  } \
360
 
})
361
 
#endif
362
 
 
363
 
/*
364
 
 *      ASSIGNCOPY(object,value) assignes a copy of the value to the object with
365
 
 *      and release operations.
366
 
 */
367
 
#ifndef ASSIGNCOPY
368
 
#define ASSIGNCOPY(object,value)        ({\
369
 
id __value = (value); \
370
 
id __object = (id)(object); \
371
 
if (__value != __object) \
372
 
  { \
373
 
    if (__value != nil) \
374
 
      { \
375
 
        __value = [__value copy]; \
376
 
      } \
377
 
    (id)object = __value; \
378
 
    if (__object != nil) \
379
 
      { \
380
 
        [__object release]; \
381
 
      } \
382
 
  } \
383
 
})
384
 
#endif
385
 
 
386
 
/*
387
 
 *      DESTROY() is a release operation which also sets the variable to be
388
 
 *      a nil pointer for tidyness - we can't accidentally use a DESTROYED
389
 
 *      object later.  It also makes sure to set the variable to nil before
390
 
 *      releasing the object - to avoid side-effects of the release trying
391
 
 *      to reference the object being released through the variable.
392
 
 */
393
 
#ifndef DESTROY
394
 
#define DESTROY(object)         ({ \
395
 
  if (object) \
396
 
    { \
397
 
      id __o = object; \
398
 
      object = nil; \
399
 
      [__o release]; \
400
 
    } \
401
 
})
402
 
#endif
403
 
 
404
 
#ifndef CREATE_AUTORELEASE_POOL
405
 
#define CREATE_AUTORELEASE_POOL(X)      \
406
 
  NSAutoreleasePool *(X) = [NSAutoreleasePool new]
407
 
#endif
408
 
 
409
 
/*
410
 
 * Similar, but allows reuse of variables. Be sure to use DESTROY()
411
 
 * so the object variable stays nil.
412
 
 */
413
 
 
414
 
#ifndef RECREATE_AUTORELEASE_POOL
415
 
#define RECREATE_AUTORELEASE_POOL(X)  \
416
 
  if (X == nil) \
417
 
    (X) = [NSAutoreleasePool new]
418
 
#endif
419
 
 
420
 
#define IF_NO_GC(X)     X
421
 
 
422
 
#endif
423
 
 
424
 
#endif /* __NSObject_h_GNUSTEP_BASE_INCLUDE */