From 6e201c4e711efdd9dc9775ad62a77da0411a50fc Mon Sep 17 00:00:00 2001 From: helge Date: Sat, 2 Dec 2006 17:32:46 +0000 Subject: [PATCH] added NSDecimalNumber computeSumForKey git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1384 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-core/EOControl/ChangeLog | 6 ++++++ sope-core/EOControl/EOKeyValueCoding.m | 27 ++++++++++++++++++++++++-- sope-core/EOControl/Version | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/sope-core/EOControl/ChangeLog b/sope-core/EOControl/ChangeLog index 8d8da17d..92a267cc 100644 --- a/sope-core/EOControl/ChangeLog +++ b/sope-core/EOControl/ChangeLog @@ -1,3 +1,9 @@ +2006-12-02 Helge Hess + + * EOKeyValueCoding.m: added NSDecimalNumber implementation for + -computeSumForKey: (TBD: implementations for the other methods) + (v4.5.69) + 2006-09-30 Helge Hess * EOKeyGlobalID.m: print a warning if a key-gid is created with a nil diff --git a/sope-core/EOControl/EOKeyValueCoding.m b/sope-core/EOControl/EOKeyValueCoding.m index 6530635e..5e1cdb67 100644 --- a/sope-core/EOControl/EOKeyValueCoding.m +++ b/sope-core/EOControl/EOKeyValueCoding.m @@ -867,6 +867,7 @@ 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; if (cc == 0) return [NSNumber numberWithDouble:0.0]; @@ -880,6 +881,28 @@ static inline BOOL setValue(NSString* key, id instance, id value) 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 { @@ -928,11 +951,11 @@ static inline BOOL setValue(NSString* key, id instance, id value) unsigned i, cc = [self count]; 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]; for (i = 1; i < cc; i++) { register double ov; diff --git a/sope-core/EOControl/Version b/sope-core/EOControl/Version index f4e13957..0817bde0 100644 --- a/sope-core/EOControl/Version +++ b/sope-core/EOControl/Version @@ -1,3 +1,3 @@ # version file -SUBMINOR_VERSION:=68 +SUBMINOR_VERSION:=69 -- 2.39.5