home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / EOSortOrdering.h < prev    next >
Encoding:
Text File  |  1996-09-11  |  2.8 KB  |  75 lines

  1. // EOSortOrdering.h
  2. // Copyright (c) 1996, NeXT Software, Inc. All rights reserved.
  3. //
  4. // EOSortOrdering is a generic, key-based, way of expressing how an array of objects
  5. // should be sorted.
  6. // EOSortOrdering objects can be used to express sorting of Enterprise Objects
  7. // in memory, as well as used to generate SQL to sort rows for objects fetched
  8. // from a database server.
  9. //
  10. // To specify a sort on Employees first by lastName, then by firstName, you could
  11. // use the following:
  12. //
  13. // NSArray *ordering = [NSArray arrayWithObjects:
  14. //        [EOSortOrdering sortOrderingWithKey:@"lastName" selector:EOCompareAscending],
  15. //        [EOSortOrdering sortOrderingWithKey:@"firstName" selector:EOCompareAscending], nil];
  16. //
  17. // An array of Employees could then be sorted in memory as follows:
  18. // NSArray *sortedEmployees = [employees sortedArrayUsingKeyOrderArray:ordering];
  19. //
  20.  
  21. #import <Foundation/Foundation.h>
  22. #import <EOControl/EONull.h>
  23.  
  24. // Key-based ordering specification
  25. @interface EOSortOrdering : NSObject <NSCoding>
  26. {
  27.     SEL _selector;
  28.     NSString *_key;
  29. }
  30.  
  31. + (EOSortOrdering *)sortOrderingWithKey:(NSString *)key selector:(SEL)selector;
  32.     // Convenience method to return an autoreleased EOSortOrdering.
  33.  
  34. - initWithKey:(NSString *)key selector:(SEL)selector;
  35. - (NSString *)key;
  36. - (SEL)selector;
  37. @end
  38.  
  39. // Categories on Array for EO sorting
  40. @interface NSArray (EOKeyBasedSorting)
  41. - (NSArray *)sortedArrayUsingKeyOrderArray:(NSArray *)orderArray;
  42.     // Returns a new array by sorting the objects of the receiver
  43.     // according to the EOSortOrderings in orderArray.
  44.     // The objects in the array are compared by extracting the
  45.     // sort properties using the KeyValueCoding protocol and sending
  46.     // them the compare: selector.
  47.     // This method will raise if the objects corresponding to the
  48.     // keys in the ordering array cannot be compared using the
  49.     // selector compare:
  50. @end
  51.  
  52. @interface NSMutableArray (EOKeyBasedSorting)
  53. - (void)sortUsingKeyOrderArray:(NSArray *)orderArray;
  54. @end
  55.  
  56. @interface NSObject (EOSortOrderingComparison)
  57. - (NSComparisonResult)compareAscending:(id)other;
  58. - (NSComparisonResult)compareDescending:(id)other;
  59. - (NSComparisonResult)compareCaseInsensitiveAscending:(id)other;
  60. - (NSComparisonResult)compareCaseInsensitiveDescending:(id)other;
  61. @end
  62.  
  63. @interface EONull (EOSortOrderingComparison)
  64. - (NSComparisonResult)compareAscending:(id)other;
  65. - (NSComparisonResult)compareDescending:(id)other;
  66. - (NSComparisonResult)compareCaseInsensitiveAscending:(id)other;
  67. - (NSComparisonResult)compareCaseInsensitiveDescending:(id)other;
  68. @end
  69.  
  70. #define EOCompareAscending @selector(compareAscending:)
  71. #define EOCompareDescending @selector(compareDescending:)
  72. #define EOCompareCaseInsensitiveAscending @selector(compareCaseInsensitiveAscending:)
  73. #define EOCompareCaseInsensitiveDescending @selector(compareCaseInsensitiveDescending:)
  74.  
  75.