diff --git a/ChangeLog b/ChangeLog index ba24be4f1..1c0b64177 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2000-12-02 Richard Frith-Macdonald + + * Source/NSDate.m: GSTime() added millisecond info. + * Source/NSCalendarDate.m: GSTime() added millisecond info. + * Headers/Foundation/NSDate.h: GSTime() added millisecond info. + * Source/NSObject.m: key-value-coding restructured to simplify + future implementation for non-object values. + 2000-11-30 Richard Frith-Macdonald * Source/NSCalendarDate.m: ([-initWithString:calendarFormat:locale:]) diff --git a/Headers/gnustep/base/NSDate.h b/Headers/gnustep/base/NSDate.h index 561fb6f45..41da850c0 100644 --- a/Headers/gnustep/base/NSDate.h +++ b/Headers/gnustep/base/NSDate.h @@ -107,7 +107,7 @@ typedef double NSTimeInterval; @end NSTimeInterval GSTimeNow(); /* Get time since reference date*/ -NSTimeInterval GSTime(int day, int mon, int year, int hour, int min, int sec); +NSTimeInterval GSTime(int d, int m, int y, int hh, int mm, int ss, int mil); #endif diff --git a/Source/NSCalendarDate.m b/Source/NSCalendarDate.m index a37acab82..a19bfa7ea 100644 --- a/Source/NSCalendarDate.m +++ b/Source/NSCalendarDate.m @@ -86,7 +86,7 @@ absoluteGregorianDay(int day, int month, int year) * External - so NSDate can use it. */ NSTimeInterval -GSTime(int day, int month, int year, int h, int m, int s) +GSTime(int day, int month, int year, int h, int m, int s, int mil) { NSTimeInterval a; @@ -98,6 +98,7 @@ GSTime(int day, int month, int year, int h, int m, int s) a += h * 3600; a += m * 60; a += s; + a += mil/1000.0; return a; } @@ -932,7 +933,7 @@ static inline int getDigits(const char *from, char *to, int limit) NSTimeInterval s; // Calculate date as GMT - s = GSTime(day, month, year, hour, minute, second); + s = GSTime(day, month, year, hour, minute, second, 0); // Assign time zone detail _time_zone = RETAIN([aTimeZone diff --git a/Source/NSDate.m b/Source/NSDate.m index d29bed5c3..cbb5aae85 100644 --- a/Source/NSDate.m +++ b/Source/NSDate.m @@ -147,8 +147,8 @@ GSTimeNow() * Get current GMT time, convert to NSTimeInterval since reference date, */ GetSystemTime(&sys_time); - t = GSTime(sys_time.wDay, sys_time.wMonth, sys_time.wYear, - sys_time.wHour, sys_time.wMinute, sys_time.wSecond); + t = GSTime(sys_time.wDay, sys_time.wMonth, sys_time.wYear, sys_time.wHour, + sys_time.wMinute, sys_time.wSecond, sys_time.wMilliseconds); #endif return t + sys_time.wMilliseconds / 1000.0; #endif /* __MINGW__ */ diff --git a/Source/NSObject.m b/Source/NSObject.m index d3767f724..648c70aa4 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -1375,7 +1375,9 @@ static BOOL deallocNotifications = NO; - (void) takeStoredValue: (id)anObject forKey: (NSString*)aKey { - SEL sel; + SEL sel = 0; + const char *type = 0; + NSString *name; if ([[self class] useStoredAccessor] == NO) { @@ -1383,72 +1385,87 @@ static BOOL deallocNotifications = NO; return; } - sel = NSSelectorFromString([NSString stringWithFormat: @"_set%@:", - [aKey capitalizedString]]); - if ([self respondsToSelector: sel] == YES) + name = [NSString stringWithFormat: @"_set%@:", [aKey capitalizedString]]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) { - [self performSelector: sel withObject: anObject]; - return; - } - - if ([[self class] accessInstanceVariablesDirectly] == YES) - { - if (GSSetInstanceVariable(self, [NSString stringWithFormat: @"_%@", aKey], - (void*)&anObject) == YES) + sel = 0; + if ([[self class] accessInstanceVariablesDirectly] == YES) { - return; + name = [NSString stringWithFormat: @"_%@", aKey]; + type = GSInstanceVariableType(self, name); + if (type == 0) + { + name = aKey; + type = GSInstanceVariableType(self, name); + } } - if (GSSetInstanceVariable(self, aKey, (void*)&anObject) == YES) + if (type == 0) { - return; + name = [NSString stringWithFormat: @"set%@:", + [aKey capitalizedString]]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) + { + sel = 0; + } } } - sel = NSSelectorFromString([NSString stringWithFormat: @"set%@:", - [aKey capitalizedString]]); - if ([self respondsToSelector: sel] == YES) + if (sel != 0) { [self performSelector: sel withObject: anObject]; - return; } - - [self handleTakeValue: anObject forUnboundKey: aKey]; + else if (type != 0) + { + GSSetInstanceVariable(self, name, (void*)&anObject); + } + else + { + [self handleTakeValue: anObject forUnboundKey: aKey]; + } } - (void) takeValue: (id)anObject forKey: (NSString*)aKey { - SEL sel; + SEL sel = 0; + const char *type = 0; + NSString *name = nil; - sel = NSSelectorFromString([NSString stringWithFormat: @"set%@:", - [aKey capitalizedString]]); - if ([self respondsToSelector: sel] == YES) + name = [NSString stringWithFormat: @"set%@:", [aKey capitalizedString]]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) { - [self performSelector: sel withObject: anObject]; - return; - } - - sel = NSSelectorFromString([NSString stringWithFormat: @"_set%@:", - [aKey capitalizedString]]); - if ([self respondsToSelector: sel] == YES) - { - [self performSelector: sel withObject: anObject]; - return; - } - - if ([[self class] accessInstanceVariablesDirectly] == YES) - { - if (GSSetInstanceVariable(self, [NSString stringWithFormat: @"_%@", aKey], - (void*)&anObject) == YES) + name = [NSString stringWithFormat: @"_set%@:", [aKey capitalizedString]]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) { - return; - } - if (GSSetInstanceVariable(self, aKey, (void*)&anObject) == YES) - { - return; + sel = 0; + if ([[self class] accessInstanceVariablesDirectly] == YES) + { + name = [NSString stringWithFormat: @"_%@", aKey]; + type = GSInstanceVariableType(self, name); + if (type == 0) + { + name = aKey; + type = GSInstanceVariableType(self, name); + } + } } } - [self handleTakeValue: anObject forUnboundKey: aKey]; + if (sel != 0) + { + [self performSelector: sel withObject: anObject]; + } + else if (type != 0) + { + GSSetInstanceVariable(self, name, (void*)&anObject); + } + else + { + [self handleTakeValue: anObject forUnboundKey: aKey]; + } } - (void) takeValue: (id)anObject forKeyPath: (NSString*)aKey @@ -1494,49 +1511,60 @@ static BOOL deallocNotifications = NO; - (id) valueForKey: (NSString*)aKey { - SEL sel; + SEL sel = 0; + NSString *name = nil; + const char *type = 0; - sel = NSSelectorFromString([NSString stringWithFormat: @"get%@", - [aKey capitalizedString]]); - if ([self respondsToSelector: sel] == YES) + name = [NSString stringWithFormat: @"get%@", [aKey capitalizedString]]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) { - return [self performSelector: sel]; - } - sel = NSSelectorFromString(aKey); - if ([self respondsToSelector: sel] == YES) - { - return [self performSelector: sel]; + name = aKey; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) + { + name = [NSString stringWithFormat: @"_get%@", + [aKey capitalizedString]]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) + { + name = [NSString stringWithFormat: @"_%@", aKey]; + sel = NSSelectorFromString(name); + if ([self respondsToSelector: sel] == NO) + { + sel = 0; + } + } + } } - sel = NSSelectorFromString([NSString stringWithFormat: @"_get%@", - [aKey capitalizedString]]); - if ([self respondsToSelector: sel] == YES) + if (sel == 0 && [[self class] accessInstanceVariablesDirectly] == YES) { - return [self performSelector: sel]; - } - sel = NSSelectorFromString([NSString stringWithFormat: @"_%@", aKey]); - if ([self respondsToSelector: sel] == YES) - { - return [self performSelector: sel]; + name = [NSString stringWithFormat: @"_%@", aKey]; + type = GSInstanceVariableType(self, name); + if (type == 0) + { + name = aKey; + type = GSInstanceVariableType(self, name); + } } - if ([[self class] accessInstanceVariablesDirectly] == YES) + if (sel != 0) + { + return [self performSelector: sel]; + } + else if (type != 0) { id v; - if (GSGetInstanceVariable(self, [NSString stringWithFormat: @"_%@", aKey], - (void*)&v) == YES) - { - return v; - } - if (GSGetInstanceVariable(self, aKey, (void*)&v) == YES) - { - return v; - } + GSGetInstanceVariable(self, name, (void*)&v); + return v; + } + else + { + [self handleTakeValue: nil forUnboundKey: aKey]; + return nil; } - - [self handleTakeValue: nil forUnboundKey: aKey]; - return nil; } - (id) valueForKeyPath: (NSString*)aKey