ftp.nice.ch/pub/next/developer/languages/c/gcc.2.7.2.2.I.b.tar.gz#/lib/gcc-lib/m68k-next-nextstep3/2.7.2.2.f.2/include/foundation/NSArray.h

This is NSArray.h in view mode; [Download] [Up]

/*	NSArray.h
	Basic dynamic array
  	Copyright 1993, 1994, NeXT, Inc.
	NeXT, March 1993
*/

#import <foundation/NSString.h>

/* This module implement the 'array' concept.  Featuring:
    - arrays are always dynamic (resize themselves by doubling when they reach a certain maximum), so that callers never have to think about allocation;
    - support read only arrays;
    - embeds various conveniences and algorithms (e.g. sort);
    
   Generic coding behavior is supplied
    - it preserves class and calls initWithObjects:count:
    - immutable arrays are distributed bycopy with their elements also bycopy
    - mutable arrays are distributed by reference unless asked bycopy
*/

obsolete enum {NSNotInArray = 0x7fffffff}; /* to be obsoleted soon*/

/***************	Read Only Abstract Class		***********/

@interface NSArray:NSObject <NSCopying, NSMutableCopying>
/* NOTES:
    -copyWithZone: and -copy guarantee an immutable returned value;
    	elements are recursively copied with -copyWithZone:
    -isEqual: checks that argument is an NSArray;
	If conforming, each item is compared using isEqual:;
    -hash is such that [x isEqual:y] => [x hash] == [y hash];    
     */

- (unsigned)count;
    /* Number of items in the array (NOT the maximum capacity of the array) */
    
- objectAtIndex:(unsigned)index;
    /* Raises if index out of bounds;
    Clients can expect this method to be fast, in O(1) */
    
@end

@interface NSArray (NSExtendedArray)

- (unsigned)indexOfObjectIdenticalTo:anObject;
    /* Performs search on the array for candidate;
    pointer equality is used;
    Return NSNotFound iff not found */

- (unsigned)indexOfObject:anObject;
    /* Performs search on the array for candidate;
    isEqual: equality is used;
    Return NSNotFound iff not found */

- (BOOL)containsObject:anObject;
    /* short cut for indexOfObject: (isEqual: is used) */
    
- (BOOL)isEqualToArray:(NSArray *)otherArray;
    /* Compares 2 arrays for exact match;
    Uses isEqual: as the comparison predicate; */

- lastObject;
    /* Returns nil if none */

- (void)makeObjectsPerform:(SEL)aSelector;
- (void)makeObjectsPerform:(SEL)aSelector withObject:argument;
    
- (NSArray *)sortedArrayUsingSelector:(SEL)comparator;
    /* Returns a sorted array of references;
    Ascending sort.  Sort guarantees at most N*LOG(N) comparisons;
    (for N=2**P, at most (2**P)*(P-1)+1 comparisons)
    Performs comparator with 2 items to be compared ([item1 comparator:item2]);
    Comparison should return <0 if ascending >0 if descending 0 if same */
    
- (NSArray *)sortedArrayUsingFunction:(int (*)(id, id, void *))comparator context:(void *)context;
    /* Same except calls comparator with 3 arguments: 2 items to be compared and parameter */

- (NSString *)componentsJoinedByString:(NSString *)separator;
    /* The reverse of the componentsSeparatedByString: method in NSString.
    From the various parts, builds a complete string, with the separator
    in between each string. If sent to an empty array, "" will be returned.
    It is an error for the array to contain any elements that aren't NSStrings. */

- firstObjectCommonWithArray:(NSArray *)otherArray;
    /* Returns the first object in the receiver which occurs in the argument. */

- (NSArray *)subarrayWithRange:(NSRange)range;
    /* returns the restriction of self to range */

- (NSEnumerator *)objectEnumerator;
    /* Returns an enumerator object to cycle through the contents,
    starting at the 0th element.
    Updates should not be done during enumeration
    To use:
    	NSEnumerator *enumerator = [collection objectEnumerator];
	id object;
	while (object = [enumerator nextObject]) {
	    ... 
	}
    */

- (NSEnumerator *)reverseObjectEnumerator;
    /* Returns an enumerator that enumerates objects starting at lastObject */

- (NSString *)description;
    /* Convert to a string, using the "PropertyList" format */

- (NSString *)descriptionWithIndent:(unsigned)level;
    /* Convert to a string, using the "PropertyList" format;
    Indent is for human-readibility;
    level==0 means top level; level==1 => 4 spaces */

@end

/***************	Mutable Abstract Class		***************/

@interface NSMutableArray: NSArray

/* Note: Only the 3 first methods are necessary for the Array abstraction.  However, in order to enable subclasses to meaningfully implement certain functions (i.e. notification), all classes implementing the NSMutableArray should implement all 5 methods, and no method should call recursively any of the others */

- (void)addObject:anObject;
    /* Appends element at end of array; Resizes if necessary;
    -retain is applied to the object inserted;
    If object is nil an exception is raised;
    Clients can expect this method to be fast, in O(1) */
    
- (void)replaceObjectAtIndex:(unsigned)index withObject:anObject;
    /* Replaces any existing item;
    If object is nil an exception is raised.
    The object inserted in the array is the result of [object retain] 
    and -release is applied to previous element;
    Clients can expect this method to be fast, in O(1) */
    
- (void)removeLastObject;
    /* Removes from array; Raises if applied on an empty list.
    Applies -release to removed object;
    Clients can expect this method to be fast, in O(1) */    
    
- (void)insertObject:anObject atIndex:(unsigned)index;
    /* Shifts the items after index to allow insertion;
    The object inserted in the array is the result of [object retain]
    Attention: this method is slow: only O(count) time is guaranteed */
    
- (void)removeObjectAtIndex:(unsigned)index;
    /* Recompacts the array after item has been removed;
    Applies -release to removed object;
    Attention: this method is slow: only O(count) time is guaranteed */
    
@end

@interface NSMutableArray (NSExtendedMutableArray)
    
- (void)removeObjectIdenticalTo:anObject;
    /* Removes all occurrences of candidate */

- (void)removeObject:anObject;
    /* Removes all occurrences of candidate */

- (void)removeAllObjects;
    /* Removes all object froms the array; 
    Applies -release to each removed object */

- (void)addObjectsFromArray:(NSArray *)otherArray;
    /* adds each element in otherArray */

- (void)removeObjectsFromIndices:(unsigned *)indices numIndices:(unsigned)count;
    /* Speed up of removeObjectAtIndex: for batches of indices;
    This method does not distribute and therefore should be used sparingly */

- (void)removeObjectsInArray:(NSArray *)otherArray;
    /* Assumes that all elements in otherArray respond to -hash and -isEqual:, 
    in order to very efficiently remove large sets of objects;
    This method does not distribute and therefore should be used sparingly */

- (void)sortUsingFunction:(int (*)(id, id, void *))compare context:(void *)context;
    /* In place sort; O(N * LOG(N)) */

@end

/***************	Array creation		***************/

@interface NSArray (NSArrayCreation)

+ allocWithZone:(NSZone *)zone;
    /* Create an uninitialized instance of a concrete array;
    substitutes a concrete class if called with NSArray;
    +alloc can also be used to that effect */

+ array;
    /* Creates an empty autoreleased array */

+ arrayWithObject:anObject;
    /* convenience to create an autoreleased array with just 1 element */

+ arrayWithObjects:firstObj, ...;
    /* convenience to create an autoreleased array */

- initWithObjects:(id *)objects count:(unsigned)count;
    /* Objects are retained;
    Designated initializer for immutable arrays */

- initWithObjects:firstObj, ...;
    /* Vararg list terminated with nil. */

- initWithArray:(NSArray *)array;
    /* Performs -retain: for each item in array */

@end

/***************	Mutable Array creation		***************/

@interface NSMutableArray (NSMutableArrayCreation)

+ allocWithZone:(NSZone *)zone;
    /* Create an uninitialized instance of a concrete mutable array;
    substitutes a concrete class if called with NSMutableArray;
    +alloc can also be used to that effect;
    -dealloc empties array using -removeAllObjects before de-allocating */

+ arrayWithCapacity:(unsigned)numItems;
    /* Creates an autoreleased mutable array */

- initWithCapacity:(unsigned)numItems;
    /* Designated initializer for mutable arrays */

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.