From: znek Date: Sat, 2 Dec 2006 18:56:36 +0000 (+0000) Subject: various bugfixes for the computeXXX: methods, proper implementations for Foundations... X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=710ae204ab16a077adf26f6a2d6ef3affc5ee96f;p=sope various bugfixes for the computeXXX: methods, proper implementations for Foundations other than libFoundation. git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1385 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-core/EOControl/ChangeLog b/sope-core/EOControl/ChangeLog index 92a267cc..e742bdf5 100644 --- a/sope-core/EOControl/ChangeLog +++ b/sope-core/EOControl/ChangeLog @@ -1,3 +1,9 @@ +2006-12-02 Marcus Mueller + + * EOKeyValueCoding.m: fixed numerous bugs in the computeXXX: methods + and provided proper implementations according to the WO4.5 specs + for gnustep-base and Apple Foundation (v4.5.70) + 2006-12-02 Helge Hess * EOKeyValueCoding.m: added NSDecimalNumber implementation for diff --git a/sope-core/EOControl/EOControl.xcodeproj/project.pbxproj b/sope-core/EOControl/EOControl.xcodeproj/project.pbxproj index 7e7c3dee..46ba9dd9 100644 --- a/sope-core/EOControl/EOControl.xcodeproj/project.pbxproj +++ b/sope-core/EOControl/EOControl.xcodeproj/project.pbxproj @@ -57,53 +57,6 @@ ADDF445D06DA511D00C4E7F8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADDF445C06DA511D00C4E7F8 /* Foundation.framework */; }; /* End PBXBuildFile section */ -/* Begin PBXBuildStyle section */ - ADDF431206DA4E2000C4E7F8 /* Development */ = { - isa = PBXBuildStyle; - buildSettings = { - COPY_PHASE_STRIP = NO; - GCC_GENERATE_DEBUGGING_SYMBOLS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "APPLE_RUNTIME=1", - "NeXT_Foundation_LIBRARY=1", - "COCOA_Foundation_LIBRARY=1", - "NeXT_RUNTIME=1", - "COMPILE_AS_FRAMEWORK=1", - "DEBUG=1", - ); - }; - name = Development; - }; - ADDF431306DA4E2000C4E7F8 /* Wrapper */ = { - isa = PBXBuildStyle; - buildSettings = { - COPY_PHASE_STRIP = YES; - DEPLOYMENT_LOCATION = NO; - DEPLOYMENT_POSTPROCESSING = YES; - DSTROOT = /; - DYLIB_INSTALL_NAME_BASE = "@executable_path/../Frameworks/"; - FRAMEWORK_SEARCH_PATHS = "$(USER_LIBRARY_DIR)/EmbeddedFrameworks"; - GCC_ENABLE_FIX_AND_CONTINUE = NO; - GCC_GENERATE_DEBUGGING_SYMBOLS = NO; - GCC_OPTIMIZATION_LEVEL = 3; - GCC_PREPROCESSOR_DEFINITIONS = ( - "APPLE_RUNTIME=1", - "NeXT_Foundation_LIBRARY=1", - "COCOA_Foundation_LIBRARY=1", - "NeXT_RUNTIME=1", - "COMPILE_AS_FRAMEWORK=1", - ); - SKIP_INSTALL = YES; - SYMROOT = "$(USER_LIBRARY_DIR)/EmbeddedFrameworks"; - TEMP_DIR = "$(SYMROOT)/$(PROJECT_NAME).build"; - UNSTRIPPED_PRODUCT = NO; - ZERO_LINK = NO; - }; - name = Wrapper; - }; -/* End PBXBuildStyle section */ - /* Begin PBXFileReference section */ ADDF431F06DA4E3500C4E7F8 /* EOControl.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EOControl.framework; sourceTree = BUILT_PRODUCTS_DIR; }; ADDF432106DA4E3500C4E7F8 /* EOControl-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "EOControl-Info.plist"; sourceTree = ""; }; @@ -339,53 +292,11 @@ ); buildRules = ( ); - buildSettings = { - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.64; - FRAMEWORK_VERSION = A; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = common.h; - GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO; - GCC_WARN_UNKNOWN_PRAGMAS = NO; - INFOPLIST_FILE = "EOControl-Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - OTHER_CFLAGS = ""; - OTHER_LDFLAGS = ( - "-seg1addr", - 0xC1000000, - "-headerpad_max_install_names", - ); - OTHER_REZFLAGS = ""; - PRODUCT_NAME = EOControl; - SECTORDER_FLAGS = ""; - WARNING_CFLAGS = "-Wmost"; - }; dependencies = ( ); name = EOControl; productName = EOControl; productReference = ADDF431F06DA4E3500C4E7F8 /* EOControl.framework */; - productSettingsXML = " - - - - CFBundleDevelopmentRegion - English - CFBundleExecutable - EOControl - CFBundleIdentifier - com.yourcompany.EOControl - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - FMWK - CFBundleSignature - ???? - CFBundleVersion - 1.0 - - -"; productType = "com.apple.product-type.framework"; }; /* End PBXNativeTarget section */ @@ -394,12 +305,6 @@ ADDF431406DA4E2000C4E7F8 /* Project object */ = { isa = PBXProject; buildConfigurationList = ADA077C30857382200993825 /* Build configuration list for PBXProject "EOControl" */; - buildSettings = { - }; - buildStyles = ( - ADDF431206DA4E2000C4E7F8 /* Development */, - ADDF431306DA4E2000C4E7F8 /* Wrapper */, - ); hasScannedForEncodings = 0; mainGroup = ADDF431006DA4E2000C4E7F8; productRefGroup = ADDF432006DA4E3500C4E7F8 /* Products */; @@ -465,7 +370,7 @@ buildSettings = { COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.64; + DYLIB_CURRENT_VERSION = 4.5.70; FRAMEWORK_VERSION = A; GCC_GENERATE_DEBUGGING_SYMBOLS = YES; GCC_OPTIMIZATION_LEVEL = 0; @@ -504,7 +409,7 @@ DEPLOYMENT_POSTPROCESSING = YES; DSTROOT = /; DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.64; + DYLIB_CURRENT_VERSION = 4.5.70; DYLIB_INSTALL_NAME_BASE = "@executable_path/../Frameworks/"; FRAMEWORK_SEARCH_PATHS = "$(USER_LIBRARY_DIR)/EmbeddedFrameworks"; FRAMEWORK_VERSION = A; @@ -546,7 +451,7 @@ isa = XCBuildConfiguration; buildSettings = { DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 4.5.64; + DYLIB_CURRENT_VERSION = 4.5.70; FRAMEWORK_VERSION = A; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = common.h; diff --git a/sope-core/EOControl/EOKeyValueCoding.m b/sope-core/EOControl/EOKeyValueCoding.m index 5e1cdb67..c790f614 100644 --- a/sope-core/EOControl/EOKeyValueCoding.m +++ b/sope-core/EOControl/EOKeyValueCoding.m @@ -866,62 +866,31 @@ static inline BOOL setValue(NSString* key, id instance, id value) - (id)computeSumForKey:(NSString *)_key { unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); -#if LIB_FOUNDATION_LIBRARY - double sum; + id (*objAtIdx)(id, SEL, unsigned int); + double sum; if (cc == 0) return [NSNumber numberWithDouble:0.0]; - + objAtIdx = (void*)[self methodForSelector:@selector(objectAtIndex:)]; for (i = 0, sum = 0.0; i < cc; i++) { register id o; o = objAtIdx(self, @selector(objectAtIndex:), i); + o = [o valueForKey:_key]; sum += [o doubleValue]; } return [NSNumber numberWithDouble:sum]; -#else - NSDecimalNumber *n; - - n = [NSDecimalNumber zero] - if (cc == 0) return n; - - objAtIdx = (void*)[self methodForSelector:@selector(objectAtIndex:)]; - - for (i = 0, sum = 0.0; i < cc; i++) { - register id o; - - o = objAtIdx(self, @selector(objectAtIndex:), i); - - if ([o isKindOfClass:[NSDecimalNumber class]]) - n = [n decimalNumberByAdding:o]; - else { - n = [n decimalNumberByAdding: - [NSDecimalNumber numberWithDouble:[o doubleValue]]]; - } - } - return n; -#endif } - (id)computeAvgForKey:(NSString *)_key { - unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double sum; + unsigned cc = [self count]; + NSNumber *sum; - if (cc == 0) return [NSNumber numberWithDouble:0.0]; + if (cc == 0) return nil; - objAtIdx = (void *)[self methodForSelector:@selector(objectAtIndex:)]; - - for (i = 0, sum = 0.0; i < cc; i++) { - register id o; - - o = objAtIdx(self, @selector(objectAtIndex:), i); - - sum += [o doubleValue]; - } - return [NSNumber numberWithDouble:(sum / (double)cc)]; + sum = [self computeSumForKey:_key]; + return [NSNumber numberWithDouble:([sum doubleValue] / (double)cc)]; } - (id)computeCountForKey:(NSString *)_key { @@ -930,18 +899,20 @@ static inline BOOL setValue(NSString* key, id instance, id value) - (id)computeMaxForKey:(NSString *)_key { unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double max; + id (*objAtIdx)(id, SEL, unsigned int); + double max; if (cc == 0) return nil; objAtIdx = (void *)[self methodForSelector:@selector(objectAtIndex:)]; - max = [objAtIdx(self, @selector(objectAtIndex:), 0) doubleValue]; + max = [[objAtIdx(self, @selector(objectAtIndex:), 0) valueForKey:_key] + doubleValue]; for (i = 1; i < cc; i++) { register double ov; - ov = [objAtIdx(self, @selector(objectAtIndex:), i) doubleValue]; + ov = [[objAtIdx(self, @selector(objectAtIndex:), i) valueForKey:_key] + doubleValue]; if (ov > max) max = ov; } return [NSNumber numberWithDouble:max]; @@ -949,18 +920,20 @@ static inline BOOL setValue(NSString* key, id instance, id value) - (id)computeMinForKey:(NSString *)_key { unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double min; - + id (*objAtIdx)(id, SEL, unsigned int); + double min; + if (cc == 0) return nil; objAtIdx = (void *)[self methodForSelector:@selector(objectAtIndex:)]; - min = [objAtIdx(self, @selector(objectAtIndex:), 0) doubleValue]; + min = [[objAtIdx(self, @selector(objectAtIndex:), 0) valueForKey:_key] + doubleValue]; for (i = 1; i < cc; i++) { register double ov; - ov = [objAtIdx(self, @selector(objectAtIndex:), i) doubleValue]; + ov = [[objAtIdx(self, @selector(objectAtIndex:), i) valueForKey:_key] + doubleValue]; if (ov < min) min = ov; } return [NSNumber numberWithDouble:min]; @@ -1447,41 +1420,47 @@ static void doubleIvarSetFunc(void* info1, void* info2, id self, id val) { @implementation NSArray(EOKeyValueCoding) +static Class NSDecimalNumberClass = Nil; + ++ (void)initialize { + static BOOL didInit = NO; + if (didInit) return; + didInit = YES; + NSDecimalNumberClass = [NSDecimalNumber class]; +} + - (id)computeSumForKey:(NSString *)_key { - unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double sum; + id (*objAtIdx)(id, SEL, unsigned int); + unsigned i, cc = [self count]; + NSDecimalNumber *sum; + + sum = [NSDecimalNumber zero]; + if (cc == 0) return sum; - if (cc == 0) return [NSNumber numberWithDouble:0.0]; - objAtIdx = (void*)[self methodForSelector:@selector(objectAtIndex:)]; - - for (i = 0, sum = 0.0; i < cc; i++) { + + for (i = 0; i < cc; i++) { register id o; - + o = objAtIdx(self, @selector(objectAtIndex:), i); - sum += [o doubleValue]; + o = [o valueForKey:_key]; + + if (![o isKindOfClass:NSDecimalNumberClass]) + o = (NSDecimalNumber *)[NSDecimalNumber numberWithDouble:[o doubleValue]]; + sum = [sum decimalNumberByAdding:o]; } - return [NSNumber numberWithDouble:sum]; + return sum; } - (id)computeAvgForKey:(NSString *)_key { - unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double sum; - - if (cc == 0) return [NSNumber numberWithDouble:0.0]; - - objAtIdx = (void *)[self methodForSelector:@selector(objectAtIndex:)]; + unsigned cc = [self count]; + NSDecimalNumber *sum, *div; - for (i = 0, sum = 0.0; i < cc; i++) { - register id o; - - o = objAtIdx(self, @selector(objectAtIndex:), i); - - sum += [o doubleValue]; - } - return [NSNumber numberWithDouble:(sum / (double)cc)]; + if (cc == 0) return nil; + + sum = [self computeSumForKey:_key]; + div = (NSDecimalNumber *)[NSDecimalNumber numberWithUnsignedInt:cc]; + return [sum decimalNumberByDividingBy:div]; } - (id)computeCountForKey:(NSString *)_key { @@ -1489,41 +1468,43 @@ static void doubleIvarSetFunc(void* info1, void* info2, id self, id val) { } - (id)computeMaxForKey:(NSString *)_key { - unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double max; - + id (*objAtIdx)(id, SEL, unsigned int); + unsigned i, cc = [self count]; + NSDecimalNumber *max; + if (cc == 0) return nil; - - objAtIdx = (void *)[self methodForSelector:@selector(objectAtIndex:)]; - max = [objAtIdx(self, @selector(objectAtIndex:), 0) doubleValue]; + objAtIdx = (void*)[self methodForSelector:@selector(objectAtIndex:)]; + max = [objAtIdx(self, @selector(objectAtIndex:), 0) valueForKey:_key]; + for (i = 1; i < cc; i++) { - register double ov; + register id o; - ov = [objAtIdx(self, @selector(objectAtIndex:), i) doubleValue]; - if (ov > max) max = ov; + o = [objAtIdx(self, @selector(objectAtIndex:), i) valueForKey:_key]; + if ([max compare:o] == NSOrderedAscending) + max = o; } - return [NSNumber numberWithDouble:max]; + return max; } - (id)computeMinForKey:(NSString *)_key { - unsigned i, cc = [self count]; - id (*objAtIdx)(id, SEL, unsigned int); - double min; - + id (*objAtIdx)(id, SEL, unsigned int); + unsigned i, cc = [self count]; + NSDecimalNumber *min; + if (cc == 0) return nil; - objAtIdx = (void *)[self methodForSelector:@selector(objectAtIndex:)]; - - min = [objAtIdx(self, @selector(objectAtIndex:), 0) doubleValue]; + objAtIdx = (void*)[self methodForSelector:@selector(objectAtIndex:)]; + min = [objAtIdx(self, @selector(objectAtIndex:), 0) valueForKey:_key]; + for (i = 1; i < cc; i++) { - register double ov; - - ov = [objAtIdx(self, @selector(objectAtIndex:), i) doubleValue]; - if (ov < min) min = ov; + register id o; + + o = [objAtIdx(self, @selector(objectAtIndex:), i) valueForKey:_key]; + if ([min compare:o] == NSOrderedDescending) + min = o; } - return [NSNumber numberWithDouble:min]; + return min; } - (id)valueForKey:(NSString *)_key { diff --git a/sope-core/EOControl/Version b/sope-core/EOControl/Version index 0817bde0..51ff5d23 100644 --- a/sope-core/EOControl/Version +++ b/sope-core/EOControl/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=69 +SUBMINOR_VERSION:=70