Merge branch 'master' into fix-enumeration-queue

This commit is contained in:
Fred Kiefer 2019-10-25 17:57:59 +02:00 committed by GitHub
commit 2fb200b705
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 3909 additions and 109 deletions

View file

@ -9,6 +9,13 @@
Perform non-concurrent block enumeration calls in place instead
of using serial queue to match Apple platforms.
2019-10-25 Frederik Seiffert <frederik@algoriddim.com>
* Headers/Foundation/NSMapTable.h:
* Headers/Foundation/NSHashTable.h:
Added generics support to NSMapTable and updated NSMapTable and
NSHashTable to use "instancetype".
2019-10-02 Frederik Seiffert <frederik@algoriddim.com>
* Source/NSDictionary.m: fixed mutable dictionary keyed subscript

View file

@ -55,12 +55,15 @@
#import <Foundation/NSConnection.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDateFormatter.h>
#import <Foundation/NSDateInterval.h>
#import <Foundation/NSDateIntervalFormatter.h>
#import <Foundation/NSDate.h>
#import <Foundation/NSDecimalNumber.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSDistantObject.h>
#import <Foundation/NSDistributedLock.h>
#import <Foundation/NSDistributedNotificationCenter.h>
#import <Foundation/NSEnergyFormatter.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSError.h>
#import <Foundation/NSException.h>
@ -86,9 +89,12 @@
#import <Foundation/NSKeyedArchiver.h>
#import <Foundation/NSKeyValueCoding.h>
#import <Foundation/NSKeyValueObserving.h>
#import <Foundation/NSLengthFormatter.h>
#import <Foundation/NSLock.h>
#import <Foundation/NSLocale.h>
#import <Foundation/NSMapTable.h>
#import <Foundation/NSMeasurement.h>
#import <Foundation/NSMeasurementFormatter.h>
#import <Foundation/NSMetadata.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSNotification.h>
@ -138,6 +144,7 @@
#import <Foundation/NSTimeZone.h>
#import <Foundation/NSUbiquitousKeyValueStore.h>
#import <Foundation/NSUndoManager.h>
#import <Foundation/NSUnit.h>
#import <Foundation/NSURLAuthenticationChallenge.h>
#import <Foundation/NSURLCache.h>
#import <Foundation/NSURLConnection.h>

View file

@ -20,9 +20,6 @@ NSAppleEventDescriptor.h
NSAppleEventManager.h
NSBackgroundActivityScheduler.h
NSDateComponentsFormatter.h
NSDateIntervalFormatter.h
NSDateInterval.h
NSEnergyFormatter.h
NSExtensionContext.h
NSExtensionItem.h
NSExtensionRequestHandling.h
@ -30,44 +27,10 @@ NSHFSFileTypes.h
NSISO8601DateFormatter.h
NSItemProvider.h
NSItemProviderReadingWriting.h
NSLengthFormatter.h
NSLinguisticTagger.h
NSMassFormatter.h
NSMeasurementFormatter.h
NSMeasurement.h
NSMetadataAttributes.h
NSObjectScripting.h
NSOrthography.h
NSUnit.h
NSUserActivity.h
NSXPCConnection.h
-------------------------------------------------------------
Foundation:
==
FoundationLegacySwiftCompatibility.h
NSAppleEventDescriptor.h
NSAppleEventManager.h
NSBackgroundActivityScheduler.h
NSDateComponentsFormatter.h
NSDateIntervalFormatter.h
NSDateInterval.h
NSEnergyFormatter.h
NSExtensionContext.h
NSExtensionItem.h
NSExtensionRequestHandling.h
NSHFSFileTypes.h
NSISO8601DateFormatter.h
NSItemProvider.h
NSItemProviderReadingWriting.h
NSLengthFormatter.h
NSLinguisticTagger.h
NSMassFormatter.h
NSMeasurementFormatter.h
NSMeasurement.h
NSMetadataAttributes.h
NSObjectScripting.h
NSOrthography.h
NSUnit.h
NSUserActivity.h
NSXPCConnection.h

View file

@ -62,7 +62,7 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
/** Returns an autoreleased instance with the current date/time.
*/
+ (id) date;
+ (instancetype) date;
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
/** Returns an autoreleased instance representing the date and time given
@ -70,7 +70,7 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
* specified by the preferences in the user defaults database, allowing
* phrases like 'last tuesday'
*/
+ (id) dateWithNaturalLanguageString: (NSString*)string;
+ (instancetype) dateWithNaturalLanguageString: (NSString*)string;
/**
* <p>Returns an autoreleased instance representing the date and time given
@ -119,47 +119,48 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
* </desc>
* </deflist>
*/
+ (id) dateWithNaturalLanguageString: (NSString*)string
locale: (NSDictionary*)locale;
+ (instancetype) dateWithNaturalLanguageString: (NSString*)string
locale: (NSDictionary*)locale;
#endif
/** Returns an autoreleased instance with the date and time value given
* by the string using the ISO standard format YYYY-MM-DD HH:MM:SS +/-HHHMM
* (all the fields of which must be present).
*/
+ (id) dateWithString: (NSString*)description;
+ (instancetype) dateWithString: (NSString*)description;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
/** Returns an autoreleased NSDate instance whose value is offset from
* that of the given date by the specified interval in seconds.
*/
+ (id) dateWithTimeInterval: (NSTimeInterval)seconds sinceDate: (NSDate*)date;
+ (instancetype) dateWithTimeInterval: (NSTimeInterval)seconds
sinceDate: (NSDate*)date;
#endif
/** Returns an autoreleased instance with the offset from the unix system
* reference date of 1 January 1970, GMT.
*/
+ (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds;
+ (instancetype) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds;
/** Returns an autoreleased instance with the offset from the current
* date/time given by seconds (which may be fractional).
*/
+ (id) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
+ (instancetype) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds;
/** Returns an autoreleased instance with the offset from the OpenStep
* reference date of 1 January 2001, GMT.
*/
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
+ (instancetype) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds;
/** Returns an autoreleased instance with the date/time set in the far
* past.
*/
+ (id) distantPast;
+ (instancetype) distantPast;
/** Returns an autoreleased instance with the date/time set in the far
* future.
*/
+ (id) distantFuture;
+ (instancetype) distantFuture;
/** Returns the time interval between the reference date and the current
* time.
@ -169,7 +170,7 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
/** Returns an autorelease date instance formed by adding the specified
* time interval in seconds to the receiver's time interval.
*/
- (id) addTimeInterval: (NSTimeInterval)seconds;
- (instancetype) addTimeInterval: (NSTimeInterval)seconds;
/** Returns the time interval between the receivers value and the
* OpenStep reference date of 1 Jan 2001 GMT.
@ -180,7 +181,7 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
/** Returns an autoreleased NSDate instance whose value is offset from
* that of the receiver by the specified interval.
*/
- (id) dateByAddingTimeInterval: (NSTimeInterval)ti;
- (instancetype) dateByAddingTimeInterval: (NSTimeInterval)ti;
#endif
/** Returns an autoreleased instance of the [NSCalendarDate] class whose
@ -214,35 +215,35 @@ GS_EXPORT const NSTimeInterval NSTimeIntervalSince1970;
/** Returns an instance initialised with the current date/time.
*/
- (id) init;
- (instancetype) init;
/** Returns an instance with the date and time value given
* by the string using the ISO standard format YYYY-MM-DD HH:MM:SS +/-HHHMM
* (all the fields of which must be present).
*/
- (id) initWithString: (NSString*)description;
- (instancetype) initWithString: (NSString*)description;
/** Returns an instance with the given offset from anotherDate.
*/
- (id) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
sinceDate: (NSDate*)anotherDate;
- (instancetype) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
sinceDate: (NSDate*)anotherDate;
#if OS_API_VERSION(GS_API_MACOSX, GS_API_LATEST)
/** Returns an instance with the offset from the unix system
* reference date of 1 January 1970, GMT.
*/
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds;
- (instancetype) initWithTimeIntervalSince1970: (NSTimeInterval)seconds;
#endif
/** Returns an instance with the offset from the current date/time.
*/
- (id) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
- (instancetype) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded;
/** <init />
* Returns an instance with the given offset from the OpenStep
* reference date of 1 January 2001, GMT.
*/
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs;
- (instancetype) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs;
/** Returns NO if other is not a date, otherwise returns the result of
* calling the -isEqualtoDate: method.

View file

@ -0,0 +1,84 @@
/* Definition of class NSDateInterval
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory Casamento <greg.casamento@gmail.com>
Date: Wed Oct 9 16:24:13 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSDateInterval_h_GNUSTEP_BASE_INCLUDE
#define _NSDateInterval_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#include <Foundation/NSDate.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
@interface NSDateInterval : NSObject <NSCoding, NSCopying>
{
NSTimeInterval _duration;
NSDate *_startDate;
}
// Init
- (instancetype) init;
- (instancetype) initWithStartDate: (NSDate *)startDate
duration: (NSTimeInterval)duration;
- (instancetype) initWithStartDate: (NSDate *)startDate
endDate: (NSDate *)endDate;
// Access
- (NSDate *) startDate;
- (void) setStartDate: (NSDate *)startDate;
- (NSDate *) endDate;
- (void) setEndDate: (NSDate *)endDate;
- (NSTimeInterval)duration;
- (void) setDuration: (NSTimeInterval)duration;
// Compare
- (NSComparisonResult) compare: (NSDateInterval *)dateInterval;
- (BOOL) isEqualToDateInterval: (NSDateInterval *)dateInterval;
// Determine
- (BOOL) intersectsDateInterval: (NSDateInterval *)dateInterval;
- (NSDateInterval *) intersectionWithDateInterval: (NSDateInterval *)dateInterval;
// Contain
- (BOOL) containsDate: (NSDate *)date;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSDateInterval_h_GNUSTEP_BASE_INCLUDE */

View file

@ -0,0 +1,91 @@
/* Definition of class NSDateIntervalFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: heron
Date: Wed Oct 9 16:23:55 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSDateIntervalFormatter_h_GNUSTEP_BASE_INCLUDE
#define _NSDateIntervalFormatter_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSFormatter.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
enum {
NSDateIntervalFormatterNoStyle = 0,
NSDateIntervalFormatterShortStyle = 1,
NSDateIntervalFormatterMediumStyle = 2,
NSDateIntervalFormatterLongStyle = 3,
NSDateIntervalFormatterFullStyle = 4
};
typedef NSUInteger NSDateIntervalFormatterStyle;
@class NSCalendar, NSLocale, NSDateInterval;
@interface NSDateIntervalFormatter : NSFormatter
{
NSLocale *_locale;
NSCalendar *_calendar;
NSTimeZone *_timeZone;
NSString *_dateTemplate;
NSDateIntervalFormatterStyle _dateStyle;
NSDateIntervalFormatterStyle _timeStyle;
}
// Properties
- (NSLocale *) locale;
- (void) setLocale: (NSLocale *)locale;
- (NSCalendar *) calendar;
- (void) setCalendar: (NSCalendar *)calendar;
- (NSTimeZone *) timeZone;
- (void) setTimeZone: (NSTimeZone *)timeZone;
- (NSString *) dateTemplate;
- (void) setDateTemplate: (NSString *)dateTemplate;
- (NSDateIntervalFormatterStyle) dateStyle;
- (void) setDateStyle: (NSDateIntervalFormatterStyle)dateStyle;
- (NSDateIntervalFormatterStyle) timeStyle;
- (void) setTimeStyle: (NSDateIntervalFormatterStyle)timeStyle;
// Create strings
- (NSString *)stringFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate;
- (NSString *)stringFromDateInterval:(NSDateInterval *)dateInterval;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSDateIntervalFormatter_h_GNUSTEP_BASE_INCLUDE */

View file

@ -0,0 +1,81 @@
/* Definition of class NSEnergyFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: heron
Date: Tue Oct 8 13:30:10 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSEnergyFormatter_h_GNUSTEP_BASE_INCLUDE
#define _NSEnergyFormatter_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSFormatter.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
@class NSNumberFormatter, NSString;
enum {
NSEnergyFormatterUnitJoule = 11,
NSEnergyFormatterUnitKilojoule = 14,
NSEnergyFormatterUnitCalorie = (7 << 8) + 1,
NSEnergyFormatterUnitKilocalorie = (7 << 8) + 2,
};
typedef NSInteger NSEnergyFormatterUnit;
@interface NSEnergyFormatter : NSFormatter
{
BOOL _isForFoodEnergyUse;
NSNumberFormatter *_numberFormatter;
NSFormattingUnitStyle _unitStyle;
}
- (NSNumberFormatter *) numberFormatter;
- (void) setNumberFormatter: (NSNumberFormatter *)formatter;
- (NSFormattingUnitStyle) unitStyle;
- (void) setUnitStyle: (NSFormattingUnitStyle)style;
- (BOOL) isForFoodEnergyUse;
- (void) setForFoodEnergyUse: (BOOL)flag;
- (NSString *) stringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit;
- (NSString *) stringFromJoules: (double)numberInJoules;
- (NSString *) unitStringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit;
- (NSString *) unitStringFromJoules: (double)numberInJoules usedUnit: (NSEnergyFormatterUnit *)unitp;
- (BOOL) getObjectValue:(id *)obj forString: (NSString *)string errorDescription: (NSString **)error;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSEnergyFormatter_h_GNUSTEP_BASE_INCLUDE */

View file

@ -63,23 +63,23 @@ typedef NSUInteger NSHashTableOptions;
@interface GS_GENERIC_CLASS(NSHashTable, ElementT) : NSObject <NSCopying, NSCoding, NSFastEnumeration>
+ (id) hashTableWithOptions: (NSPointerFunctionsOptions)options;
+ (instancetype) hashTableWithOptions: (NSPointerFunctionsOptions)options;
+ (id) hashTableWithWeakObjects;
+ (instancetype) hashTableWithWeakObjects;
/**
* Creates a hash table that uses zeroing weak references (either using the
* automatic reference counting or garbage collection mechanism, depending on
* which mode this framework is compiled in) so that objects are removed when
* their last other reference disappears.
*/
+ (id) weakObjectsHashTable;
+ (instancetype) weakObjectsHashTable;
- (id) initWithOptions: (NSPointerFunctionsOptions)options
capacity: (NSUInteger)initialCapacity;
- (instancetype) initWithOptions: (NSPointerFunctionsOptions)options
capacity: (NSUInteger)initialCapacity;
- (id) initWithPointerFunctions: (NSPointerFunctions*)functions
capacity: (NSUInteger)initialCapacity;
- (instancetype) initWithPointerFunctions: (NSPointerFunctions*)functions
capacity: (NSUInteger)initialCapacity;
/** Adds the object to the receiver.
*/

View file

@ -0,0 +1,84 @@
/* Definition of class NSLengthFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Tue Oct 8 13:30:33 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSLengthFormatter_h_GNUSTEP_BASE_INCLUDE
#define _NSLengthFormatter_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSFormatter.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
enum {
NSLengthFormatterUnitMillimeter = 8,
NSLengthFormatterUnitCentimeter = 9,
NSLengthFormatterUnitMeter = 11,
NSLengthFormatterUnitKilometer = 14,
NSLengthFormatterUnitInch = (5 << 8) + 1,
NSLengthFormatterUnitFoot = (5 << 8) + 2,
NSLengthFormatterUnitYard = (5 << 8) + 3,
NSLengthFormatterUnitMile = (5 << 8) + 4,
};
typedef NSInteger NSLengthFormatterUnit;
@class NSNumberFormatter, NSString;
@interface NSLengthFormatter : NSFormatter
{
BOOL _isForPersonHeightUse;
NSNumberFormatter *_numberFormatter;
NSFormattingUnitStyle _unitStyle;
}
- (NSNumberFormatter *) numberFormatter;
- (void) setNumberFormatter: (NSNumberFormatter *)formatter;
- (NSFormattingUnitStyle) unitStyle;
- (void) setUnitStyle: (NSFormattingUnitStyle)style;
- (BOOL) isForPersonHeightUse;
- (void) setForPersonHeightUse: (BOOL)flag;
- (NSString *) stringFromValue: (double)value unit: (NSLengthFormatterUnit)unit;
- (NSString *) stringFromMeters: (double)numberInMeters;
- (NSString *) unitStringFromValue: (double)value unit: (NSLengthFormatterUnit)unit;
- (NSString *) unitStringFromMeters: (double)numberInMeters usedUnit: (NSLengthFormatterUnit *)unit;
- (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSLengthFormatter_h_GNUSTEP_BASE_INCLUDE */

View file

@ -59,67 +59,68 @@ enum {
typedef NSUInteger NSMapTableOptions;
@interface NSMapTable : NSObject <NSCopying, NSCoding, NSFastEnumeration>
@interface GS_GENERIC_CLASS(NSMapTable, KeyT, ValT)
: NSObject <NSCopying, NSCoding, NSFastEnumeration>
/** Return a map table initialised using the specified options for
* keys and values.
*/
+ (id) mapTableWithKeyOptions: (NSPointerFunctionsOptions)keyOptions
valueOptions: (NSPointerFunctionsOptions)valueOptions;
+ (instancetype) mapTableWithKeyOptions: (NSPointerFunctionsOptions)keyOptions
valueOptions: (NSPointerFunctionsOptions)valueOptions;
/** Convenience method for creating a map table to store object values
* using object keys.
*/
+ (id) mapTableWithStrongToStrongObjects;
+ (instancetype) mapTableWithStrongToStrongObjects;
/** Convenience method for creating a map table to store non-retained
* object values with retained object keys.
*/
+ (id) mapTableWithStrongToWeakObjects;
+ (instancetype) mapTableWithStrongToWeakObjects;
/** Convenience method for creating a map table to store retained
* object values with non-retained object keys.
*/
+ (id) mapTableWithWeakToStrongObjects;
+ (instancetype) mapTableWithWeakToStrongObjects;
/** Convenience method for creating a map table to store non-retained
* object values with non-retained object keys.
*/
+ (id) mapTableWithWeakToWeakObjects;
+ (instancetype) mapTableWithWeakToWeakObjects;
/** Convenience method for creating a map table to store object values
* using object keys. The collection will retain both the key and the value.
*/
+ (id) strongToStrongObjectsMapTable;
+ (instancetype) strongToStrongObjectsMapTable;
/** Convenience method for creating a map table to store object values
* using object keys. The collection will retain the key, the value will be a
* zeroing weak reference.
*/
+ (id) strongToWeakObjectsMapTable;
+ (instancetype) strongToWeakObjectsMapTable;
/** Convenience method for creating a map table to store object values
* using object keys. The collection will retain the value, the key will be a
* zeroing weak reference.
*/
+ (id) weakToStrongObjectsMapTable;
+ (instancetype) weakToStrongObjectsMapTable;
/** Convenience method for creating a map table to store object values
* using object keys. The collection will use zeroing weak references for both
* the key and the value.
*/
+ (id) weakToWeakObjectsMapTable;
+ (instancetype) weakToWeakObjectsMapTable;
/** Initialiser using option bitmasks to describe the keys and values.
*/
- (id) initWithKeyOptions: (NSPointerFunctionsOptions)keyOptions
valueOptions: (NSPointerFunctionsOptions)valueOptions
capacity: (NSUInteger)initialCapacity;
- (instancetype) initWithKeyOptions: (NSPointerFunctionsOptions)keyOptions
valueOptions: (NSPointerFunctionsOptions)valueOptions
capacity: (NSUInteger)initialCapacity;
/** Initialiser using full pointer function information to describe
* the keys and values.
*/
- (id) initWithKeyPointerFunctions: (NSPointerFunctions*)keyFunctions
valuePointerFunctions: (NSPointerFunctions*)valueFunctions
capacity: (NSUInteger)initialCapacity;
- (instancetype) initWithKeyPointerFunctions: (NSPointerFunctions*)keyFunctions
valuePointerFunctions: (NSPointerFunctions*)valueFunctions
capacity: (NSUInteger)initialCapacity;
/** Return the number of items stored in the map.
*/
@ -131,7 +132,7 @@ typedef NSUInteger NSMapTableOptions;
/** Return an enumerator able to enumerate the keys in the receiver.
*/
- (NSEnumerator*) keyEnumerator;
- (GS_GENERIC_CLASS(NSEnumerator, KeyT)*) keyEnumerator;
/** Return an NSPointerFunctions value describind the functions used by the
* receiver to handle keys.
@ -140,11 +141,11 @@ typedef NSUInteger NSMapTableOptions;
/** Return an enumerator able to enumerate the values in the receiver.
*/
- (NSEnumerator*) objectEnumerator;
- (GS_GENERIC_CLASS(NSEnumerator, ValT)*) objectEnumerator;
/** Return the object stored under the specified key.
*/
- (id) objectForKey: (id)aKey;
- (GS_GENERIC_TYPE(ValT)) objectForKey: (GS_GENERIC_TYPE(KeyT))aKey;
/** Empty the receiver of all stored values.
*/
@ -152,12 +153,12 @@ typedef NSUInteger NSMapTableOptions;
/** Remove the object stored under the specified key.
*/
- (void) removeObjectForKey: (id)aKey;
- (void) removeObjectForKey: (GS_GENERIC_TYPE(KeyT))aKey;
/** Store the object under the specified key, replacing any object which
* was previously stored under that key.
*/
- (void) setObject: (id)anObject forKey: (id)aKey;
- (void) setObject: (GS_GENERIC_TYPE(ValT))anObject forKey: (GS_GENERIC_TYPE(KeyT))aKey;
/** Return an NSPointerFunctions value describind the functions used by the
* receiver to handle values.

View file

@ -0,0 +1,83 @@
/* Definition of class NSMassFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: heron
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSMassFormatter_h_GNUSTEP_BASE_INCLUDE
#define _NSMassFormatter_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSFormatter.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
enum {
NSMassFormatterUnitGram = 11,
NSMassFormatterUnitKilogram = 14,
NSMassFormatterUnitOunce = (6 << 8) + 1,
NSMassFormatterUnitPound = (6 << 8) + 2,
NSMassFormatterUnitStone = (6 << 8) + 3,
};
typedef NSInteger NSMassFormatterUnit;
@class NSNumberFormatter;
@interface NSMassFormatter : NSObject
{
NSNumberFormatter *_numberFormatter;
BOOL _isForPersonMassUse;
NSFormattingUnitStyle _unitStyle;
}
- (NSNumberFormatter *) numberFormatter;
- (void) setNumberFormatter: (NSNumberFormatter *)formatter;
- (NSFormattingUnitStyle) unitStyle;
- (void) setUnitStyle: (NSFormattingUnitStyle)style;
- (BOOL) isForPersonMassUse;
- (void) setForPersonMassUse: (BOOL)flag;
- (NSString *)stringFromValue: (double)value unit: (NSMassFormatterUnit)unit;
- (NSString *)stringFromKilograms: (double)numberInKilograms;
- (NSString *)unitStringFromValue: (double)value unit: (NSMassFormatterUnit)unit;
- (NSString *)unitStringFromKilograms: (double)numberInKilograms usedUnit: (NSMassFormatterUnit *)unitp;
- (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSMassFormatter_h_GNUSTEP_BASE_INCLUDE */

View file

@ -0,0 +1,74 @@
/* Definition of class NSMeasurement
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSMeasurement_h_GNUSTEP_BASE_INCLUDE
#define _NSMeasurement_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#include <Foundation/NSUnit.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST)
@class NSUnit;
@interface NSMeasurement : NSObject <NSCopying, NSCoding>
{
NSUnit *_unit;
double _doubleValue;
}
// Creating Measurements
- (instancetype) initWithDoubleValue: (double)doubleValue
unit: (NSUnit *)unit;
// Accessing unit and value
- (NSUnit *) unit;
- (double) doubleValue;
// Conversion
- (BOOL) canBeConvertedToUnit: (NSUnit *)unit;
- (NSMeasurement *) measurementByConvertingToUnit: (NSUnit *)unit;
// Operating
- (NSMeasurement *) measurementByAddingMeasurement: (NSMeasurement *)measurement;
- (NSMeasurement *) measurementBySubtractingMeasurement: (NSMeasurement *)measurement;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSMeasurement_h_GNUSTEP_BASE_INCLUDE */

View file

@ -0,0 +1,80 @@
/* Definition of class NSMeasurementFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: heron
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSMeasurementFormatter_h_GNUSTEP_BASE_INCLUDE
#define _NSMeasurementFormatter_h_GNUSTEP_BASE_INCLUDE
#if defined(__cplusplus)
extern "C" {
#endif
#include <Foundation/NSObject.h>
#include <Foundation/NSFormatter.h>
@class NSLocale, NSMeasurement, NSNumberFormatter, NSUnit;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
enum {
NSMeasurementFormatterUnitOptionsProvidedUnit = (1UL << 0),
NSMeasurementFormatterUnitOptionsNaturalScale = (1UL << 1),
NSMeasurementFormatterUnitOptionsTemperatureWithoutUnit = (1UL << 2),
};
typedef NSUInteger NSMeasurementFormatterUnitOptions;
@interface NSMeasurementFormatter : NSFormatter <NSCoding>
{
NSMeasurementFormatterUnitOptions _unitOptions;
NSFormattingUnitStyle _unitStyle;
NSLocale *_locale;
NSNumberFormatter *_numberFormatter;
}
- (NSMeasurementFormatterUnitOptions) unitOptions;
- (void) setUnitOptions: (NSMeasurementFormatterUnitOptions) unitOptions;
- (NSFormattingUnitStyle) unitStyle;
- (void) setUnitStyle: (NSFormattingUnitStyle)style;
- (NSLocale *) locale;
- (void) setLocale: (NSLocale *)locale;
- (NSNumberFormatter *) numberFormatter;
- (void) setNumberFormatter: (NSNumberFormatter *)numberFormatter;
- (NSString *)stringFromMeasurement: (NSMeasurement *)measurement;
- (NSString *)stringFromUnit: (NSUnit *)unit;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSMeasurementFormatter_h_GNUSTEP_BASE_INCLUDE */

420
Headers/Foundation/NSUnit.h Normal file
View file

@ -0,0 +1,420 @@
/* Definition of class NSUnit
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#ifndef _NSUnit_h_GNUSTEP_BASE_INCLUDE
#define _NSUnit_h_GNUSTEP_BASE_INCLUDE
#include <Foundation/NSObject.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
// Unit converter
@interface NSUnitConverter : NSObject
- (double) baseUnitValueFromValue: (double)value;
- (double) valueFromBaseUnitValue: (double)baseUnitValue;
@end
// Linea converter... for things like C <-> F conversion...
@interface NSUnitConverterLinear : NSUnitConverter <NSCoding>
{
double _coefficient;
double _constant;
}
- (instancetype) initWithCoefficient: (double)coefficient;
- (instancetype) initWithCoefficient: (double)coefficient
constant: (double)constant;
- (double) coefficient;
- (double) constant;
@end
// Units... abstract...
@interface NSUnit : NSObject <NSCopying, NSCoding>
{
NSString *_symbol;
}
- (instancetype) init;
- (instancetype) initWithSymbol: (NSString *)symbol;
- (NSString *) symbol;
@end
// Dimension using units....
@interface NSDimension : NSUnit <NSCoding>
{
double _value;
NSUnitConverter *_converter;
}
- (NSUnitConverter *) converter;
- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *)converter ;
+ (instancetype) baseUnit;
@end
// Predefined....
@interface NSUnitAcceleration : NSDimension
/*
Base unit - metersPerSecondSquared
*/
+ (NSUnitAcceleration *) metersPerSecondSquared;
+ (NSUnitAcceleration *) gravity;
@end
@interface NSUnitAngle : NSDimension
/*
Base unit - degrees
*/
+ (NSUnitAngle *) degrees;
+ (NSUnitAngle *) arcMinutes;
+ (NSUnitAngle *) arcSeconds;
+ (NSUnitAngle *) radians;
+ (NSUnitAngle *) gradians;
+ (NSUnitAngle *) revolutions;
@end
@interface NSUnitArea : NSDimension
/*
Base unit - squareMeters
*/
+ (NSUnitArea *) squareMegameters;
+ (NSUnitArea *) squareKilometers;
+ (NSUnitArea *) squareMeters;
+ (NSUnitArea *) squareCentimeters;
+ (NSUnitArea *) squareMillimeters;
+ (NSUnitArea *) squareMicrometers;
+ (NSUnitArea *) squareNanometers;
+ (NSUnitArea *) squareInches;
+ (NSUnitArea *) squareFeet;
+ (NSUnitArea *) squareYards;
+ (NSUnitArea *) squareMiles;
+ (NSUnitArea *) acres;
+ (NSUnitArea *) ares;
+ (NSUnitArea *) hectares;
@end
@interface NSUnitConcentrationMass : NSDimension
/*
Base unit - gramsPerLiter
*/
+ (NSUnitConcentrationMass *) gramsPerLiter;
+ (NSUnitConcentrationMass *) milligramsPerDeciliter;
+ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole: (double)gramsPerMole;
@end
@interface NSUnitDispersion : NSDimension
/*
Base unit - partsPerMillion
*/
+ (NSUnitDispersion *) partsPerMillion;
@end
@interface NSUnitDuration : NSDimension
/*
Base unit - seconds
*/
+ (NSUnitDuration *) seconds;
+ (NSUnitDuration *) minutes;
+ (NSUnitDuration *) hours;
@end
@interface NSUnitElectricCharge : NSDimension
/*
Base unit - coulombs
*/
+ (NSUnitElectricCharge *) coulombs;
+ (NSUnitElectricCharge *) megaampereHours;
+ (NSUnitElectricCharge *) kiloampereHours;
+ (NSUnitElectricCharge *) ampereHours;
+ (NSUnitElectricCharge *) milliampereHours;
+ (NSUnitElectricCharge *) microampereHours;
@end
@interface NSUnitElectricCurrent : NSDimension
/*
Base unit - amperes
*/
+ (NSUnitElectricCurrent *) megaamperes;
+ (NSUnitElectricCurrent *) kiloamperes;
+ (NSUnitElectricCurrent *) amperes;
+ (NSUnitElectricCurrent *) milliamperes;
+ (NSUnitElectricCurrent *) microamperes;
@end
@interface NSUnitElectricPotentialDifference : NSDimension
/*
Base unit - volts
*/
+ (NSUnitElectricPotentialDifference *) megavolts;
+ (NSUnitElectricPotentialDifference *) kilovolts;
+ (NSUnitElectricPotentialDifference *) volts;
+ (NSUnitElectricPotentialDifference *) millivolts;
+ (NSUnitElectricPotentialDifference *) microvolts;
@end
@interface NSUnitElectricResistance : NSDimension
/*
Base unit - ohms
*/
+ (NSUnitElectricResistance *) megaohms;
+ (NSUnitElectricResistance *) kiloohms;
+ (NSUnitElectricResistance *) ohms;
+ (NSUnitElectricResistance *) milliohms;
+ (NSUnitElectricResistance *) microohms;
@end
@interface NSUnitEnergy : NSDimension
/*
Base unit - joules
*/
+ (NSUnitEnergy *) kilojoules;
+ (NSUnitEnergy *) joules;
+ (NSUnitEnergy *) kilocalories;
+ (NSUnitEnergy *) calories;
+ (NSUnitEnergy *) kilowattHours;
@end
@interface NSUnitFrequency : NSDimension
/*
Base unit - hertz
*/
+ (NSUnitFrequency *) terahertz;
+ (NSUnitFrequency *) gigahertz;
+ (NSUnitFrequency *) megahertz;
+ (NSUnitFrequency *) kilohertz;
+ (NSUnitFrequency *) hertz;
+ (NSUnitFrequency *) millihertz;
+ (NSUnitFrequency *) microhertz;
+ (NSUnitFrequency *) nanohertz;
@end
@interface NSUnitFuelEfficiency : NSDimension
/*
Base unit - litersPer100Kilometers
*/
+ (NSUnitFuelEfficiency *) litersPer100Kilometers;
+ (NSUnitFuelEfficiency *) milesPerImperialGallon;
+ (NSUnitFuelEfficiency *) milesPerGallon;
@end
@interface NSUnitLength : NSDimension
/*
Base unit - meters
*/
+ (NSUnitLength *) megameters;
+ (NSUnitLength *) kilometers;
+ (NSUnitLength *) hectometers;
+ (NSUnitLength *) decameters;
+ (NSUnitLength *) meters;
+ (NSUnitLength *) decimeters;
+ (NSUnitLength *) centimeters;
+ (NSUnitLength *) millimeters;
+ (NSUnitLength *) micrometers;
+ (NSUnitLength *) nanometers;
+ (NSUnitLength *) picometers;
+ (NSUnitLength *) inches;
+ (NSUnitLength *) feet;
+ (NSUnitLength *) yards;
+ (NSUnitLength *) miles;
+ (NSUnitLength *) scandinavianMiles;
+ (NSUnitLength *) lightyears;
+ (NSUnitLength *) nauticalMiles;
+ (NSUnitLength *) fathoms;
+ (NSUnitLength *) furlongs;
+ (NSUnitLength *) astronomicalUnits;
+ (NSUnitLength *) parsecs;
@end
@interface NSUnitIlluminance : NSDimension
/*
Base unit - lux
*/
+ (NSUnitIlluminance *) lux;
@end
@interface NSUnitMass : NSDimension
/*
Base unit - kilograms
*/
+ (NSUnitMass *) kilograms;
+ (NSUnitMass *) grams;
+ (NSUnitMass *) decigrams;
+ (NSUnitMass *) centigrams;
+ (NSUnitMass *) milligrams;
+ (NSUnitMass *) micrograms;
+ (NSUnitMass *) nanograms;
+ (NSUnitMass *) picograms;
+ (NSUnitMass *) ounces;
+ (NSUnitMass *) pounds;
+ (NSUnitMass *) stones;
+ (NSUnitMass *) metricTons;
+ (NSUnitMass *) shortTons;
+ (NSUnitMass *) carats;
+ (NSUnitMass *) ouncesTroy;
+ (NSUnitMass *) slugs;
@end
@interface NSUnitPower : NSDimension
/*
Base unit - watts
*/
+ (NSUnitPower *) terawatts;
+ (NSUnitPower *) gigawatts;
+ (NSUnitPower *) megawatts;
+ (NSUnitPower *) kilowatts;
+ (NSUnitPower *) watts;
+ (NSUnitPower *) milliwatts;
+ (NSUnitPower *) microwatts;
+ (NSUnitPower *) nanowatts;
+ (NSUnitPower *) picowatts;
+ (NSUnitPower *) femtowatts;
+ (NSUnitPower *) horsepower;
@end
@interface NSUnitPressure : NSDimension
/*
Base unit - newtonsPerMetersSquared (equivalent to 1 pascal)
*/
+ (NSUnitPressure *) newtonsPerMetersSquared;
+ (NSUnitPressure *) gigapascals;
+ (NSUnitPressure *) megapascals;
+ (NSUnitPressure *) kilopascals;
+ (NSUnitPressure *) hectopascals;
+ (NSUnitPressure *) inchesOfMercury;
+ (NSUnitPressure *) bars;
+ (NSUnitPressure *) millibars;
+ (NSUnitPressure *) millimetersOfMercury;
+ (NSUnitPressure *) poundsForcePerSquareInch;
@end
@interface NSUnitSpeed : NSDimension
/*
Base unit - metersPerSecond
*/
+ (NSUnitSpeed *) metersPerSecond;
+ (NSUnitSpeed *) kilometersPerHour;
+ (NSUnitSpeed *) milesPerHour;
+ (NSUnitSpeed *) knots;
@end
@interface NSUnitTemperature : NSDimension
/*
Base unit - kelvin
*/
+ (NSUnitTemperature *) kelvin;
+ (NSUnitTemperature *) celsius;
+ (NSUnitTemperature *) fahrenheit;
@end
@interface NSUnitVolume : NSDimension
/*
Base unit - liters
*/
+ (NSUnitVolume *) megaliters;
+ (NSUnitVolume *) kiloliters;
+ (NSUnitVolume *) liters;
+ (NSUnitVolume *) deciliters;
+ (NSUnitVolume *) centiliters;
+ (NSUnitVolume *) milliliters;
+ (NSUnitVolume *) cubicKilometers;
+ (NSUnitVolume *) cubicMeters;
+ (NSUnitVolume *) cubicDecimeters;
+ (NSUnitVolume *) cubicCentimeters;
+ (NSUnitVolume *) cubicMillimeters;
+ (NSUnitVolume *) cubicInches;
+ (NSUnitVolume *) cubicFeet;
+ (NSUnitVolume *) cubicYards;
+ (NSUnitVolume *) cubicMiles;
+ (NSUnitVolume *) acreFeet;
+ (NSUnitVolume *) bushels;
+ (NSUnitVolume *) teaspoons;
+ (NSUnitVolume *) tablespoons;
+ (NSUnitVolume *) fluidOunces;
+ (NSUnitVolume *) cups;
+ (NSUnitVolume *) pints;
+ (NSUnitVolume *) quarts;
+ (NSUnitVolume *) gallons;
+ (NSUnitVolume *) imperialTeaspoons;
+ (NSUnitVolume *) imperialTablespoons;
+ (NSUnitVolume *) imperialFluidOunces;
+ (NSUnitVolume *) imperialPints;
+ (NSUnitVolume *) imperialQuarts;
+ (NSUnitVolume *) imperialGallons;
+ (NSUnitVolume *) metricCups;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSUnit_h_GNUSTEP_BASE_INCLUDE */

View file

@ -99,10 +99,14 @@ ifeq ($(_have_makefiles),yes)
config.mak: config.status config.mak.in
@./$< $@
base.make: config.status base.make.in Version
# If Version is newer than the target, configure must be rerun so that
# its variables get AC_SUBST'ed and actually updated in base.make.
@if [ Version -nt $@ ]; then ./configure; else ./$< $@; fi
base.make:: Version
@./configure
# Normally (Version unchanged) config.status can regenerate base.make.
base.make:: config.status base.make.in
@./$< $@
config.status: configure
@if [ -f $@ ]; then ./$@ --recheck; else ./$<; fi

View file

@ -213,6 +213,8 @@ NSConnection.m \
NSData.m \
NSDate.m \
NSDateFormatter.m \
NSDateInterval.m \
NSDateIntervalFormatter.m \
NSDebug.m \
NSDecimal.m \
NSDecimalNumber.m \
@ -220,6 +222,7 @@ NSDictionary.m \
NSDistantObject.m \
NSDistributedLock.m \
NSDistributedNotificationCenter.m \
NSEnergyFormatter.m \
NSEnumerator.m \
NSError.m \
NSException.m \
@ -244,10 +247,14 @@ NSKeyedArchiver.m \
NSKeyedUnarchiver.m \
NSKeyValueCoding.m \
NSKeyValueObserving.m \
NSLengthFormatter.m \
NSLocale.m \
NSLock.m \
NSLog.m \
NSMapTable.m \
NSMassFormatter.m \
NSMeasurementFormatter.m \
NSMeasurement.m \
NSMetadata.m \
NSMethodSignature.m \
NSNotification.m \
@ -292,6 +299,7 @@ NSScriptKeyValueCoding.m \
NSScriptObjectSpecifiers.m \
NSScriptStandardSuiteCommands.m \
NSScriptSuiteRegistry.m \
NSUnit.m \
NSUserScriptTask.m \
NSSerializer.m \
NSSet.m \
@ -401,6 +409,8 @@ NSCompoundPredicate.h \
NSConnection.h \
NSData.h \
NSDateFormatter.h \
NSDateInterval.h \
NSDateIntervalFormatter.h \
NSDate.h \
NSDebug.h \
NSDecimal.h \
@ -409,6 +419,7 @@ NSDictionary.h \
NSDistantObject.h \
NSDistributedLock.h \
NSDistributedNotificationCenter.h \
NSEnergyFormatter.h \
NSEnumerator.h \
NSError.h \
NSErrorRecoveryAttempting.h \
@ -435,9 +446,13 @@ NSJSONSerialization.h \
NSKeyedArchiver.h \
NSKeyValueCoding.h \
NSKeyValueObserving.h \
NSLengthFormatter.h \
NSLocale.h \
NSLock.h \
NSMapTable.h \
NSMassFormatter.h \
NSMeasurementFormatter.h \
NSMeasurement.h \
NSMetadata.h \
NSMethodSignature.h \
NSNetServices.h \
@ -477,6 +492,7 @@ NSScriptKeyValueCoding.h \
NSScriptObjectSpecifiers.h \
NSScriptStandardSuiteCommands.h \
NSScriptSuiteRegistry.h \
NSUnit.h \
NSUserScriptTask.h \
NSScriptWhoseTests.h \
NSSerialization.h \

View file

@ -159,7 +159,7 @@ otherTime(NSDate* other)
return NSAllocateObject(self, 0, z);
}
+ (id) date
+ (instancetype) date
{
return AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithTimeIntervalSinceReferenceDate: GSPrivateTimeNow()]);
@ -171,14 +171,14 @@ otherTime(NSDate* other)
* specified by the preferences in the user defaults database, allowing
* phrases like 'last tuesday'
*/
+ (id) dateWithNaturalLanguageString: (NSString*)string
+ (instancetype) dateWithNaturalLanguageString: (NSString*)string
{
return [self dateWithNaturalLanguageString: string
locale: nil];
}
+ (id) dateWithNaturalLanguageString: (NSString*)string
locale: (NSDictionary*)locale
+ (instancetype) dateWithNaturalLanguageString: (NSString*)string
locale: (NSDictionary*)locale
{
NSCharacterSet *ws;
NSCharacterSet *digits;
@ -885,35 +885,36 @@ otherTime(NSDate* other)
}
}
+ (id) dateWithString: (NSString*)description
+ (instancetype) dateWithString: (NSString*)description
{
return AUTORELEASE([[self alloc] initWithString: description]);
}
+ (id) dateWithTimeInterval: (NSTimeInterval)seconds sinceDate: (NSDate*)date
+ (instancetype) dateWithTimeInterval: (NSTimeInterval)seconds
sinceDate: (NSDate*)date
{
return AUTORELEASE([[self alloc] initWithTimeInterval: seconds
sinceDate: date]);
}
+ (id) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds
+ (instancetype) dateWithTimeIntervalSince1970: (NSTimeInterval)seconds
{
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceReferenceDate:
seconds - NSTimeIntervalSince1970]);
}
+ (id) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds
+ (instancetype) dateWithTimeIntervalSinceNow: (NSTimeInterval)seconds
{
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceNow: seconds]);
}
+ (id) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
+ (instancetype) dateWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
{
return AUTORELEASE([[self alloc] initWithTimeIntervalSinceReferenceDate:
seconds]);
}
+ (id) distantPast
+ (instancetype) distantPast
{
if (_distantPast == nil)
{
@ -922,7 +923,7 @@ otherTime(NSDate* other)
return _distantPast;
}
+ (id) distantFuture
+ (instancetype) distantFuture
{
if (_distantFuture == nil)
{
@ -940,7 +941,7 @@ otherTime(NSDate* other)
return GSPrivateTimeNow();
}
- (id) addTimeInterval: (NSTimeInterval)seconds
- (instancetype) addTimeInterval: (NSTimeInterval)seconds
{
return [self dateByAddingTimeInterval: seconds];
}
@ -976,7 +977,7 @@ otherTime(NSDate* other)
return abstractClass;
}
- (id) dateByAddingTimeInterval: (NSTimeInterval)ti
- (instancetype) dateByAddingTimeInterval: (NSTimeInterval)ti
{
return [[self class] dateWithTimeIntervalSinceReferenceDate:
otherTime(self) + ti];
@ -1069,7 +1070,7 @@ otherTime(NSDate* other)
return (NSUInteger)[self timeIntervalSinceReferenceDate];
}
- (id) initWithCoder: (NSCoder*)coder
- (instancetype) initWithCoder: (NSCoder*)coder
{
NSTimeInterval interval;
id o;
@ -1099,12 +1100,12 @@ otherTime(NSDate* other)
return o;
}
- (id) init
- (instancetype) init
{
return [self initWithTimeIntervalSinceReferenceDate: GSPrivateTimeNow()];
}
- (id) initWithString: (NSString*)description
- (instancetype) initWithString: (NSString*)description
{
// Easiest to just have NSCalendarDate do the work for us
NSCalendarDate *d = [calendarClass alloc];
@ -1123,8 +1124,8 @@ otherTime(NSDate* other)
}
}
- (id) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
sinceDate: (NSDate*)anotherDate
- (instancetype) initWithTimeInterval: (NSTimeInterval)secsToBeAdded
sinceDate: (NSDate*)anotherDate
{
if (anotherDate == nil)
{
@ -1137,20 +1138,20 @@ otherTime(NSDate* other)
otherTime(anotherDate) + secsToBeAdded];
}
- (id) initWithTimeIntervalSince1970: (NSTimeInterval)seconds
- (instancetype) initWithTimeIntervalSince1970: (NSTimeInterval)seconds
{
return [self initWithTimeIntervalSinceReferenceDate:
seconds - NSTimeIntervalSince1970];
}
- (id) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded
- (instancetype) initWithTimeIntervalSinceNow: (NSTimeInterval)secsToBeAdded
{
// Get the current time, add the secs and init thyself
return [self initWithTimeIntervalSinceReferenceDate:
GSPrivateTimeNow() + secsToBeAdded];
}
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
- (instancetype) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
{
[self subclassResponsibility: _cmd];
return self;

221
Source/NSDateInterval.m Normal file
View file

@ -0,0 +1,221 @@
/* Implementation of class NSDateInterval
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory Casamento <greg.casamento@gmail.com>
Date: Wed Oct 9 16:24:13 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSDateInterval.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSException.h>
@implementation NSDateInterval
// Init
- (instancetype)init
{
self = [super init];
if(self != nil)
{
_startDate = [NSDate date];
_duration = 0.0;
RETAIN(_startDate);
}
return self;
}
- (instancetype)initWithStartDate:(NSDate *)startDate
duration:(NSTimeInterval)duration
{
self = [super init];
if(self != nil)
{
ASSIGNCOPY(_startDate, startDate);
if(duration < 0)
{
[NSException raise: NSInvalidArgumentException
format: @"Duration %f is less than zero", duration];
}
_duration = duration;
}
return self;
}
- (instancetype)initWithStartDate:(NSDate *)startDate
endDate:(NSDate *)endDate
{
return [self initWithStartDate: startDate
duration: [endDate timeIntervalSinceDate: startDate]];
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
// TODO: Implement encoding
return nil;
}
- (void) encodeWithCoder: (NSCoder *)coder
{
}
- (id) copyWithZone: (NSZone *)zone
{
return [[[self class] allocWithZone: zone]
initWithStartDate: _startDate
duration: _duration];
}
- (void) dealloc
{
RELEASE(_startDate);
[super dealloc];
}
// Access
- (NSDate *) startDate
{
return _startDate;
}
- (void) setStartDate: (NSDate *)startDate
{
ASSIGNCOPY(_startDate, startDate);
}
- (NSDate *) endDate
{
return [_startDate dateByAddingTimeInterval: _duration];
}
- (void) setEndDate: (NSDate *)endDate
{
_duration = [endDate timeIntervalSinceDate: _startDate];
}
- (NSTimeInterval) duration
{
return _duration;
}
- (void) setDuration: (NSTimeInterval)duration
{
_duration = duration;
}
// Compare
- (NSComparisonResult) compare: (NSDateInterval *)dateInterval
{
NSComparisonResult result = NSOrderedSame;
if([_startDate isEqualToDate: [dateInterval startDate]] &&
_duration < [dateInterval duration])
{
result = NSOrderedAscending;
}
else if([_startDate compare: [dateInterval startDate]] == NSOrderedAscending)
{
result = NSOrderedAscending;
}
else if([self isEqualToDateInterval: dateInterval])
{
result = NSOrderedSame;
}
else if([_startDate isEqualToDate: [dateInterval startDate]] &&
_duration > [dateInterval duration])
{
result = NSOrderedDescending;
}
else if([_startDate compare: [dateInterval startDate]] == NSOrderedDescending)
{
result = NSOrderedDescending;
}
return result;
}
- (BOOL) isEqualToDateInterval: (NSDateInterval *)dateInterval
{
return ([_startDate isEqualToDate: [dateInterval startDate]] &&
_duration == [dateInterval duration]);
}
// Determine
- (BOOL) intersectsDateInterval: (NSDateInterval *)dateInterval
{
return [self intersectionWithDateInterval: dateInterval] != nil;
}
- (NSDateInterval *) intersectionWithDateInterval: (NSDateInterval *)dateInterval
{
NSDateInterval *result = nil;
NSDateInterval *first = self; //[sortedArray firstObject];
NSDateInterval *last = dateInterval; // [sortedArray lastObject];
NSDate *intersectStartDate = nil;
NSDate *intersectEndDate = nil;
// NSArray *array = [NSArray arrayWithObjects: self, dateInterval, nil];
// NSArray *sortedArray = [array sortedArrayUsingSelector: @selector(compare:)];
// Max of start date....
if([[first startDate] compare: [last startDate]] == NSOrderedAscending ||
[[first startDate] isEqualToDate: [last startDate]])
{
intersectStartDate = [last startDate];
}
if([[first startDate] compare: [last startDate]] == NSOrderedDescending)
{
intersectStartDate = [first startDate];
}
// Min of end date...
if([[first endDate] compare: [last endDate]] == NSOrderedDescending ||
[[first endDate] isEqualToDate: [last endDate]])
{
intersectEndDate = [last endDate];
}
if([[first endDate] compare: [last endDate]] == NSOrderedAscending)
{
intersectEndDate = [first endDate];
}
if([intersectStartDate compare: intersectEndDate] == NSOrderedAscending)
{
result = [[NSDateInterval alloc] initWithStartDate: intersectStartDate
endDate: intersectEndDate];
AUTORELEASE(result);
}
return result;
}
// Contain
- (BOOL) containsDate: (NSDate *)date
{
NSDate *endDate = [self endDate];
return ([_startDate compare: date] == NSOrderedSame ||
[endDate compare: date] == NSOrderedSame ||
([_startDate compare: date] == NSOrderedAscending &&
[endDate compare: date] == NSOrderedDescending));
}
@end

View file

@ -0,0 +1,115 @@
/* Implementation of class NSDateIntervalFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Wed Oct 9 16:23:55 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSDateIntervalFormatter.h>
#include <Foundation/NSLocale.h>
#include <Foundation/NSCalendar.h>
#include <Foundation/NSTimeZone.h>
#include <Foundation/NSString.h>
#include <Foundation/NSDate.h>
#include <Foundation/NSDateInterval.h>
@implementation NSDateIntervalFormatter
// Properties
- (NSLocale *) locale
{
return _locale;
}
- (void) setLocale: (NSLocale *)locale
{
ASSIGNCOPY(_locale, locale);
}
- (NSCalendar *) calendar
{
return _calendar;
}
- (void) setCalendar: (NSCalendar *)calendar
{
ASSIGNCOPY(_calendar, calendar);
}
- (NSTimeZone *) timeZone
{
return _timeZone;
}
- (void) setTimeZone: (NSTimeZone *)timeZone
{
ASSIGNCOPY(_timeZone, timeZone);
}
- (NSString *) dateTemplate
{
return _dateTemplate;
}
- (void) setDateTemplate: (NSString *)dateTemplate
{
ASSIGNCOPY(_dateTemplate, dateTemplate);
}
- (NSDateIntervalFormatterStyle) dateStyle
{
return _dateStyle;
}
- (void) setDateStyle: (NSDateIntervalFormatterStyle)dateStyle
{
_dateStyle = dateStyle;
}
- (NSDateIntervalFormatterStyle) timeStyle
{
return _timeStyle;
}
- (void) setTimeStyle: (NSDateIntervalFormatterStyle)timeStyle
{
_timeStyle = timeStyle;
}
// Create strings
- (NSString *) stringFromDate: (NSDate *)fromDate toDate: (NSDate *)toDate
{
NSDateInterval *interval = [[NSDateInterval alloc] initWithStartDate: fromDate
endDate: toDate];
AUTORELEASE(interval);
return [self stringFromDateInterval: interval];
}
- (NSString *) stringFromDateInterval: (NSDateInterval *)dateInterval
{
NSDate *fromDate = [dateInterval startDate];
NSDate *toDate = [dateInterval endDate];
// Add formatting of NSDate here.
return [NSString stringWithFormat: @"%@ - %@", fromDate, toDate];
}
@end

128
Source/NSEnergyFormatter.m Normal file
View file

@ -0,0 +1,128 @@
/* Implementation of class NSEnergyFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Tue Oct 8 13:30:10 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSEnergyFormatter.h>
#include <Foundation/NSMeasurement.h>
#include <Foundation/NSMeasurementFormatter.h>
#include <Foundation/NSUnit.h>
@implementation NSEnergyFormatter
- (instancetype) init
{
self = [super init];
if(self != nil)
{
_numberFormatter = nil;
_unitStyle = NSFormattingUnitStyleMedium;
_isForFoodEnergyUse = NO;
}
return self;
}
- (NSNumberFormatter *) numberFormatter
{
return _numberFormatter;
}
- (void) setNumberFormatter: (NSNumberFormatter *)formatter
{
ASSIGN(_numberFormatter, formatter);
}
- (NSFormattingUnitStyle) unitStyle
{
return _unitStyle;
}
- (void) setUnitStyle: (NSFormattingUnitStyle)style
{
_unitStyle = style;
}
- (BOOL) isForFoodEnergyUse
{
return _isForFoodEnergyUse;
}
- (void) setForFoodEnergyUse: (BOOL)flag
{
_isForFoodEnergyUse = flag;
}
- (NSString *) stringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit
{
NSUnit *u = nil;
NSMeasurement *m = nil;
NSMeasurementFormatter *mf = nil;
switch(unit)
{
case NSEnergyFormatterUnitJoule:
u = [NSUnitEnergy joules];
break;
case NSEnergyFormatterUnitKilojoule:
u = [NSUnitEnergy kilojoules];
break;
case NSEnergyFormatterUnitCalorie:
u = [NSUnitEnergy calories];
break;
case NSEnergyFormatterUnitKilocalorie:
u = [NSUnitEnergy kilocalories];
break;
}
m = [[NSMeasurement alloc] initWithDoubleValue: value
unit: u];
AUTORELEASE(m);
mf = [[NSMeasurementFormatter alloc] init];
AUTORELEASE(mf);
[mf setUnitStyle: _unitStyle];
[mf setNumberFormatter: _numberFormatter];
return [mf stringFromMeasurement: m];
}
- (NSString *) stringFromJoules: (double)numberInJoules
{
return [self stringFromValue: numberInJoules unit: NSEnergyFormatterUnitJoule];
}
- (NSString *) unitStringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit
{
return [self stringFromValue: value unit: unit];
}
- (NSString *) unitStringFromJoules: (double)numberInJoules usedUnit: (NSEnergyFormatterUnit *)unit
{
*unit = NSEnergyFormatterUnitJoule;
return [self stringFromValue: numberInJoules unit: *unit];
}
- (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error
{
return NO;
}
@end

148
Source/NSLengthFormatter.m Normal file
View file

@ -0,0 +1,148 @@
/* Implementation of class NSLengthFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: heron
Date: Tue Oct 8 13:30:33 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSLengthFormatter.h>
#include <Foundation/NSUnit.h>
#include <Foundation/NSMeasurement.h>
#include <Foundation/NSMeasurementFormatter.h>
@implementation NSLengthFormatter
- (instancetype) init
{
self = [super init];
if(self != nil)
{
_numberFormatter = nil;
_unitStyle = NSFormattingUnitStyleMedium;
_isForPersonHeightUse = NO;
}
return self;
}
- (void) dealloc
{
RELEASE(_numberFormatter);
[super dealloc];
}
- (NSNumberFormatter *) numberFormatter
{
return _numberFormatter;
}
- (void) setNumberFormatter: (NSNumberFormatter *)formatter
{
ASSIGN(_numberFormatter, formatter);
}
- (NSFormattingUnitStyle) unitStyle
{
return _unitStyle;
}
- (void) setUnitStyle: (NSFormattingUnitStyle)style
{
_unitStyle = style;
}
- (BOOL) isForPersonHeightUse
{
return _isForPersonHeightUse;
}
- (void) setForPersonHeightUse: (BOOL)flag
{
_isForPersonHeightUse = flag;
}
- (NSString *) stringFromValue: (double)value unit: (NSLengthFormatterUnit)unit
{
NSUnit *u = nil;
NSMeasurement *m = nil;
NSMeasurementFormatter *mf = nil;
switch(unit)
{
case NSLengthFormatterUnitMillimeter:
u = [NSUnitLength millimeters];
break;
case NSLengthFormatterUnitCentimeter:
u = [NSUnitLength centimeters];
break;
case NSLengthFormatterUnitMeter:
u = [NSUnitLength meters];
break;
case NSLengthFormatterUnitKilometer:
u = [NSUnitLength kilometers];
break;
case NSLengthFormatterUnitInch:
u = [NSUnitLength inches];
break;
case NSLengthFormatterUnitFoot:
u = [NSUnitLength feet];
break;
case NSLengthFormatterUnitYard:
u = [NSUnitLength yards];
break;
case NSLengthFormatterUnitMile:
u = [NSUnitLength miles];
break;
}
m = [[NSMeasurement alloc] initWithDoubleValue: value
unit: u];
AUTORELEASE(m);
mf = [[NSMeasurementFormatter alloc] init];
AUTORELEASE(mf);
[mf setUnitStyle: _unitStyle];
[mf setNumberFormatter: _numberFormatter];
return [mf stringFromMeasurement: m];
}
- (NSString *) stringFromMeters: (double)numberInMeters
{
return [self stringFromValue: numberInMeters unit: NSLengthFormatterUnitMeter];
}
- (NSString *) unitStringFromValue: (double)value unit: (NSLengthFormatterUnit)unit
{
return [self stringFromValue: value unit: unit];
}
- (NSString *) unitStringFromMeters: (double)numberInMeters usedUnit: (NSLengthFormatterUnit *)unit
{
*unit = NSLengthFormatterUnitMeter;
return [self stringFromValue: numberInMeters unit: *unit];
}
- (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error
{
return NO;
}
@end

133
Source/NSMassFormatter.m Normal file
View file

@ -0,0 +1,133 @@
/* Implementation of class NSMassFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: heron
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSMassFormatter.h>
#include <Foundation/NSMeasurement.h>
#include <Foundation/NSMeasurementFormatter.h>
#include <Foundation/NSUnit.h>
@implementation NSMassFormatter
- (instancetype) init
{
self = [super init];
if(self != nil)
{
_numberFormatter = nil;
_unitStyle = NSFormattingUnitStyleMedium;
_isForPersonMassUse = NO;
}
return self;
}
- (NSNumberFormatter *) numberFormatter
{
return _numberFormatter;
}
- (void) setNumberFormatter: (NSNumberFormatter *)formatter
{
ASSIGN(_numberFormatter, formatter);
}
- (NSFormattingUnitStyle) unitStyle
{
return _unitStyle;
}
- (void) setUnitStyle: (NSFormattingUnitStyle)style;
{
_unitStyle = style;
}
- (BOOL) isForPersonMassUse;
{
return _isForPersonMassUse;
}
- (void) setForPersonMassUse: (BOOL)flag;
{
_isForPersonMassUse = flag;
}
- (NSString *)stringFromValue: (double)value unit: (NSMassFormatterUnit)unit;
{
NSUnit *u = nil;
NSMeasurement *m = nil;
NSMeasurementFormatter *mf = nil;
switch(unit)
{
case NSMassFormatterUnitGram:
u = [NSUnitMass grams];
break;
case NSMassFormatterUnitKilogram:
u = [NSUnitMass kilograms];
break;
case NSMassFormatterUnitOunce:
u = [NSUnitMass ounces];
break;
case NSMassFormatterUnitPound:
u = [NSUnitMass pounds];
break;
case NSMassFormatterUnitStone:
u = [NSUnitMass stones];
break;
}
m = [[NSMeasurement alloc] initWithDoubleValue: value
unit: u];
AUTORELEASE(m);
mf = [[NSMeasurementFormatter alloc] init];
AUTORELEASE(mf);
[mf setUnitStyle: _unitStyle];
[mf setNumberFormatter: _numberFormatter];
return [mf stringFromMeasurement: m];
}
- (NSString *)stringFromKilograms: (double)numberInKilograms;
{
return [self stringFromValue: numberInKilograms unit: NSMassFormatterUnitKilogram];
}
- (NSString *)unitStringFromValue: (double)value unit: (NSMassFormatterUnit)unit;
{
return [self stringFromValue: value unit: unit];
}
- (NSString *)unitStringFromKilograms: (double)numberInKilograms usedUnit: (NSMassFormatterUnit *)unit
{
*unit = NSMassFormatterUnitKilogram;
return [self stringFromValue: numberInKilograms unit: *unit];
}
- (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error
{
return NO;
}
@end

157
Source/NSMeasurement.m Normal file
View file

@ -0,0 +1,157 @@
/* Implementation of class NSMeasurement
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSMeasurement.h>
#include <Foundation/NSUnit.h>
#include <Foundation/NSException.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSKeyedArchiver.h>
@implementation NSMeasurement
// Creating Measurements
- (instancetype)initWithDoubleValue: (double)doubleValue
unit: (NSUnit *)unit
{
self = [super init];
if(self != nil)
{
ASSIGNCOPY(_unit, unit);
_doubleValue = doubleValue;
}
return self;
}
- (void) dealloc
{
RELEASE(_unit);
[super dealloc];
}
// Accessing unit and value
- (NSUnit *) unit
{
return _unit;
}
- (double) doubleValue
{
return _doubleValue;
}
// Conversion
- (BOOL) canBeConvertedToUnit: (NSUnit *)unit
{
return ([unit isKindOfClass: [_unit class]] &&
[unit respondsToSelector: @selector(converter)]);
}
- (NSMeasurement *) measurementByConvertingToUnit: (NSUnit *)unit
{
NSMeasurement *result = nil;
double val = 0.0;
if([self canBeConvertedToUnit: unit])
{
// Do conversion...
NSUnitConverter *c = [(NSDimension *)unit converter];
val = [c baseUnitValueFromValue: _doubleValue];
result = [[NSMeasurement alloc] initWithDoubleValue: val unit: unit];
AUTORELEASE(result);
}
else
{
[NSException raise: NSInvalidArgumentException
format: @"Cannot convert from %@ to %@", _unit, unit];
}
return result;
}
// Operating
- (NSMeasurement *) measurementByAddingMeasurement: (NSMeasurement *)measurement
{
NSMeasurement *newMeasurement = [measurement measurementByConvertingToUnit: _unit];
NSMeasurement *result = nil;
double v = 0.0;
v = _doubleValue + [newMeasurement doubleValue];
result = [[NSMeasurement alloc] initWithDoubleValue: v unit: _unit];
AUTORELEASE(result);
return result;
}
- (NSMeasurement *) measurementBySubtractingMeasurement: (NSMeasurement *)measurement
{
NSMeasurement *newMeasurement = [measurement measurementByConvertingToUnit: _unit];
NSMeasurement *result = nil;
double v = 0.0;
v = _doubleValue - [newMeasurement doubleValue];
result = [[NSMeasurement alloc] initWithDoubleValue: v unit: _unit];
AUTORELEASE(result);
return result;
}
// NSCopying
- (id) copyWithZone: (NSZone *)zone
{
return [[[self class] allocWithZone: zone] initWithDoubleValue: _doubleValue
unit: _unit];
}
// NSCoding
- (void) encodeWithCoder: (NSCoder *)coder
{
if([coder allowsKeyedCoding])
{
// TODO: Verify that this is the correct encoding...
[coder encodeObject: _unit forKey: @"unit"];
[coder encodeDouble: _doubleValue forKey: @"doubleValue"];
}
else
{
[coder encodeObject: _unit];
[coder encodeValueOfObjCType: @encode(double) at: &_doubleValue];
}
}
- (id) initWithCoder: (NSCoder *)coder
{
if((self = [super init]) != nil)
{
if([coder allowsKeyedCoding])
{
_unit = [coder decodeObjectForKey: @"unit"];
_doubleValue = [coder decodeDoubleForKey: @"doubleValue"];
}
else
{
_unit = [coder decodeObject];
[coder decodeValueOfObjCType: @encode(double) at: &_doubleValue];
}
}
return self;
}
@end

View file

@ -0,0 +1,130 @@
/* Implementation of class NSMeasurementFormatter
Copyright (C) 2019 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: Mon Sep 30 15:58:21 EDT 2019
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#include <Foundation/NSMeasurementFormatter.h>
#include <Foundation/NSLocale.h>
#include <Foundation/NSMeasurement.h>
#include <Foundation/NSNumberFormatter.h>
#include <Foundation/NSUnit.h>
@implementation NSMeasurementFormatter
- (instancetype) init
{
self = [super init];
if(self != nil)
{
_unitOptions = NSMeasurementFormatterUnitOptionsProvidedUnit;
_unitStyle = NSFormattingUnitStyleMedium;
_locale = RETAIN([NSLocale currentLocale]);
}
return self;
}
- (void) dealloc
{
RELEASE(_locale);
[super dealloc];
}
- (NSMeasurementFormatterUnitOptions) unitOptions
{
return _unitOptions;
}
- (void) setUnitOptions: (NSMeasurementFormatterUnitOptions) unitOptions
{
_unitOptions = unitOptions;
}
- (NSFormattingUnitStyle) unitStyle
{
return _unitStyle;
}
- (void) setUnitStyle: (NSFormattingUnitStyle)style
{
_unitStyle = style;
}
- (NSLocale *) locale
{
return _locale;
}
- (void) setLocale: (NSLocale *)locale
{
ASSIGNCOPY(_locale, locale);
}
- (NSNumberFormatter *) numberFormatter
{
return _numberFormatter;
}
- (void) setNumberFormatter: (NSNumberFormatter *)numberFormatter
{
ASSIGNCOPY(_numberFormatter, numberFormatter);
}
- (NSString *)stringFromMeasurement: (NSMeasurement *)measurement
{
NSString *result = nil;
NSNumber *num = [NSNumber numberWithDouble: [measurement doubleValue]];
NSUnit *u = [measurement unit];
result = [_numberFormatter stringForObjectValue: num];
switch(_unitStyle)
{
case NSFormattingUnitStyleShort:
case NSFormattingUnitStyleMedium:
case NSFormattingUnitStyleLong:
result = [result stringByAppendingString: [self stringFromUnit: u]];
break;
}
return result;
}
- (NSString *)stringFromUnit: (NSUnit *)unit
{
return [unit symbol];
}
- (NSString *)stringForObjectValue: (id)obj
{
NSString *result = nil;
if([obj isKindOfClass: [NSMeasurement class]])
{
result = [self stringFromMeasurement: obj];
}
else if([obj isKindOfClass: [NSUnit class]])
{
result = [self stringFromUnit: obj];
}
return result;
}
@end

1771
Source/NSUnit.m Normal file

File diff suppressed because it is too large Load diff