1
/**Interface for NSObject for GNUStep
2
Copyright (C) 1995, 1996, 1998 Free Software Foundation, Inc.
4
Written by: Andrew Kachites McCallum <mccallum@gnu.ai.mit.edu>
7
This file is part of the GNUstep Base Library.
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.
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.
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.
24
#ifndef __NSObject_h_GNUSTEP_BASE_INCLUDE
25
#define __NSObject_h_GNUSTEP_BASE_INCLUDE
28
* Check consistency of definitions for system compatibility.
30
#if defined(STRICT_OPENSTEP)
32
#elif defined(STRICT_MACOS_X)
38
#include <Foundation/NSObjCRuntime.h>
39
#include <base/preface.h>
41
#include <objc/objc.h>
42
#include <objc/Protocol.h>
43
#include <Foundation/NSZone.h>
50
@class NSMethodSignature;
51
@class NSMutableString;
52
@class NSRecursiveLock;
60
- (BOOL) isEqual: anObject;
61
- (BOOL) isKindOfClass: (Class)aClass;
62
- (BOOL) isMemberOfClass: (Class)aClass;
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;
73
- (oneway void) release;
74
- (unsigned) retainCount;
76
- (NSString*) description;
80
- (id) copyWithZone: (NSZone *)zone;
83
@protocol NSMutableCopying
84
- (id) mutableCopyWithZone: (NSZone *)zone;
88
- (void) encodeWithCoder: (NSCoder*)aCoder;
89
- (id) initWithCoder: (NSCoder*)aDecoder;
93
@interface NSObject <NSObject>
100
+ (BOOL) requiresTypedMemory;
104
+ (id) allocWithZone: (NSZone*)z;
113
+ (Class) superclass;
115
+ (BOOL) instancesRespondToSelector: (SEL)aSelector;
117
+ (IMP) instanceMethodForSelector: (SEL)aSelector;
118
- (IMP) methodForSelector: (SEL)aSelector;
119
+ (NSMethodSignature*) instanceMethodSignatureForSelector: (SEL)aSelector;
120
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
122
- (NSString*) description;
123
+ (NSString*) description;
125
+ (void) poseAsClass: (Class)aClassObject;
127
- (void) doesNotRecognizeSelector: (SEL)aSelector;
129
- (void) forwardInvocation: (NSInvocation*)anInvocation;
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;
140
+ (id) setVersion: (int)aVersion;
146
NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone);
148
NSDeallocateObject(NSObject *anObject);
150
NSCopyObject(NSObject *anObject, unsigned extraBytes, NSZone *zone);
153
NSShouldRetainWithZone(NSObject *anObject, NSZone *requestedZone);
155
NSExtraRefCount(id anObject);
157
NSIncrementExtraRefCount(id anObject);
159
NSDecrementExtraRefCountWasZero(id anObject);
161
typedef enum _NSComparisonResult
163
NSOrderedAscending = -1, NSOrderedSame, NSOrderedDescending
167
enum {NSNotFound = 0x7fffffff};
171
@interface NSObject (NEXTSTEP)
172
- error:(const char *)aString, ...;
173
- notImplemented:(SEL)aSel;
174
/* - (const char *) name;
175
Removed because OpenStep has -(NSString*)name; */
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;
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.
189
@protocol GNUDescriptionDestination
190
- (void) appendFormat: (NSString*)str, ...;
191
- (void) appendString: (NSString*)str;
194
@interface NSObject (GNU)
195
- (NSComparisonResult) compare: (id)anObject;
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:]
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;
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.
233
- (BOOL) deallocNotificationsActive;
234
- (void) setDeallocNotificationsActive: (BOOL)flag;
241
* Protocol for garbage collection finalization - same as libFoundation
244
@protocol GCFinalization
248
#include <Foundation/NSDate.h>
249
@interface NSObject (TimedPerformers)
250
+ (void) cancelPreviousPerformRequestsWithTarget: (id)obj
253
- (void) performSelector: (SEL)s
255
afterDelay: (NSTimeInterval)seconds;
256
- (void) performSelector: (SEL)s
258
afterDelay: (NSTimeInterval)seconds
259
inModes: (NSArray*)modes;
263
* RETAIN(), RELEASE(), and AUTORELEASE() are placeholders for the
264
* future day when we have garbage collecting.
272
#define RETAIN(object) ((id)object)
275
#define RELEASE(object)
278
#define AUTORELEASE(object) ((id)object)
282
#define TEST_RETAIN(object) ((id)object)
285
#define TEST_RELEASE(object)
287
#ifndef TEST_AUTORELEASE
288
#define TEST_AUTORELEASE(object) ((id)object)
292
#define ASSIGN(object,value) (object = value)
295
#define ASSIGNCOPY(object,value) (object = [value copy])
298
#define DESTROY(object) (object = nil)
301
#ifndef CREATE_AUTORELEASE_POOL
302
#define CREATE_AUTORELEASE_POOL(X)
305
#ifndef RECREATE_AUTORELEASE_POOL
306
#define RECREATE_AUTORELEASE_POOL(X)
314
* Basic retain, release, and autorelease operations.
317
#define RETAIN(object) [object retain]
320
#define RELEASE(object) [object release]
323
#define AUTORELEASE(object) [object autorelease]
327
* Tested retain, release, and autorelease operations - only invoke the
328
* objective-c method if the receiver is not nil.
331
#define TEST_RETAIN(object) (object != nil ? [object retain] : nil)
334
#define TEST_RELEASE(object) ({ if (object) [object release]; })
336
#ifndef TEST_AUTORELEASE
337
#define TEST_AUTORELEASE(object) ({ if (object) [object autorelease]; })
341
* ASSIGN(object,value) assigns the value to the object with
342
* appropriate retain and release operations.
345
#define ASSIGN(object,value) ({\
346
id __value = (id)(value); \
347
id __object = (id)(object); \
348
if (__value != __object) \
350
if (__value != nil) \
355
if (__object != nil) \
357
[__object release]; \
364
* ASSIGNCOPY(object,value) assignes a copy of the value to the object with
365
* and release operations.
368
#define ASSIGNCOPY(object,value) ({\
369
id __value = (value); \
370
id __object = (id)(object); \
371
if (__value != __object) \
373
if (__value != nil) \
375
__value = [__value copy]; \
377
(id)object = __value; \
378
if (__object != nil) \
380
[__object release]; \
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.
394
#define DESTROY(object) ({ \
404
#ifndef CREATE_AUTORELEASE_POOL
405
#define CREATE_AUTORELEASE_POOL(X) \
406
NSAutoreleasePool *(X) = [NSAutoreleasePool new]
410
* Similar, but allows reuse of variables. Be sure to use DESTROY()
411
* so the object variable stays nil.
414
#ifndef RECREATE_AUTORELEASE_POOL
415
#define RECREATE_AUTORELEASE_POOL(X) \
417
(X) = [NSAutoreleasePool new]
420
#define IF_NO_GC(X) X
424
#endif /* __NSObject_h_GNUSTEP_BASE_INCLUDE */