00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPObject.j"
00024 @import "CPObjJRuntime.j"
00025
00026
00032 CPOrderedAscending = -1;
00038 CPOrderedSame = 0;
00044 CPOrderedDescending = 1;
00045
00051 @implementation CPSortDescriptor : CPObject
00052 {
00053 CPString _key;
00054 SEL _selector;
00055 BOOL _ascending;
00056 }
00057
00058
00065 - (id)initWithKey:(CPString)aKey ascending:(BOOL)isAscending
00066 {
00067 return [self initWithKey:aKey ascending:isAscending selector:@selector(compare:)];
00068 }
00069
00077 - (id)initWithKey:(CPString)aKey ascending:(BOOL)isAscending selector:(SEL)aSelector
00078 {
00079 self = [super init];
00080
00081 if (self)
00082 {
00083 _key = aKey;
00084 _ascending = isAscending;
00085 _selector = aSelector;
00086 }
00087
00088 return self;
00089 }
00090
00091
00095 - (BOOL)ascending
00096 {
00097 return _ascending;
00098 }
00099
00103 - (CPString)key
00104 {
00105 return _key;
00106 }
00107
00111 - (SEL)selector
00112 {
00113 return _selector;
00114 }
00115
00116
00123 - (CPComparisonResult)compareObject:(id)lhsObject withObject:(id)rhsObject
00124 {
00125 return (_ascending ? 1 : -1) * [[lhsObject valueForKey:_key] performSelector:_selector withObject:[rhsObject valueForKey:_key]];
00126 }
00127
00132 - (id)reversedSortDescriptor
00133 {
00134 return [[[self class] alloc] initWithKey:_key ascending:!_ascending selector:_selector];
00135 }
00136
00137 @end