diff --git a/Headers/Foundation/Foundation.h b/Headers/Foundation/Foundation.h index 9bb48ab71..c1fd568a0 100644 --- a/Headers/Foundation/Foundation.h +++ b/Headers/Foundation/Foundation.h @@ -55,12 +55,15 @@ #import #import #import +#import +#import #import #import #import #import #import #import +#import #import #import #import @@ -86,9 +89,12 @@ #import #import #import +#import #import #import #import +#import +#import #import #import #import @@ -138,6 +144,7 @@ #import #import #import +#import #import #import #import diff --git a/Headers/Foundation/MISSING b/Headers/Foundation/MISSING index a64d088bf..98a92d009 100644 --- a/Headers/Foundation/MISSING +++ b/Headers/Foundation/MISSING @@ -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 diff --git a/Headers/Foundation/NSDateInterval.h b/Headers/Foundation/NSDateInterval.h new file mode 100644 index 000000000..a7e6082b1 --- /dev/null +++ b/Headers/Foundation/NSDateInterval.h @@ -0,0 +1,84 @@ +/* Definition of class NSDateInterval + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory Casamento + 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 +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST) + +@interface NSDateInterval : NSObject +{ + 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 */ + diff --git a/Headers/Foundation/NSDateIntervalFormatter.h b/Headers/Foundation/NSDateIntervalFormatter.h new file mode 100644 index 000000000..ebd051540 --- /dev/null +++ b/Headers/Foundation/NSDateIntervalFormatter.h @@ -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 + +#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 */ + diff --git a/Headers/Foundation/NSEnergyFormatter.h b/Headers/Foundation/NSEnergyFormatter.h new file mode 100644 index 000000000..a105ab347 --- /dev/null +++ b/Headers/Foundation/NSEnergyFormatter.h @@ -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 + +#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 */ + diff --git a/Headers/Foundation/NSLengthFormatter.h b/Headers/Foundation/NSLengthFormatter.h new file mode 100644 index 000000000..e1dae4b83 --- /dev/null +++ b/Headers/Foundation/NSLengthFormatter.h @@ -0,0 +1,84 @@ +/* Definition of class NSLengthFormatter + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 + +#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 */ + diff --git a/Headers/Foundation/NSMassFormatter.h b/Headers/Foundation/NSMassFormatter.h new file mode 100644 index 000000000..e58f0e78c --- /dev/null +++ b/Headers/Foundation/NSMassFormatter.h @@ -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 + +#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 */ + diff --git a/Headers/Foundation/NSMeasurement.h b/Headers/Foundation/NSMeasurement.h new file mode 100644 index 000000000..822a993fa --- /dev/null +++ b/Headers/Foundation/NSMeasurement.h @@ -0,0 +1,74 @@ +/* Definition of class NSMeasurement + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) + +@class NSUnit; + +@interface NSMeasurement : NSObject +{ + 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 */ + diff --git a/Headers/Foundation/NSMeasurementFormatter.h b/Headers/Foundation/NSMeasurementFormatter.h new file mode 100644 index 000000000..33be1196f --- /dev/null +++ b/Headers/Foundation/NSMeasurementFormatter.h @@ -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 +#include + +@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 +{ + 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 */ + diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h new file mode 100644 index 000000000..f5d80a972 --- /dev/null +++ b/Headers/Foundation/NSUnit.h @@ -0,0 +1,420 @@ +/* Definition of class NSUnit + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 + +#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 +{ + 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 +{ + NSString *_symbol; +} + +- (instancetype) init; +- (instancetype) initWithSymbol: (NSString *)symbol; +- (NSString *) symbol; + +@end + +// Dimension using units.... +@interface NSDimension : NSUnit +{ + 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 */ + diff --git a/Source/GNUmakefile b/Source/GNUmakefile index c4c324534..72831e3c2 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -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 \ +NSLengthFormtter.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 \ diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m new file mode 100644 index 000000000..da8b1f476 --- /dev/null +++ b/Source/NSDateInterval.m @@ -0,0 +1,221 @@ +/* Implementation of class NSDateInterval + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory Casamento + 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 +#include +#include +#include + +@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 + diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m new file mode 100644 index 000000000..f8dda781c --- /dev/null +++ b/Source/NSDateIntervalFormatter.m @@ -0,0 +1,115 @@ +/* Implementation of class NSDateIntervalFormatter + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 +#include +#include +#include +#include +#include +#include + +@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 + diff --git a/Source/NSEnergyFormatter.m b/Source/NSEnergyFormatter.m new file mode 100644 index 000000000..f599515a7 --- /dev/null +++ b/Source/NSEnergyFormatter.m @@ -0,0 +1,128 @@ +/* Implementation of class NSEnergyFormatter + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 +#include +#include +#include + +@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 + diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m new file mode 100644 index 000000000..6e7f93c26 --- /dev/null +++ b/Source/NSLengthFormatter.m @@ -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 +#include +#include +#include + +@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 + diff --git a/Source/NSMassFormatter.m b/Source/NSMassFormatter.m new file mode 100644 index 000000000..5252d37e8 --- /dev/null +++ b/Source/NSMassFormatter.m @@ -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 +#include +#include +#include + +@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 + diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m new file mode 100644 index 000000000..76d925daa --- /dev/null +++ b/Source/NSMeasurement.m @@ -0,0 +1,157 @@ +/* Implementation of class NSMeasurement + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 +#include +#include +#include +#include + +@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 + diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m new file mode 100644 index 000000000..1f1d32534 --- /dev/null +++ b/Source/NSMeasurementFormatter.m @@ -0,0 +1,130 @@ +/* Implementation of class NSMeasurementFormatter + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 +#include +#include +#include +#include + +@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 + diff --git a/Source/NSUnit.m b/Source/NSUnit.m new file mode 100644 index 000000000..adb66dd72 --- /dev/null +++ b/Source/NSUnit.m @@ -0,0 +1,1771 @@ +/* Implementation of class NSUnit + Copyright (C) 2019 Free Software Foundation, Inc. + + By: Gregory John Casamento + 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 +#include +#include + +// Private methods... +@interface NSDimension (Private) +- (instancetype) initWithSymbol: (NSString *)symbol + coefficient: (double)coefficient + constant: (double)constant; +@end + +// Abstract conversion... +@implementation NSUnitConverter +- (instancetype) init +{ + self = [super init]; + if (self != nil) + { + } + return self; +} + +- (double)baseUnitValueFromValue:(double)value +{ + return 0.0; +} + +- (double)valueFromBaseUnitValue:(double)baseUnitValue +{ + return 0.0; +} +@end + +// Linear conversion... +@implementation NSUnitConverterLinear +- (instancetype) initWithCoefficient: (double)coefficient +{ + self = [super init]; + if(self != nil) + { + _coefficient = coefficient; + _constant = 0.0; + } + return self; +} + +- (instancetype) initWithCoefficient: (double)coefficient + constant: (double)constant +{ + self = [super init]; + if(self != nil) + { + _coefficient = coefficient; + _constant = constant; + } + return self; +} + +- (id) initWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + _coefficient = [coder decodeDoubleForKey: @"coefficient"]; + _constant = [coder decodeDoubleForKey: @"constant"]; + } + else + { + [coder decodeValueOfObjCType: @encode(double) at: &_coefficient]; + [coder decodeValueOfObjCType: @encode(double) at: &_constant]; + } + return self; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + [coder encodeDouble: _coefficient forKey: @"coefficient"]; + [coder encodeDouble: _constant forKey: @"constant"]; + } + else + { + [coder encodeValueOfObjCType: @encode(double) at: &_coefficient]; + [coder encodeValueOfObjCType: @encode(double) at: &_constant]; + } +} + +- (double) coefficient +{ + return _coefficient; +} + +- (double) constant +{ + return _constant; +} + +- (double)baseUnitValueFromValue:(double)value +{ + return ((_coefficient * value) + _constant); +} + +- (double)valueFromBaseUnitValue:(double)baseUnitValue +{ + return (baseUnitValue - _constant) * _coefficient; //((baseUnitValue / _coefficient) - _constant); +} +@end + +// Abstract unit... +@implementation NSUnit ++ (instancetype)new +{ + return [[self alloc] init]; +} + +- (instancetype)init +{ + self = [super init]; + if(self != nil) + { + ASSIGNCOPY(_symbol, @""); + } + return self; +} + +- (instancetype)initWithSymbol:(NSString *)symbol +{ + self = [super init]; + if(self != nil) + { + ASSIGNCOPY(_symbol, symbol); + } + return self; +} + +- (id) initWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + _symbol = [coder decodeObjectForKey: @"symbol"]; + } + else + { + _symbol = [coder decodeObject]; + } + return self; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ + if([coder allowsKeyedCoding]) + { + [coder encodeObject: _symbol forKey: @"coder"]; + } + else + { + [coder encodeObject: _symbol]; + } +} + +- (instancetype) copyWithZone: (NSZone *)zone +{ + NSUnit *u = [[NSUnit allocWithZone: zone] initWithSymbol: [self symbol]]; + return u; +} + +- (NSString *)symbol +{ + return _symbol; +} +@end + + +// Dimension using units.... +@implementation NSDimension +- (NSUnitConverter *) converter +{ + return _converter; +} + +- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *) converter +{ + self = [super initWithSymbol: symbol]; + if(self != nil) + { + ASSIGN(_converter, converter); + } + return self; +} + +- (instancetype) initWithSymbol: (NSString *)symbol + coefficient: (double)coefficient + constant: (double)constant +{ + NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: coefficient + constant: constant]; + self = [self initWithSymbol: symbol + converter: converter]; + + AUTORELEASE(converter); + return self; +} + ++ (instancetype) baseUnit +{ + return nil; +} +@end + + +// Predefined.... +@implementation NSUnitAcceleration + ++ (instancetype) baseUnit +{ + return [self metersPerSecondSquared]; +} + +// Base unit - metersPerSecondSquared ++ (NSUnitAcceleration *) metersPerSecondSquared +{ + NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"m/s^2" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitAcceleration *) gravity +{ + NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"g" + coefficient: 9.81 + constant: 0]; + return result; +} + +@end + +@implementation NSUnitAngle + ++ (instancetype) baseUnit +{ + return [self degrees]; +} + +// Base unit - degrees ++ (NSUnitAngle *) degrees +{ + NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"deg" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitAngle *) arcMinutes +{ + NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"'" + coefficient: 0.016667 + constant: 0.0]; + return result; +} + ++ (NSUnitAngle *) arcSeconds +{ + NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"\"" + coefficient: 0.00027778 + constant: 0.0]; + return result; +} + ++ (NSUnitAngle *) radians +{ + NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"rad" + coefficient: 57.2958 + constant: 0.0]; + return result; +} + ++ (NSUnitAngle *) gradians +{ + NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"grad" + coefficient: 0.9 + constant: 0.0]; + return result; +} + ++ (NSUnitAngle *) revolutions +{ + NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitArea + ++ (instancetype) baseUnit +{ + return [self squareMeters]; +} + +// Base unit - squareMeters ++ (NSUnitArea *) squareMegameters +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"Mm^2" + coefficient: 1e12 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareKilometers +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"km^2" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMeters +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"m^2" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareCentimeters +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"cm^2" + coefficient: 0.0001 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMillimeters +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"mm^2" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMicrometers +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"um^2" + coefficient: 1e-12 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareNanometers +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"nm^2" + coefficient: 1e-18 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareInches +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"in^2" + coefficient: 0.00064516 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareFeet +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"ft^2" + coefficient: 0.092903 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareYards +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"yd^2" + coefficient: 0.836127 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMiles +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"mi^2" + coefficient: 2.59e+6 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) acres +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"acres" + coefficient: 4046.86 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) ares +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"ares" + coefficient: 100.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) hectares +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"hectares" + coefficient: 10000.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitConcentrationMass + ++ (instancetype) baseUnit +{ + return [self gramsPerLiter]; +} + +// Base unit - gramsPerLiter ++ (NSUnitConcentrationMass *) gramsPerLiter +{ + NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"g/L" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitConcentrationMass *) milligramsPerDeciliter +{ + NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"mg/dL" + coefficient: 0.01 + constant: 0.0]; + return result; +} + ++ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole +{ + NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"mmol/L" + coefficient: 18.0 * gramsPerMole + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitDispersion + ++ (instancetype) baseUnit +{ + return [self partsPerMillion]; +} + +// Base unit - partsPerMillion ++ (NSUnitDispersion *) partsPerMillion +{ + NSUnitDispersion *result = [[NSUnitDispersion alloc] initWithSymbol: @"ppm" + coefficient: 1.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitDuration + ++ (instancetype) baseUnit +{ + return [self seconds]; +} + +// Base unit - seconds ++ (NSUnitDuration *) seconds +{ + NSUnitDuration *result = [[NSUnitDuration alloc] initWithSymbol: @"sec" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitDuration *) minutes +{ + NSUnitDuration *result = [[NSUnitDuration alloc] initWithSymbol: @"min" + coefficient: 60.0 + constant: 0.0]; + return result; +} + ++ (NSUnitDuration *) hours +{ + NSUnitDuration *result = [[NSUnitDuration alloc] initWithSymbol: @"hr" + coefficient: 3600.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitElectricCharge + ++ (instancetype) baseUnit +{ + return [self coulombs]; +} + +// Base unit - coulombs ++ (NSUnitElectricCharge *) coulombs +{ + NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"C" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCharge *) megaampereHours +{ + NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"MAh" + coefficient: 3.6e9 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCharge *) kiloampereHours +{ + NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"kAh" + coefficient: 3600000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCharge *) ampereHours +{ + NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"mAh" + coefficient: 3600.0 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCharge *) milliampereHours +{ + NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"hr" + coefficient: 3.6 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCharge *) microampereHours +{ + NSUnitElectricCharge *result = [[NSUnitElectricCharge alloc] initWithSymbol: @"uAh" + coefficient: 0.0036 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitElectricCurrent + ++ (instancetype) baseUnit +{ + return [self amperes]; +} + +// Base unit - amperes ++ (NSUnitElectricCurrent *) megaamperes +{ + NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"MA" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCurrent *) kiloamperes +{ + NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"kA" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCurrent *) amperes +{ + NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"A" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCurrent *) milliamperes +{ + NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"mA" + coefficient: 0.001 + constant: 0.0]; + return result; +} + ++ (NSUnitElectricCurrent *) microamperes +{ + NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"uA" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitElectricPotentialDifference + ++ (instancetype) baseUnit +{ + return [self volts]; +} + +// Base unit - volts ++ (NSUnitElectricPotentialDifference *) megavolts +{ + NSUnitElectricPotentialDifference *result = + [[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"MV" + coefficient: 0.0 + constant: 1000000.0]; + return result; +} + ++ (NSUnitElectricPotentialDifference *) kilovolts +{ + NSUnitElectricPotentialDifference *result = + [[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"kV" + coefficient: 0.0 + constant: 1000.0]; + return result; +} + ++ (NSUnitElectricPotentialDifference *) volts +{ + NSUnitElectricPotentialDifference *result = + [[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"V" + coefficient: 0.0 + constant: 1.0]; + return result; +} + ++ (NSUnitElectricPotentialDifference *) millivolts +{ + NSUnitElectricPotentialDifference *result = + [[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"mV" + coefficient: 0.0 + constant: 0.001]; + return result; +} + ++ (NSUnitElectricPotentialDifference *) microvolts +{ + NSUnitElectricPotentialDifference *result = + [[NSUnitElectricPotentialDifference alloc] initWithSymbol: @"uV" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + +@end + +@implementation NSUnitElectricResistance + ++ (instancetype) baseUnit +{ + return [self ohms]; +} + +// Base unit - ohms ++ (NSUnitElectricResistance *) megaohms +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"MOhm" + coefficient: 0.0 + constant: 100000.0]; + return result; +} + ++ (NSUnitElectricResistance *) kiloohms +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"kOhm" + coefficient: 0.0 + constant: 1000.000001]; + return result; +} + ++ (NSUnitElectricResistance *) ohms +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"Ohm" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + ++ (NSUnitElectricResistance *) milliohms +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"mOhm" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + ++ (NSUnitElectricResistance *) microohms +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"uOhm" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + + +@end + +@implementation NSUnitEnergy + ++ (instancetype) baseUnit +{ + return [self joules]; +} + +// Base unit - joules ++ (NSUnitEnergy *) kilojoules +{ + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"kJ" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) joules +{ + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"J" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) kilocalories +{ + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"kCal" + coefficient: 4184.0 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) calories +{ + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"cal" + coefficient: 4.184 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) kilowattHours +{ + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"kWh" + coefficient: 3600000.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitFrequency + ++ (instancetype) baseUnit +{ + return [self hertz]; +} + +// Base unit - hertz + ++ (NSUnitFrequency *) terahertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"thz" + coefficient: 1e12 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) gigahertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"ghz" + coefficient: 1e9 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) megahertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"GHz" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) kilohertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"KHz" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) hertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"Hz" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) millihertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"mHz" + coefficient: 0.001 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) microhertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"uHz" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + ++ (NSUnitFrequency *) nanohertz +{ + NSUnitFrequency *result = [[NSUnitFrequency alloc] initWithSymbol: @"nHz" + coefficient: 1e-9 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitFuelEfficiency + ++ (instancetype) baseUnit +{ + return [self litersPer100Kilometers]; +} + +// Base unit - litersPer100Kilometers + ++ (NSUnitFuelEfficiency *) litersPer100Kilometers +{ + NSUnitFuelEfficiency *result = [[NSUnitFuelEfficiency alloc] initWithSymbol: @"L/100km" + coefficient: 0.0 + constant: 0.0]; + return result; +} + ++ (NSUnitFuelEfficiency *) milesPerImperialGallon +{ + NSUnitFuelEfficiency *result = [[NSUnitFuelEfficiency alloc] initWithSymbol: @"mpg" + coefficient: 0.0 + constant: 0.0]; + return result; +} + ++ (NSUnitFuelEfficiency *) milesPerGallon +{ + NSUnitFuelEfficiency *result = [[NSUnitFuelEfficiency alloc] initWithSymbol: @"mpg" + coefficient: 0.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitLength + ++ (instancetype) baseUnit +{ + return [self meters]; +} + +// Base unit - meters + ++ (NSUnitLength *) megameters +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"Mm" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) kilometers +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"kM" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) hectometers +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"hm" + coefficient: 100.0 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) decameters +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"dam" + coefficient: 10 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) meters +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"meters" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) decimeters +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"dm" + coefficient: 0.1 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) centimeters +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"cm" + coefficient: 0.01 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) millimeters +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"mm" + coefficient: 0.001 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) micrometers +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"um" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) nanometers +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"nm" + coefficient: 1e-9 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) picometers +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"pm" + coefficient: 1e-12 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) inches +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"in" + coefficient: 0.254 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) feet +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"ft" + coefficient: 0.3048 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) yards +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"yd" + coefficient: 0.9144 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) miles +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"mi" + coefficient: 1609.34 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) scandinavianMiles +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"smi" + coefficient: 10000 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) lightyears +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"ly" + coefficient: 9.461e+15 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) nauticalMiles +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"NM" + coefficient: 1852.0 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) fathoms +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"ftm" + coefficient: 1.8288 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) furlongs +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"fur" + coefficient: 0.0 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) astronomicalUnits +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"ua" + coefficient: 1.496e+11 + constant: 0.0]; + return result; +} + ++ (NSUnitLength *) parsecs +{ + NSUnitLength *result = [[NSUnitLength alloc] initWithSymbol: @"pc" + coefficient: 3.086e+16 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitIlluminance + ++ (instancetype) baseUnit +{ + return [self lux]; +} + +// Base unit - lux ++ (NSUnitIlluminance *) lux +{ + NSUnitIlluminance *result = [[NSUnitIlluminance alloc] initWithSymbol: @"lux" + coefficient: 1.0 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitMass + ++ (instancetype) baseUnit +{ + return [self kilograms]; +} + +// Base unit - kilograms + ++ (NSUnitMass *) kilograms +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kg" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) grams +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"g" + coefficient: 0.001 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) decigrams +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"dg" + coefficient: 0.0001 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) centigrams +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"cg" + coefficient: 0.00001 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) milligrams +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"mg" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) micrograms +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"ug" + coefficient: 1e9 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) nanograms +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"ng" + coefficient: 1e-12 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) picograms +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"pg" + coefficient: 1e-15 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) ounces +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"oz" + coefficient: 0.0283495 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) pounds +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"lb" + coefficient: 0.453592 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) stones +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"st" + coefficient: 0.157473 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) metricTons +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"t" + coefficient: 1000 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) shortTons +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"ton" + coefficient: 907.185 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) carats +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"ct" + coefficient: 0.0002 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) ouncesTroy +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"oz t" + coefficient: 0.03110348 + constant: 0.0]; + return result; +} + ++ (NSUnitMass *) slugs +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"slug" + coefficient: 14.5939 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitPower + ++ (instancetype) baseUnit +{ + return [self watts]; +} + +// Base unit - watts + ++ (NSUnitPower *) terawatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"TW" + coefficient: 1e12 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) gigawatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"GW" + coefficient: 1e9 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) megawatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"MW" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) kilowatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"kW" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) watts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"W" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) milliwatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"mW" + coefficient: 0.001 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) microwatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"uW" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) nanowatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"nW" + coefficient: 1e-9 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) picowatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"pW" + coefficient: 1e-12 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) femtowatts +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"fW" + coefficient: 1e-15 + constant: 0.0]; + return result; +} + ++ (NSUnitPower *) horsepower +{ + NSUnitPower *result = [[NSUnitPower alloc] initWithSymbol: @"hp" + coefficient: 745.7 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitPressure + ++ (instancetype) baseUnit +{ + return [self newtonsPerMetersSquared]; +} + +// Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) + ++ (NSUnitPressure *) newtonsPerMetersSquared +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"N/m^2" + coefficient: 0.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) gigapascals +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"GPa" + coefficient: 1e9 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) megapascals +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"MPa" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) kilopascals +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"kPa" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) hectopascals +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"hPa" + coefficient: 100.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) inchesOfMercury +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"inHg" + coefficient: 3386.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) bars +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"bars" + coefficient: 100000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) millibars +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"mbars" + coefficient: 100.0 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) millimetersOfMercury +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"mmHg" + coefficient: 133.322 + constant: 0.0]; + return result; +} + ++ (NSUnitPressure *) poundsForcePerSquareInch +{ + NSUnitPressure *result = [[NSUnitPressure alloc] initWithSymbol: @"psi" + coefficient: 6894.76 + constant: 0.0]; + return result; +} + + +@end + +@implementation NSUnitSpeed ++ (instancetype) baseUnit +{ + return [self metersPerSecond]; +} + +// Base unit - metersPerSecond ++ (NSUnitSpeed *) metersPerSecond +{ + NSUnitSpeed *result = [[NSUnitSpeed alloc] initWithSymbol: @"m/s" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitSpeed *) kilometersPerHour +{ + NSUnitSpeed *result = [[NSUnitSpeed alloc] initWithSymbol: @"km/h" + coefficient: 0.277778 + constant: 0.0]; + return result; +} + ++ (NSUnitSpeed *) milesPerHour +{ + NSUnitSpeed *result = [[NSUnitSpeed alloc] initWithSymbol: @"mph" + coefficient: 0.44704 + constant: 0.0]; + return result; +} + ++ (NSUnitSpeed *) knots +{ + NSUnitSpeed *result = [[NSUnitSpeed alloc] initWithSymbol: @"kn" + coefficient: 0.51444 + constant: 0.0]; + return result; +} + +@end + +@implementation NSUnitTemperature ++ (instancetype) baseUnit +{ + return [self kelvin]; +} + +// Base unit - kelvin ++ (NSUnitTemperature *) kelvin +{ + NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"K" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitTemperature *) celsius +{ + NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"C" + coefficient: 1.0 + constant: 273.15]; + return result; +} + ++ (NSUnitTemperature *) fahrenheit +{ + NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"F" + coefficient: 0.55555555555556 + constant: 255.37222222222427]; + return result; +} +@end + +@implementation NSUnitVolume ++ (instancetype) baseUnit +{ + return [self liters]; +} + +// Base unit - liters ++ (NSUnitVolume *) megaliters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"ML" + coefficient: 1000000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) kiloliters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"kL" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) liters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"L" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) deciliters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"dL" + coefficient: 0.1 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) centiliters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"cL" + coefficient: 0.01 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) milliliters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"mL" + coefficient: 0.001 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicKilometers +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"km^3" + coefficient: 1e12 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicMeters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"m^3" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicDecimeters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"dm^3" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicCentimeters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"cm^3" + coefficient: 0.0001 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicMillimeters +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"mm^3" + coefficient: 0.000001 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicInches +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"in^3" + coefficient: 0.0163871 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicFeet +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"ft^3" + coefficient: 28.3168 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicYards +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"yd^3" + coefficient: 764.555 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cubicMiles +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"mi^3" + coefficient: 4.168e+12 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) acreFeet +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"af" + coefficient: 1.233e+6 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) bushels +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"bsh" + coefficient: 32.2391 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) teaspoons +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"tsp" + coefficient: 0.00492892 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) tablespoons +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"tbsp" + coefficient: 0.0147868 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) fluidOunces +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"fl oz" + coefficient: 0.295735 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) cups +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"cups" + coefficient: 0.24 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) pints +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"pt" + coefficient: 0.473176 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) quarts +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"qt" + coefficient: 0.946353 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) gallons +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"gal" + coefficient: 3.78541 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) imperialTeaspoons +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"tsp" + coefficient: 0.00591939 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) imperialTablespoons +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"tbsp" + coefficient: 0.0177582 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) imperialFluidOunces +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"fl oz" + coefficient: 0.0284131 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) imperialPints +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"pt" + coefficient: 0.568261 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) imperialQuarts +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"qt" + coefficient: 1.13652 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) imperialGallons +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"gal" + coefficient: 4.54609 + constant: 0.0]; + return result; +} + ++ (NSUnitVolume *) metricCups +{ + NSUnitVolume *result = [[NSUnitVolume alloc] initWithSymbol: @"metric cup" + coefficient: 0.25 + constant: 0.0]; + return result; +} + + +@end