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
00053 @implementation CPSortDescriptor : CPObject
00054 {
00055 CPString _key;
00056 SEL _selector;
00057 BOOL _ascending;
00058 }
00059
00060
00067 - (id)initWithKey:(CPString)aKey ascending:(BOOL)isAscending
00068 {
00069 return [self initWithKey:aKey ascending:isAscending selector:@selector(compare:)];
00070 }
00071
00079 - (id)initWithKey:(CPString)aKey ascending:(BOOL)isAscending selector:(SEL)aSelector
00080 {
00081 self = [super init];
00082
00083 if (self)
00084 {
00085 _key = aKey;
00086 _ascending = isAscending;
00087 _selector = aSelector;
00088 }
00089
00090 return self;
00091 }
00092
00093
00097 - (BOOL)ascending
00098 {
00099 return _ascending;
00100 }
00101
00105 - (CPString)key
00106 {
00107 return _key;
00108 }
00109
00113 - (SEL)selector
00114 {
00115 return _selector;
00116 }
00117
00118
00125 - (CPComparisonResult)compareObject:(id)lhsObject withObject:(id)rhsObject
00126 {
00127 return (_ascending ? 1 : -1) * [[lhsObject valueForKey:_key] performSelector:_selector withObject:[rhsObject valueForKey:_key]];
00128 }
00129
00134 - (id)reversedSortDescriptor
00135 {
00136 return [[[self class] alloc] initWithKey:_key ascending:!_ascending selector:_selector];
00137 }
00138
00139 @end