home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / OpenStepConversion / IntermediateFrameworks3 / Foundation.framework / Headers / NSObject.h < prev    next >
Text File  |  1996-03-27  |  9KB  |  236 lines

  1. /*    NSObject.h
  2.     Definitions of very basic things
  3.     Copyright 1994, NeXT Computer, Inc.
  4. */
  5.  
  6. #import <Foundation/NSObjCRuntime.h>
  7. #import <Foundation/NSZone.h>
  8.  
  9. @class NSInvocation;
  10. @class NSMethodSignature;
  11. @class NSCoder;
  12. @class NSString;
  13. @class NSEnumerator;
  14.  
  15. @class Protocol;    // part of ObjC language
  16.  
  17. /***************    Basic protocols        ***************/
  18.  
  19. @protocol NSObject
  20.  
  21. - (BOOL)isEqual:(id)object;
  22.     /* must accept any object as argument;
  23.     Default for NSObject is pointer equality */
  24.  
  25. - (unsigned)hash;
  26.     /* Must satisfy [x isEqual:y] => [x hash]==[y hash];
  27.     Default for NSObject is to hash the pointer */
  28.     
  29. - (Class)superclass;
  30. - (Class)class;
  31. - (id)self;
  32. - (NSZone *)zone;
  33.  
  34. - (id)performSelector:(SEL)aSelector;
  35.     // method performed should return a 32-bit quantity
  36. - (id)performSelector:(SEL)aSelector withObject:(id)object;
  37.     // method performed should return a 32-bit quantity
  38. - (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2;
  39.     // method performed should return a 32-bit quantity
  40.  
  41. - (BOOL)isProxy;
  42.  
  43. - (BOOL)isKindOfClass:(Class)aClass;
  44. - (BOOL)isMemberOfClass:(Class)aClass;
  45. - (BOOL)conformsToProtocol:(Protocol *)aProtocol;
  46.  
  47. - (BOOL)respondsToSelector:(SEL)aSelector;
  48.  
  49. - (id)retain;
  50.     /* default for NSObject is to externally increment the ref count;
  51.     subclasses may redefine if they have their own reference counting scheme, but should not call super;
  52.     For convenience only, retain returns self; no other object should be returned than self */
  53.     
  54. - (oneway void)release;
  55.     /* default for NSObject is to externally decrement the reference count and to perform  dealloc if zero;
  56.     subclasses may redefine if they have their own reference counting scheme, but should not call super */
  57.  
  58. - (id)autorelease;
  59.     /* Inserts the object in the current delayed free pool, and returns the object itself for convenience;
  60.     */
  61.  
  62. - (unsigned)retainCount;
  63.     /* Method that should only be used for DEBUG or very unusual ref-counting strategies!
  64.     default for NSObject is to return the externally maintained ref count;
  65.     subclasses may should override this method if they implement their own refcounting scheme.
  66.     This method is only used by foundation during debug, when "enableDoubleFreeCheck" (or the dwrite NSDisableDoubleFreeCheck) has been set to check for overfreeing, or over autoreleasing of objects. 
  67.     For objects which never get released (i.e. their release method is a no-op), this method should return UINT_MAX. */
  68.  
  69. - (NSString *)description;
  70.     /* Human-readable NSString */
  71.  
  72. @end
  73.  
  74. @protocol NSCopying
  75.  
  76. - (id)copyWithZone:(NSZone *)zone;
  77.     /* expresses snapshots of objects.  
  78.     Typical usage is for 'passing by value' value objects.  The only
  79.     guarantee of the snapshot operation for classes that implement the
  80.     NSCopying protocol is that: 
  81.         -copyWithZone: will yield a functional object as long as you don't
  82.     change the returned value.  
  83.     That snapshot operation does not preserve class mutability (for classes
  84.     for which that makes sense).  Immutability of the returned value is not
  85.     guaranteed in general either, although Property List classes (NSString,
  86.     NSData, NSArray, NSDictionary) guarantee immutable returned values. 
  87.     This method is an exception to the allocation rule: returned value is
  88.     owned by caller who is responsible for releasing it;
  89.     zone may be NULL */
  90.  
  91. @end
  92.  
  93. @protocol NSMutableCopying
  94.  
  95. - (id)mutableCopyWithZone:(NSZone *)zone;
  96.     /* This should be implemented by cluster of classes that differentiate between mutable and immutable objects (such as the basic property list classes)
  97.     It should yield a mutable copy, owned by the caller;
  98.     zone may be NULL */
  99.  
  100. @end
  101.  
  102. @protocol NSCoding
  103.     /* The NSCoding protocol is implemented by objects that wish to be persistent and/or distributed */
  104.  
  105. - (void)encodeWithCoder:(NSCoder *)aCoder;
  106.     /* Object should store its state onto aCoder;
  107.     First thing should be to call [super encodeWithCoder:] if self's superclass conforms to <NSCoding>;  
  108.     Note that NSObject does NOT conform to <NSCoding>, and therefore subclasses of NSObject that do <NSCoding> should NOT call super. */
  109.  
  110. - (id)initWithCoder:(NSCoder *)aDecoder;
  111.     /* Called with a freshly allocated object;
  112.     should ask its super to reestablish its state, and then fill itself with data obtained from aDecoder;
  113.     When the exact format of the parent classes serialization is known,
  114.     the object can replace itself by another object.  In that case,
  115.     -initWithCoder: must deallocate self, and take total responsability
  116.     of the deserialization.  Also, there is a restriction that the original
  117.     object must not appear more than once in the encoding graph;
  118.     NSObject does not implement this method! */
  119.  
  120. @end
  121.  
  122. /***********    Base class        ***********/
  123.  
  124. @interface NSObject <NSObject> {
  125.     Class    isa;
  126. }
  127.  
  128. + (void)load;
  129.  
  130. + (id)initialize;
  131. - (id)init;
  132. - (void)dealloc;
  133.     /* deallocates self; 
  134.     subclasses should release their instance variables and call [super dealloc] */
  135.  
  136. + (id)new;
  137. + (id)allocWithZone:(NSZone *)zone;
  138.     /* zone passed may be NULL */
  139. + (id)alloc;
  140. - (id)copy;
  141.     /* Convenience for implementors of <NSCopying>: just calls copyWithZone:, which raises (unless defined by a subclass) */
  142.  
  143. - (id)mutableCopy;
  144.     /* Convenience for implementors of <NSMutableCopying>: just calls mutableCopyWithZone:, which raises (unless defined by a subclass) */
  145.  
  146. + (id)copyWithZone:(NSZone *)zone;
  147. + (id)mutableCopyWithZone:(NSZone *)zone;
  148.     /* Convenience -- classes can be dictionary keys */
  149.  
  150. + (Class)superclass;
  151. + (Class)class;
  152. + (void)poseAsClass:(Class)aClass;
  153. + (BOOL)instancesRespondToSelector:(SEL)aSelector;
  154. + (BOOL)conformsToProtocol:(Protocol *)protocol;
  155. - (IMP)methodForSelector:(SEL)aSelector;
  156. + (IMP)instanceMethodForSelector:(SEL)aSelector;
  157. + (int)version;
  158. + (void)setVersion:(int)aVersion;
  159. - (void)doesNotRecognizeSelector:(SEL)aSelector;
  160. - (void)forwardInvocation:(NSInvocation *)anInvocation;
  161. - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
  162.  
  163. + (NSString *)description;
  164.     /* returns the class name */
  165.  
  166. - (Class)classForCoder;
  167.     /* Provide the class name used for coding.
  168.     Default is -class */
  169.  
  170. - (id)replacementObjectForCoder:(NSCoder *)aCoder;
  171.     /* Allows argument to propose another object at its place when encoding;
  172.     nil means to encode nothing;
  173.     default is to return self */
  174.  
  175. - (id)awakeAfterUsingCoder:(NSCoder *)aDecoder;
  176.     /* Gives a last change for the object to propose another at its place;
  177.     This is necessary because an object (say an instance of a subclass Font)
  178.     may decide to replace itself once all the -initWithCoder have been done,
  179.     and the method deciding to replace maybe in the middle of the
  180.     inheritance hierarchy (say Font).
  181.     Default is simply to return self;
  182.     If a replacement takes place, the implementation of -awakeAfterUsingCoder is responsible for releasing the old self */
  183.  
  184. @end
  185.  
  186. /***********    Object Allocation / Deallocation        *******/
  187.     
  188. extern NSObject *NSAllocateObject(Class aClass, unsigned extraBytes, NSZone *zone);
  189.     /* All allocations of NSObjects should go through this routine for the benefit of debug tools;
  190.     If zone is NULL NSDefaultMallocZone() is used. extraBytes is typically 0. */
  191.  
  192. extern void NSDeallocateObject(NSObject *object);
  193.     /* Must have been allocated with NSAllocateObject() */
  194.  
  195. extern NSObject *NSCopyObject(NSObject *object, unsigned extraBytes, NSZone *zone);
  196.     /* Bit-by-bit copy of the object */
  197.  
  198. extern BOOL NSShouldRetainWithZone(NSObject *anObject, NSZone *requestedZone);
  199.     /* This method encapsulates the little bit of logic to decide whether to honor the zone in a copyWithZone: or just do a -retain;
  200.     This of course is only applicable for certain classes;
  201.     The logic is as following:
  202.     - if the default zone (or NULL) is requested just retain;
  203.     - if the zone is the same as the object zone, retain;
  204.     - otherwise, make a true copy */
  205.  
  206. /***********    Reference counting utilities        *******/
  207.  
  208. extern void NSIncrementExtraRefCount(id object);
  209.  
  210. extern BOOL NSDecrementExtraRefCountWasZero(id object);
  211.  
  212. extern unsigned NSExtraRefCount(id object);
  213.  
  214. /***********        Misc        *******/
  215.  
  216. /* NSComparisonResult is used for ordered comparision results. If the first
  217. argument to the comparision (the receiving object in a message call or the
  218. left argument in a function call) is greater than the second,
  219. NSOrderedDescending is returned.  If it is smaller, NSOrderedAscending
  220. is returned. Examples:
  221.   [@"Zebra" compare:@"Aardvark"] returns NSOrderedDescending
  222.   compareInts (1, 7) returns NSOrderedAscending
  223. */
  224. typedef enum _NSComparisonResult {NSOrderedAscending = -1, NSOrderedSame, NSOrderedDescending} NSComparisonResult;
  225.  
  226. enum {NSNotFound = 0x7fffffff};
  227.  
  228. /******************* Extra stuff for Conversion ***********/
  229.  
  230. #import <objc/objc-class.h>
  231. #import <objc/typedstream.h>
  232. #import <stdarg.h>
  233.  
  234. #define obsolete    // In order to mark obsolete constructs and to be able to apply tops scripts
  235.  
  236.