Merge branch 'master' of github.com:gnustep/libs-base into NSByteCountFormatter_branch

This commit is contained in:
Gregory John Casamento 2019-07-15 02:12:57 -04:00
commit e5acbf27eb
2 changed files with 32 additions and 122 deletions

View file

@ -1,3 +1,9 @@
2019-07-01 Fred Kiefer <fredkiefer@gmx.de>
* Source/NSUbiquitousKeyValueStore.m: Change to use GNUstep
formatting. Move simple methods into base class. Correct the usage
of long long NSNumber.
2019-07-10 Gregory Casamento <greg.casamento@gmail.com> 2019-07-10 Gregory Casamento <greg.casamento@gmail.com>
* Headers/Foundation/NSUbiquitousKeyValueStore.h * Headers/Foundation/NSUbiquitousKeyValueStore.h

View file

@ -43,7 +43,7 @@ static NSUbiquitousKeyValueStore *_sharedUbiquitousKeyValueStore = nil;
// Getting the Shared Instance // Getting the Shared Instance
- (id) init - (id) init
{ {
if((self = [super init]) != nil) if ((self = [super init]) != nil)
{ {
} }
return self; return self;
@ -51,14 +51,14 @@ static NSUbiquitousKeyValueStore *_sharedUbiquitousKeyValueStore = nil;
+ (NSUbiquitousKeyValueStore *) defaultStore + (NSUbiquitousKeyValueStore *) defaultStore
{ {
if(_sharedUbiquitousKeyValueStore == nil) if (_sharedUbiquitousKeyValueStore == nil)
{ {
NSString *storeClassName = [[NSUserDefaults standardUserDefaults] NSString *storeClassName = [[NSUserDefaults standardUserDefaults]
stringForKey: @"GSUbiquitousKeyValueStoreClass"]; stringForKey: @"GSUbiquitousKeyValueStoreClass"];
Class klass = (storeClassName != nil) ? NSClassFromString(storeClassName) : Class klass = (storeClassName != nil) ? NSClassFromString(storeClassName) :
NSClassFromString(@"GSSimpleUbiquitousKeyValueStore"); NSClassFromString(@"GSSimpleUbiquitousKeyValueStore");
_sharedUbiquitousKeyValueStore = [[klass alloc] init]; _sharedUbiquitousKeyValueStore = [[klass alloc] init];
if(_sharedUbiquitousKeyValueStore == nil) if (_sharedUbiquitousKeyValueStore == nil)
{ {
NSLog(@"Cannot instantiate class shared key store"); NSLog(@"Cannot instantiate class shared key store");
} }
@ -70,43 +70,37 @@ static NSUbiquitousKeyValueStore *_sharedUbiquitousKeyValueStore = nil;
// Returns the array associated with the specified key. // Returns the array associated with the specified key.
- (NSArray *) arrayForKey: (NSString *)key - (NSArray *) arrayForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return (NSArray *)[self objectForKey: key];
return nil;
} }
// Returns the Boolean value associated with the specified key. // Returns the Boolean value associated with the specified key.
- (BOOL) boolForKey: (NSString *)key - (BOOL) boolForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return (BOOL)([[self objectForKey: key] boolValue] == 1);
return NO;
} }
// Returns the data object associated with the specified key. // Returns the data object associated with the specified key.
- (NSData*) dataForKey: (NSString *)key - (NSData*) dataForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return (NSData *)[self objectForKey: key];
return nil;
} }
// Returns the dictionary object associated with the specified key. // Returns the dictionary object associated with the specified key.
- (NSDictionary *) dictionaryForKey: (NSString *)key - (NSDictionary *) dictionaryForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return (NSDictionary *)[self objectForKey: key];
return nil;
} }
// Returns the double value associated with the specified key. // Returns the double value associated with the specified key.
- (double) doubleForKey: (NSString *)key - (double) doubleForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return [[self objectForKey: key] doubleValue];
return 0.0;
} }
// Returns the long long value associated with the specified key. // Returns the long long value associated with the specified key.
- (long long) longLongForKey: (NSString *)key - (long long) longLongForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return [[self objectForKey: key] longLongValue];
return 0.0;
} }
// Returns the object associated with the specified key. // Returns the object associated with the specified key.
@ -119,44 +113,47 @@ static NSUbiquitousKeyValueStore *_sharedUbiquitousKeyValueStore = nil;
// Returns the string associated with the specified key. // Returns the string associated with the specified key.
- (NSString *) stringForKey: (NSString *)key - (NSString *) stringForKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; return (NSString *)[self objectForKey: key];
return nil;
} }
// Setting Values // Setting Values
// Sets an array object for the specified key in the key-value store. // Sets an array object for the specified key in the key-value store.
- (void) setArray: (NSArray *)array forKey: (NSString *)key - (void) setArray: (NSArray *)array forKey: (NSString *)key
{ {
[self setObject: array forKey: key];
} }
// Sets a Boolean value for the specified key in the key-value store. // Sets a Boolean value for the specified key in the key-value store.
- (void) setBool: (BOOL)flag forKey: (NSString *)key - (void) setBool: (BOOL)flag forKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; NSNumber *num = [NSNumber numberWithBool: flag];
[self setObject: num forKey: key];
} }
// Sets a data object for the specified key in the key-value store. // Sets a data object for the specified key in the key-value store.
- (void) setData: (NSData *)data forKey: (NSString *)key - (void) setData: (NSData *)data forKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; [self setObject: data forKey: key];
} }
// Sets a dictionary object for the specified key in the key-value store. // Sets a dictionary object for the specified key in the key-value store.
- (void) setDictionary: (NSDictionary *)dict forKey: (NSString *)key - (void) setDictionary: (NSDictionary *)dict forKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; [self setObject: dict forKey: key];
} }
// Sets a double value for the specified key in the key-value store. // Sets a double value for the specified key in the key-value store.
- (void) setDouble: (double)val forKey: (NSString *)key - (void) setDouble: (double)val forKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; NSNumber *num = [NSNumber numberWithDouble: val];
[self setObject: num forKey: key];
} }
// Sets a long long value for the specified key in the key-value store. // Sets a long long value for the specified key in the key-value store.
- (void) setLongLong: (long long)val forKey: (NSString *)key - (void) setLongLong: (long long)val forKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; NSNumber *num = [NSNumber numberWithLongLong: val];
[self setObject: num forKey: key];
} }
// Sets an object for the specified key in the key-value store. // Sets an object for the specified key in the key-value store.
@ -168,7 +165,7 @@ static NSUbiquitousKeyValueStore *_sharedUbiquitousKeyValueStore = nil;
// Sets a string object for the specified key in the key-value store. // Sets a string object for the specified key in the key-value store.
- (void) setString: (NSString *)string forKey: (NSString *)key - (void) setString: (NSString *)string forKey: (NSString *)key
{ {
[self subclassResponsibility: _cmd]; [self setObject: string forKey: key];
} }
// Explicitly Synchronizing In-Memory Key-Value Data to Disk // Explicitly Synchronizing In-Memory Key-Value Data to Disk
@ -193,10 +190,6 @@ static NSUbiquitousKeyValueStore *_sharedUbiquitousKeyValueStore = nil;
return nil; return nil;
} }
// Notifications & constants
GS_EXPORT NSString* const NSUbiquitousKeyValueStoreDidChangeExternallyNotification;
GS_EXPORT NSString* const NSUbiquitousKeyValueStoreChangeReasonKey;
@end @end
@interface GSSimpleUbiquitousKeyValueStore : NSUbiquitousKeyValueStore @interface GSSimpleUbiquitousKeyValueStore : NSUbiquitousKeyValueStore
@ -217,107 +210,18 @@ GS_EXPORT NSString* const NSUbiquitousKeyValueStoreChangeReasonKey;
return self; return self;
} }
// Getting Values
// Returns the array associated with the specified key.
- (NSArray *) arrayForKey: (NSString *)key
{
return (NSArray *)[_dict objectForKey: key];
}
// Returns the Boolean value associated with the specified key.
- (BOOL) boolForKey: (NSString *)key
{
return (BOOL)([[_dict objectForKey: key] boolValue] == 1);
}
// Returns the data object associated with the specified key.
- (NSData*) dataForKey: (NSString *)key
{
return (NSData *)[_dict objectForKey: key];
}
// Returns the dictionary object associated with the specified key.
- (NSDictionary *) dictionaryForKey: (NSString *)key
{
return (NSDictionary *)[_dict objectForKey: key];
}
// Returns the double value associated with the specified key.
- (double) doubleForKey: (NSString *)key
{
return (double)[[_dict objectForKey: key] doubleValue];
}
// Returns the long long value associated with the specified key.
- (long long) longLongForKey: (NSString *)key
{
return (long long)[[_dict objectForKey: key] longValue];
}
// Returns the object associated with the specified key. // Returns the object associated with the specified key.
- (id) objectForKey: (NSString *)key - (id) objectForKey: (NSString *)key
{ {
return [_dict objectForKey: key]; return [_dict objectForKey: key];
} }
// Returns the string associated with the specified key.
- (NSString *) stringForKey: (NSString *)key
{
return (NSString *)[_dict objectForKey: key];
}
// Setting Values
// Sets an array object for the specified key in the key-value store.
- (void) setArray: (NSArray *)array forKey: (NSString *)key
{
[_dict setObject: array forKey: key];
}
// Sets a Boolean value for the specified key in the key-value store.
- (void) setBool: (BOOL)flag forKey: (NSString *)key
{
NSNumber *num = [NSNumber numberWithBool: flag];
[_dict setObject: num forKey: key];
}
// Sets a data object for the specified key in the key-value store.
- (void) setData: (NSData *)data forKey: (NSString *)key
{
[_dict setObject: data forKey: key];
}
// Sets a dictionary object for the specified key in the key-value store.
- (void) setDictionary: (NSDictionary *)dict forKey: (NSString *)key
{
[_dict setObject: dict forKey: key];
}
// Sets a double value for the specified key in the key-value store.
- (void) setDouble: (double)val forKey: (NSString *)key
{
NSNumber *num = [NSNumber numberWithDouble: val];
[_dict setObject: num forKey: key];
}
// Sets a long long value for the specified key in the key-value store.
- (void) setLongLong: (long long)val forKey: (NSString *)key
{
NSNumber *num = [NSNumber numberWithLong: val];
[_dict setObject: num forKey: key];
}
// Sets an object for the specified key in the key-value store. // Sets an object for the specified key in the key-value store.
- (void) setObject: (id) obj forKey: (NSString *)key - (void) setObject: (id) obj forKey: (NSString *)key
{ {
[_dict setObject: obj forKey: key]; [_dict setObject: obj forKey: key];
} }
// Sets a string object for the specified key in the key-value store.
- (void) setString: (NSString *)string forKey: (NSString *)key
{
[_dict setObject: string forKey: key];
}
// Explicitly Synchronizing In-Memory Key-Value Data to Disk // Explicitly Synchronizing In-Memory Key-Value Data to Disk
// Explicitly synchronizes in-memory keys and values with those stored on disk. // Explicitly synchronizes in-memory keys and values with those stored on disk.
- (void) synchronize - (void) synchronize