home *** CD-ROM | disk | FTP | other *** search
- // EOSortOrdering.h
- // Copyright (c) 1996, NeXT Software, Inc. All rights reserved.
- //
- // EOSortOrdering is a generic, key-based, way of expressing how an array of objects
- // should be sorted.
- // EOSortOrdering objects can be used to express sorting of Enterprise Objects
- // in memory, as well as used to generate SQL to sort rows for objects fetched
- // from a database server.
- //
- // To specify a sort on Employees first by lastName, then by firstName, you could
- // use the following:
- //
- // NSArray *ordering = [NSArray arrayWithObjects:
- // [EOSortOrdering sortOrderingWithKey:@"lastName" selector:EOCompareAscending],
- // [EOSortOrdering sortOrderingWithKey:@"firstName" selector:EOCompareAscending], nil];
- //
- // An array of Employees could then be sorted in memory as follows:
- // NSArray *sortedEmployees = [employees sortedArrayUsingKeyOrderArray:ordering];
- //
-
- #import <Foundation/Foundation.h>
- #import <EOControl/EONull.h>
-
- // Key-based ordering specification
- @interface EOSortOrdering : NSObject <NSCoding>
- {
- SEL _selector;
- NSString *_key;
- }
-
- + (EOSortOrdering *)sortOrderingWithKey:(NSString *)key selector:(SEL)selector;
- // Convenience method to return an autoreleased EOSortOrdering.
-
- - initWithKey:(NSString *)key selector:(SEL)selector;
- - (NSString *)key;
- - (SEL)selector;
- @end
-
- // Categories on Array for EO sorting
- @interface NSArray (EOKeyBasedSorting)
- - (NSArray *)sortedArrayUsingKeyOrderArray:(NSArray *)orderArray;
- // Returns a new array by sorting the objects of the receiver
- // according to the EOSortOrderings in orderArray.
- // The objects in the array are compared by extracting the
- // sort properties using the KeyValueCoding protocol and sending
- // them the compare: selector.
- // This method will raise if the objects corresponding to the
- // keys in the ordering array cannot be compared using the
- // selector compare:
- @end
-
- @interface NSMutableArray (EOKeyBasedSorting)
- - (void)sortUsingKeyOrderArray:(NSArray *)orderArray;
- @end
-
- @interface NSObject (EOSortOrderingComparison)
- - (NSComparisonResult)compareAscending:(id)other;
- - (NSComparisonResult)compareDescending:(id)other;
- - (NSComparisonResult)compareCaseInsensitiveAscending:(id)other;
- - (NSComparisonResult)compareCaseInsensitiveDescending:(id)other;
- @end
-
- @interface EONull (EOSortOrderingComparison)
- - (NSComparisonResult)compareAscending:(id)other;
- - (NSComparisonResult)compareDescending:(id)other;
- - (NSComparisonResult)compareCaseInsensitiveAscending:(id)other;
- - (NSComparisonResult)compareCaseInsensitiveDescending:(id)other;
- @end
-
- #define EOCompareAscending @selector(compareAscending:)
- #define EOCompareDescending @selector(compareDescending:)
- #define EOCompareCaseInsensitiveAscending @selector(compareCaseInsensitiveAscending:)
- #define EOCompareCaseInsensitiveDescending @selector(compareCaseInsensitiveDescending:)
-
-