From 4db9aa0298676de730d43ce6b302e7bdb4bac5bc Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 30 Sep 2019 15:59:50 -0400 Subject: [PATCH 01/79] Units of measure --- Headers/Foundation/NSMassFormatter.h | 48 +++++++++++++++++++++ Headers/Foundation/NSMeasurement.h | 48 +++++++++++++++++++++ Headers/Foundation/NSMeasurementFormatter.h | 48 +++++++++++++++++++++ Headers/Foundation/NSUnit.h | 48 +++++++++++++++++++++ Source/NSMassFormatter.m | 31 +++++++++++++ Source/NSMeasurement.m | 31 +++++++++++++ Source/NSMeasurementFormatter.m | 31 +++++++++++++ Source/NSUnit.m | 31 +++++++++++++ 8 files changed, 316 insertions(+) create mode 100644 Headers/Foundation/NSMassFormatter.h create mode 100644 Headers/Foundation/NSMeasurement.h create mode 100644 Headers/Foundation/NSMeasurementFormatter.h create mode 100644 Headers/Foundation/NSUnit.h create mode 100644 Source/NSMassFormatter.m create mode 100644 Source/NSMeasurement.m create mode 100644 Source/NSMeasurementFormatter.m create mode 100644 Source/NSUnit.m diff --git a/Headers/Foundation/NSMassFormatter.h b/Headers/Foundation/NSMassFormatter.h new file mode 100644 index 000000000..6fc43889f --- /dev/null +++ b/Headers/Foundation/NSMassFormatter.h @@ -0,0 +1,48 @@ + +/* 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_0, GS_API_LATEST) + +@interface NSMassFormatter : NSObject + +@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..d95c14239 --- /dev/null +++ b/Headers/Foundation/NSMeasurement.h @@ -0,0 +1,48 @@ + +/* Definition of class NSMeasurement + 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 _NSMeasurement_h_GNUSTEP_BASE_INCLUDE +#define _NSMeasurement_h_GNUSTEP_BASE_INCLUDE + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) + +@interface NSMeasurement : NSObject + +@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..d9ae8edd6 --- /dev/null +++ b/Headers/Foundation/NSMeasurementFormatter.h @@ -0,0 +1,48 @@ + +/* 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 + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) + +@interface NSMeasurementFormatter : NSObject + +@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..a52263249 --- /dev/null +++ b/Headers/Foundation/NSUnit.h @@ -0,0 +1,48 @@ + +/* Definition of class NSUnit + 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 _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_0, GS_API_LATEST) + +@interface NSUnit : NSObject + +@end + +#if defined(__cplusplus) +} +#endif + +#endif /* GS_API_MACOSX */ + +#endif /* _NSUnit_h_GNUSTEP_BASE_INCLUDE */ + diff --git a/Source/NSMassFormatter.m b/Source/NSMassFormatter.m new file mode 100644 index 000000000..27df3c32f --- /dev/null +++ b/Source/NSMassFormatter.m @@ -0,0 +1,31 @@ + +/* 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 + +@implementation NSMassFormatter + +@end + diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m new file mode 100644 index 000000000..91917bb94 --- /dev/null +++ b/Source/NSMeasurement.m @@ -0,0 +1,31 @@ + +/* Implementation of class NSMeasurement + 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 + +@implementation NSMeasurement + +@end + diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m new file mode 100644 index 000000000..81cde7709 --- /dev/null +++ b/Source/NSMeasurementFormatter.m @@ -0,0 +1,31 @@ + +/* Implementation 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. +*/ + +#include + +@implementation NSMeasurementFormatter + +@end + diff --git a/Source/NSUnit.m b/Source/NSUnit.m new file mode 100644 index 000000000..57a268ebd --- /dev/null +++ b/Source/NSUnit.m @@ -0,0 +1,31 @@ + +/* Implementation of class NSUnit + 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 + +@implementation NSUnit + +@end + From e95de25ea02e19849bb89fd814952dca04f7a511 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 30 Sep 2019 16:06:11 -0400 Subject: [PATCH 02/79] Compiling skeletons. --- Source/GNUmakefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Source/GNUmakefile b/Source/GNUmakefile index c4c324534..27cd54257 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -248,6 +248,9 @@ NSLocale.m \ NSLock.m \ NSLog.m \ NSMapTable.m \ +NSMassFormatter.m \ +NSMeasurementFormatter.m \ +NSMeasurement.m \ NSMetadata.m \ NSMethodSignature.m \ NSNotification.m \ @@ -292,6 +295,7 @@ NSScriptKeyValueCoding.m \ NSScriptObjectSpecifiers.m \ NSScriptStandardSuiteCommands.m \ NSScriptSuiteRegistry.m \ +NSUnit.m \ NSUserScriptTask.m \ NSSerializer.m \ NSSet.m \ @@ -438,6 +442,9 @@ NSKeyValueObserving.h \ NSLocale.h \ NSLock.h \ NSMapTable.h \ +NSMassFormatter.h \ +NSMeasurementFormatter.h \ +NSMeasurement.h \ NSMetadata.h \ NSMethodSignature.h \ NSNetServices.h \ @@ -477,6 +484,7 @@ NSScriptKeyValueCoding.h \ NSScriptObjectSpecifiers.h \ NSScriptStandardSuiteCommands.h \ NSScriptSuiteRegistry.h \ +NSUnit.h \ NSUserScriptTask.h \ NSScriptWhoseTests.h \ NSSerialization.h \ From 4c51378c0c9e92b91342c12e458b42095226f1cd Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 00:24:46 -0400 Subject: [PATCH 03/79] Implementation of copying and copy protocols for base class --- Headers/Foundation/NSUnit.h | 14 +++++++-- Source/NSUnit.m | 62 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index a52263249..0996f20b2 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -32,12 +32,22 @@ extern "C" { #endif -#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) +#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST) -@interface NSUnit : NSObject +@interface NSUnit : NSObject +{ + NSString *_symbol; +} + ++ (instancetype)new; +- (instancetype)init; +- (instancetype)initWithSymbol:(NSString *)symbol; +- (NSString *)symbol; @end + + #if defined(__cplusplus) } #endif diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 57a268ebd..98aaa0f4e 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -27,5 +27,67 @@ @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 decodeObjectRorKey: @"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 From b2f4495a75573a91bd44279c5792d5d64872c3dc Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 00:57:17 -0400 Subject: [PATCH 04/79] Correction for coding... add base class for converter. --- Headers/Foundation/NSUnit.h | 6 ++++++ Source/NSUnit.m | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 0996f20b2..f2241d651 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -34,6 +34,12 @@ extern "C" { #if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST) +@interface NSUnitConverter : NSObject +- (double)baseUnitValueFromValue:(double)value; +- (double)valueFromBaseUnitValue:(double)baseUnitValue; +@end + + @interface NSUnit : NSObject { NSString *_symbol; diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 98aaa0f4e..fbbc21b01 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -24,9 +24,21 @@ */ #include +#include + +@implementation NSUnitConverter +- (double)baseUnitValueFromValue:(double)value +{ + return 0.0; +} + +- (double)valueFromBaseUnitValue:(double)baseUnitValue +{ + return 0.0; +} +@end @implementation NSUnit - + (instancetype)new { @@ -57,7 +69,7 @@ { if([coder allowsKeyedCoding]) { - _symbol = [coder decodeObjectRorKey: @"symbol"]; + _symbol = [coder decodeObjectForKey: @"symbol"]; } else { From 7aee0a7c6ae24a2bab4532e9431e01d158dd503b Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 02:05:18 -0400 Subject: [PATCH 05/79] Implementation of Linear converter --- Headers/Foundation/NSUnit.h | 15 +++++++++++- Source/NSUnit.m | 49 +++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 3 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index f2241d651..21e2313bb 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -39,7 +39,20 @@ extern "C" { - (double)valueFromBaseUnitValue:(double)baseUnitValue; @end - +@interface NSUnitConverterLinear : NSUnitConverter +{ + double _coefficient; + double _constant; +} + +- (instancetype) initWithCoefficient: (double)coefficient; +- (instancetype) initWithCoefficient: (double)coefficient + constant: (double)constant; + +- (double) coefficient; +- (double) constant; +@end + @interface NSUnit : NSObject { NSString *_symbol; diff --git a/Source/NSUnit.m b/Source/NSUnit.m index fbbc21b01..67cb4f1a6 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -38,8 +38,54 @@ } @end + +@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 +{ + return nil; +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ +} + +- (double) coefficient +{ + return _coefficient; +} + +- (double) constant +{ + return _constant; +} +@end + + @implementation NSUnit - + (instancetype)new { return [[self alloc] init]; @@ -100,6 +146,5 @@ { return _symbol; } - @end From 0dd8791f2e3813d341b446672492e5cdc21095ac Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 05:08:37 -0400 Subject: [PATCH 06/79] Skeletal implementation of NSDimension --- Headers/Foundation/NSUnit.h | 17 ++++++++++++++-- Source/NSUnit.m | 40 ++++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 21e2313bb..363dcc147 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -34,25 +34,26 @@ extern "C" { #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; @@ -65,6 +66,18 @@ extern "C" { @end +// Dimension using units.... +@interface NSDimension : NSUnit +{ + NSUInteger _reserved; + NSUnitConverter *_converter; +} + +- (NSUnitConverter *) converter; +- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *) converter ; ++ (instancetype) baseUnit; + +@end #if defined(__cplusplus) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 67cb4f1a6..7b9d83265 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -66,11 +66,28 @@ - (id) initWithCoder: (NSCoder *)coder { - return nil; + 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]) + { + + } + else + { + } } - (double) coefficient @@ -148,3 +165,24 @@ } @end + +// Dimension using units.... +@implementation NSDimension + +- (NSUnitConverter *) converter +{ + return _converter; +} + +- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *) converter +{ + return nil; +} + ++ (instancetype) baseUnit +{ + return nil; +} + +@end + From 9f84664b05f8fab14bdd0938391136e3a7117266 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 05:12:07 -0400 Subject: [PATCH 07/79] Add encodings --- Source/NSUnit.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 7b9d83265..53225565c 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -1,4 +1,3 @@ - /* Implementation of class NSUnit Copyright (C) 2019 Free Software Foundation, Inc. @@ -83,10 +82,13 @@ { 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]; } } From ea074469c102e2d5f40b32866bd4fc2524fcd404 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 05:47:03 -0400 Subject: [PATCH 08/79] Add predefined measurement classes --- Headers/Foundation/NSUnit.h | 332 ++++++++++++++++++++++++++++++++++++ Source/NSUnit.m | 9 +- 2 files changed, 336 insertions(+), 5 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 363dcc147..c1d4187d1 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -79,6 +79,338 @@ extern "C" { @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 *)poundsMass; +- (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) } diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 53225565c..685a7c252 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -24,7 +24,9 @@ #include #include +#include +// Abstract conversion... @implementation NSUnitConverter - (double)baseUnitValueFromValue:(double)value { @@ -37,9 +39,8 @@ } @end - +// Linear conversion... @implementation NSUnitConverterLinear - - (instancetype) initWithCoefficient: (double)coefficient { self = [super init]; @@ -103,7 +104,7 @@ } @end - +// Abstract unit... @implementation NSUnit + (instancetype)new { @@ -170,7 +171,6 @@ // Dimension using units.... @implementation NSDimension - - (NSUnitConverter *) converter { return _converter; @@ -185,6 +185,5 @@ { return nil; } - @end From 1b80522f63439bffc3a433c5876c62b24589adb0 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 2 Oct 2019 07:09:32 -0400 Subject: [PATCH 09/79] Correct formatting --- Headers/Foundation/NSUnit.h | 335 ++++++++++++++++++------------------ 1 file changed, 167 insertions(+), 168 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index c1d4187d1..38e6dafa8 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -1,4 +1,3 @@ - /* Definition of class NSUnit Copyright (C) 2019 Free Software Foundation, Inc. @@ -61,8 +60,8 @@ extern "C" { + (instancetype)new; - (instancetype)init; -- (instancetype)initWithSymbol:(NSString *)symbol; -- (NSString *)symbol; +- (instancetype)initWithSymbol:(NSString *) symbol; +- (NSString *) symbol; @end @@ -74,7 +73,7 @@ extern "C" { } - (NSUnitConverter *) converter; -- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *) converter ; +- (instancetype) initWithSymbol: (NSString *) symbol converter: (NSUnitConverter *) converter ; + (instancetype) baseUnit; @end @@ -85,8 +84,8 @@ extern "C" { Base unit - metersPerSecondSquared */ -- (NSUnitAcceleration *)metersPerSecondSquared; -- (NSUnitAcceleration *)gravity; +- (NSUnitAcceleration *) metersPerSecondSquared; +- (NSUnitAcceleration *) gravity; @end @@ -95,12 +94,12 @@ extern "C" { Base unit - degrees */ -- (NSUnitAngle *)degrees; -- (NSUnitAngle *)arcMinutes; -- (NSUnitAngle *)arcSeconds; -- (NSUnitAngle *)radians; -- (NSUnitAngle *)gradians; -- (NSUnitAngle *)revolutions; +- (NSUnitAngle *) degrees; +- (NSUnitAngle *) arcMinutes; +- (NSUnitAngle *) arcSeconds; +- (NSUnitAngle *) radians; +- (NSUnitAngle *) gradians; +- (NSUnitAngle *) revolutions; @end @@ -109,20 +108,20 @@ extern "C" { 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; +- (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 @@ -131,10 +130,10 @@ extern "C" { Base unit - gramsPerLiter */ -- (NSUnitConcentrationMass *)gramsPerLiter; -- (NSUnitConcentrationMass *)milligramsPerDeciliter; +- (NSUnitConcentrationMass *) gramsPerLiter; +- (NSUnitConcentrationMass *) milligramsPerDeciliter; -+ (NSUnitConcentrationMass *)millimolesPerLiterWithGramsPerMole:(double)gramsPerMole; ++ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole; @end @@ -142,7 +141,7 @@ extern "C" { /* Base unit - partsPerMillion */ -- (NSUnitDispersion *)partsPerMillion; +- (NSUnitDispersion *) partsPerMillion; @end @@ -151,9 +150,9 @@ extern "C" { Base unit - seconds */ -- (NSUnitDuration *)seconds; -- (NSUnitDuration *)minutes; -- (NSUnitDuration *)hours; +- (NSUnitDuration *) seconds; +- (NSUnitDuration *) minutes; +- (NSUnitDuration *) hours; @end @@ -162,12 +161,12 @@ extern "C" { Base unit - coulombs */ -- (NSUnitElectricCharge *)coulombs; -- (NSUnitElectricCharge *)megaampereHours; -- (NSUnitElectricCharge *)kiloampereHours; -- (NSUnitElectricCharge *)ampereHours; -- (NSUnitElectricCharge *)milliampereHours; -- (NSUnitElectricCharge *)microampereHours; +- (NSUnitElectricCharge *) coulombs; +- (NSUnitElectricCharge *) megaampereHours; +- (NSUnitElectricCharge *) kiloampereHours; +- (NSUnitElectricCharge *) ampereHours; +- (NSUnitElectricCharge *) milliampereHours; +- (NSUnitElectricCharge *) microampereHours; @end @@ -176,11 +175,11 @@ extern "C" { Base unit - amperes */ -- (NSUnitElectricCurrent *)megaamperes; -- (NSUnitElectricCurrent *)kiloamperes; -- (NSUnitElectricCurrent *)amperes; -- (NSUnitElectricCurrent *)milliamperes; -- (NSUnitElectricCurrent *)microamperes; +- (NSUnitElectricCurrent *) megaamperes; +- (NSUnitElectricCurrent *) kiloamperes; +- (NSUnitElectricCurrent *) amperes; +- (NSUnitElectricCurrent *) milliamperes; +- (NSUnitElectricCurrent *) microamperes; @end @@ -189,11 +188,11 @@ extern "C" { Base unit - volts */ -- (NSUnitElectricPotentialDifference *)megavolts; -- (NSUnitElectricPotentialDifference *)kilovolts; -- (NSUnitElectricPotentialDifference *)volts; -- (NSUnitElectricPotentialDifference *)millivolts; -- (NSUnitElectricPotentialDifference *)microvolts; +- (NSUnitElectricPotentialDifference *) megavolts; +- (NSUnitElectricPotentialDifference *) kilovolts; +- (NSUnitElectricPotentialDifference *) volts; +- (NSUnitElectricPotentialDifference *) millivolts; +- (NSUnitElectricPotentialDifference *) microvolts; @end @@ -202,11 +201,11 @@ extern "C" { Base unit - ohms */ -- (NSUnitElectricResistance *)megaohms; -- (NSUnitElectricResistance *)kiloohms; -- (NSUnitElectricResistance *)ohms; -- (NSUnitElectricResistance *)milliohms; -- (NSUnitElectricResistance *)microohms; +- (NSUnitElectricResistance *) megaohms; +- (NSUnitElectricResistance *) kiloohms; +- (NSUnitElectricResistance *) ohms; +- (NSUnitElectricResistance *) milliohms; +- (NSUnitElectricResistance *) microohms; @end @@ -215,11 +214,11 @@ extern "C" { Base unit - joules */ -- (NSUnitEnergy *)kilojoules; -- (NSUnitEnergy *)joules; -- (NSUnitEnergy *)kilocalories; -- (NSUnitEnergy *)calories; -- (NSUnitEnergy *)kilowattHours; +- (NSUnitEnergy *) kilojoules; +- (NSUnitEnergy *) joules; +- (NSUnitEnergy *) kilocalories; +- (NSUnitEnergy *) calories; +- (NSUnitEnergy *) kilowattHours; @end @@ -228,14 +227,14 @@ extern "C" { Base unit - hertz */ -- (NSUnitFrequency *)terahertz; -- (NSUnitFrequency *)gigahertz; -- (NSUnitFrequency *)megahertz; -- (NSUnitFrequency *)kilohertz; -- (NSUnitFrequency *)hertz; -- (NSUnitFrequency *)millihertz; -- (NSUnitFrequency *)microhertz; -- (NSUnitFrequency *)nanohertz; +- (NSUnitFrequency *) terahertz; +- (NSUnitFrequency *) gigahertz; +- (NSUnitFrequency *) megahertz; +- (NSUnitFrequency *) kilohertz; +- (NSUnitFrequency *) hertz; +- (NSUnitFrequency *) millihertz; +- (NSUnitFrequency *) microhertz; +- (NSUnitFrequency *) nanohertz; @end @@ -244,9 +243,9 @@ extern "C" { Base unit - litersPer100Kilometers */ -- (NSUnitFuelEfficiency *)litersPer100Kilometers; -- (NSUnitFuelEfficiency *)milesPerImperialGallon; -- (NSUnitFuelEfficiency *)milesPerGallon; +- (NSUnitFuelEfficiency *) litersPer100Kilometers; +- (NSUnitFuelEfficiency *) milesPerImperialGallon; +- (NSUnitFuelEfficiency *) milesPerGallon; @end @@ -255,28 +254,28 @@ extern "C" { 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; +- (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 @@ -285,7 +284,7 @@ extern "C" { Base unit - lux */ -- (NSUnitIlluminance *)lux; +- (NSUnitIlluminance *) lux; @end @@ -294,22 +293,22 @@ extern "C" { Base unit - kilograms */ -- (NSUnitMass *)kilograms; -- (NSUnitMass *)grams; -- (NSUnitMass *)decigrams; -- (NSUnitMass *)centigrams; -- (NSUnitMass *)milligrams; -- (NSUnitMass *)micrograms; -- (NSUnitMass *)nanograms; -- (NSUnitMass *)picograms; -- (NSUnitMass *)ounces; -- (NSUnitMass *)poundsMass; -- (NSUnitMass *)stones; -- (NSUnitMass *)metricTons; -- (NSUnitMass *)shortTons; -- (NSUnitMass *)carats; -- (NSUnitMass *)ouncesTroy; -- (NSUnitMass *)slugs; +- (NSUnitMass *) kilograms; +- (NSUnitMass *) grams; +- (NSUnitMass *) decigrams; +- (NSUnitMass *) centigrams; +- (NSUnitMass *) milligrams; +- (NSUnitMass *) micrograms; +- (NSUnitMass *) nanograms; +- (NSUnitMass *) picograms; +- (NSUnitMass *) ounces; +- (NSUnitMass *) poundsMass; +- (NSUnitMass *) stones; +- (NSUnitMass *) metricTons; +- (NSUnitMass *) shortTons; +- (NSUnitMass *) carats; +- (NSUnitMass *) ouncesTroy; +- (NSUnitMass *) slugs; @end @@ -318,17 +317,17 @@ extern "C" { 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; +- (NSUnitPower *) terawatts; +- (NSUnitPower *) gigawatts; +- (NSUnitPower *) megawatts; +- (NSUnitPower *) kilowatts; +- (NSUnitPower *) watts; +- (NSUnitPower *) milliwatts; +- (NSUnitPower *) microwatts; +- (NSUnitPower *) nanowatts; +- (NSUnitPower *) picowatts; +- (NSUnitPower *) femtowatts; +- (NSUnitPower *) horsepower; @end @@ -337,16 +336,16 @@ extern "C" { 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; +- (NSUnitPressure *) newtonsPerMetersSquared; +- (NSUnitPressure *) gigapascals; +- (NSUnitPressure *) megapascals; +- (NSUnitPressure *) kilopascals; +- (NSUnitPressure *) hectopascals; +- (NSUnitPressure *) inchesOfMercury; +- (NSUnitPressure *) bars; +- (NSUnitPressure *) millibars; +- (NSUnitPressure *) millimetersOfMercury; +- (NSUnitPressure *) poundsForcePerSquareInch; @end @@ -355,10 +354,10 @@ extern "C" { Base unit - metersPerSecond */ -- (NSUnitSpeed *)metersPerSecond; -- (NSUnitSpeed *)kilometersPerHour; -- (NSUnitSpeed *)milesPerHour; -- (NSUnitSpeed *)knots; +- (NSUnitSpeed *) metersPerSecond; +- (NSUnitSpeed *) kilometersPerHour; +- (NSUnitSpeed *) milesPerHour; +- (NSUnitSpeed *) knots; @end @@ -366,9 +365,9 @@ extern "C" { /* Base unit - kelvin */ -- (NSUnitTemperature *)kelvin; -- (NSUnitTemperature *)celsius; -- (NSUnitTemperature *)fahrenheit; +- (NSUnitTemperature *) kelvin; +- (NSUnitTemperature *) celsius; +- (NSUnitTemperature *) fahrenheit; @end @@ -378,37 +377,37 @@ extern "C" { 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; +- (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 From 1e794f8d92f3a77ef739b278e4fe81990d54e4a4 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 3 Oct 2019 22:29:00 -0400 Subject: [PATCH 10/79] Skeletal implementation of Units --- Headers/Foundation/NSUnit.h | 42 ++--- Source/NSUnit.m | 333 ++++++++++++++++++++++++++++++++++++ 2 files changed, 354 insertions(+), 21 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 38e6dafa8..94b6e518b 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -79,7 +79,7 @@ extern "C" { @end // Predefined.... -@interface NSUnitAcceleration : NSDimension +@interface NSUnitAcceleration : NSDimension /* Base unit - metersPerSecondSquared */ @@ -89,7 +89,7 @@ extern "C" { @end -@interface NSUnitAngle : NSDimension +@interface NSUnitAngle : NSDimension /* Base unit - degrees */ @@ -103,7 +103,7 @@ extern "C" { @end -@interface NSUnitArea : NSDimension +@interface NSUnitArea : NSDimension /* Base unit - squareMeters */ @@ -125,7 +125,7 @@ extern "C" { @end -@interface NSUnitConcentrationMass : NSDimension +@interface NSUnitConcentrationMass : NSDimension /* Base unit - gramsPerLiter */ @@ -137,7 +137,7 @@ extern "C" { @end -@interface NSUnitDispersion : NSDimension +@interface NSUnitDispersion : NSDimension /* Base unit - partsPerMillion */ @@ -145,7 +145,7 @@ extern "C" { @end -@interface NSUnitDuration : NSDimension +@interface NSUnitDuration : NSDimension /* Base unit - seconds */ @@ -156,7 +156,7 @@ extern "C" { @end -@interface NSUnitElectricCharge : NSDimension +@interface NSUnitElectricCharge : NSDimension /* Base unit - coulombs */ @@ -170,7 +170,7 @@ extern "C" { @end -@interface NSUnitElectricCurrent : NSDimension +@interface NSUnitElectricCurrent : NSDimension /* Base unit - amperes */ @@ -183,7 +183,7 @@ extern "C" { @end -@interface NSUnitElectricPotentialDifference : NSDimension +@interface NSUnitElectricPotentialDifference : NSDimension /* Base unit - volts */ @@ -196,7 +196,7 @@ extern "C" { @end -@interface NSUnitElectricResistance : NSDimension +@interface NSUnitElectricResistance : NSDimension /* Base unit - ohms */ @@ -209,7 +209,7 @@ extern "C" { @end -@interface NSUnitEnergy : NSDimension +@interface NSUnitEnergy : NSDimension /* Base unit - joules */ @@ -222,7 +222,7 @@ extern "C" { @end -@interface NSUnitFrequency : NSDimension +@interface NSUnitFrequency : NSDimension /* Base unit - hertz */ @@ -238,7 +238,7 @@ extern "C" { @end -@interface NSUnitFuelEfficiency : NSDimension +@interface NSUnitFuelEfficiency : NSDimension /* Base unit - litersPer100Kilometers */ @@ -249,7 +249,7 @@ extern "C" { @end -@interface NSUnitLength : NSDimension +@interface NSUnitLength : NSDimension /* Base unit - meters */ @@ -279,7 +279,7 @@ extern "C" { @end -@interface NSUnitIlluminance : NSDimension +@interface NSUnitIlluminance : NSDimension /* Base unit - lux */ @@ -288,7 +288,7 @@ extern "C" { @end -@interface NSUnitMass : NSDimension +@interface NSUnitMass : NSDimension /* Base unit - kilograms */ @@ -312,7 +312,7 @@ extern "C" { @end -@interface NSUnitPower : NSDimension +@interface NSUnitPower : NSDimension /* Base unit - watts */ @@ -331,7 +331,7 @@ extern "C" { @end -@interface NSUnitPressure : NSDimension +@interface NSUnitPressure : NSDimension /* Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) */ @@ -349,7 +349,7 @@ extern "C" { @end -@interface NSUnitSpeed : NSDimension +@interface NSUnitSpeed : NSDimension /* Base unit - metersPerSecond */ @@ -361,7 +361,7 @@ extern "C" { @end -@interface NSUnitTemperature : NSDimension +@interface NSUnitTemperature : NSDimension /* Base unit - kelvin */ @@ -372,7 +372,7 @@ extern "C" { @end -@interface NSUnitVolume : NSDimension +@interface NSUnitVolume : NSDimension /* Base unit - liters */ diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 685a7c252..946f57e4c 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -187,3 +187,336 @@ } @end + +// Predefined.... +@implementation NSUnitAcceleration +/* + Base unit - metersPerSecondSquared + */ + +- (NSUnitAcceleration *) metersPerSecondSquared { return nil; } +- (NSUnitAcceleration *) gravity { return nil; } + +@end + +@implementation NSUnitAngle +/* + Base unit - degrees + */ + +- (NSUnitAngle *) degrees { return nil; } +- (NSUnitAngle *) arcMinutes { return nil; } +- (NSUnitAngle *) arcSeconds { return nil; } +- (NSUnitAngle *) radians { return nil; } +- (NSUnitAngle *) gradians { return nil; } +- (NSUnitAngle *) revolutions { return nil; } + +@end + +@implementation NSUnitArea +/* + Base unit - squareMeters + */ + +- (NSUnitArea *) squareMegameters { return nil; } +- (NSUnitArea *) squareKilometers { return nil; } +- (NSUnitArea *) squareMeters { return nil; } +- (NSUnitArea *) squareCentimeters { return nil; } +- (NSUnitArea *) squareMillimeters { return nil; } +- (NSUnitArea *) squareMicrometers { return nil; } +- (NSUnitArea *) squareNanometers { return nil; } +- (NSUnitArea *) squareInches { return nil; } +- (NSUnitArea *) squareFeet { return nil; } +- (NSUnitArea *) squareYards { return nil; } +- (NSUnitArea *) squareMiles { return nil; } +- (NSUnitArea *) acres { return nil; } +- (NSUnitArea *) ares { return nil; } +- (NSUnitArea *) hectares { return nil; } + +@end + +@implementation NSUnitConcentrationMass +/* + Base unit - gramsPerLiter + */ + +- (NSUnitConcentrationMass *) gramsPerLiter { return nil; } +- (NSUnitConcentrationMass *) milligramsPerDeciliter { return nil; } + ++ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole { return nil; } + +@end + +@implementation NSUnitDispersion +/* + Base unit - partsPerMillion + */ +- (NSUnitDispersion *) partsPerMillion { return nil; } + +@end + +@implementation NSUnitDuration +/* + Base unit - seconds + */ + +- (NSUnitDuration *) seconds { return nil; } +- (NSUnitDuration *) minutes { return nil; } +- (NSUnitDuration *) hours { return nil; } + +@end + +@implementation NSUnitElectricCharge +/* + Base unit - coulombs + */ + +- (NSUnitElectricCharge *) coulombs { return nil; } +- (NSUnitElectricCharge *) megaampereHours { return nil; } +- (NSUnitElectricCharge *) kiloampereHours { return nil; } +- (NSUnitElectricCharge *) ampereHours { return nil; } +- (NSUnitElectricCharge *) milliampereHours { return nil; } +- (NSUnitElectricCharge *) microampereHours { return nil; } + +@end + +@implementation NSUnitElectricCurrent +/* + Base unit - amperes + */ + +- (NSUnitElectricCurrent *) megaamperes { return nil; } +- (NSUnitElectricCurrent *) kiloamperes { return nil; } +- (NSUnitElectricCurrent *) amperes { return nil; } +- (NSUnitElectricCurrent *) milliamperes { return nil; } +- (NSUnitElectricCurrent *) microamperes { return nil; } + +@end + +@implementation NSUnitElectricPotentialDifference +/* + Base unit - volts + */ + +- (NSUnitElectricPotentialDifference *) megavolts { return nil; } +- (NSUnitElectricPotentialDifference *) kilovolts { return nil; } +- (NSUnitElectricPotentialDifference *) volts { return nil; } +- (NSUnitElectricPotentialDifference *) millivolts { return nil; } +- (NSUnitElectricPotentialDifference *) microvolts { return nil; } + +@end + +@implementation NSUnitElectricResistance +/* + Base unit - ohms + */ + +- (NSUnitElectricResistance *) megaohms { return nil; } +- (NSUnitElectricResistance *) kiloohms { return nil; } +- (NSUnitElectricResistance *) ohms { return nil; } +- (NSUnitElectricResistance *) milliohms { return nil; } +- (NSUnitElectricResistance *) microohms { return nil; } + +@end + +@implementation NSUnitEnergy +/* + Base unit - joules + */ + +- (NSUnitEnergy *) kilojoules { return nil; } +- (NSUnitEnergy *) joules { return nil; } +- (NSUnitEnergy *) kilocalories { return nil; } +- (NSUnitEnergy *) calories { return nil; } +- (NSUnitEnergy *) kilowattHours { return nil; } + +@end + +@implementation NSUnitFrequency +/* + Base unit - hertz + */ + +- (NSUnitFrequency *) terahertz { return nil; } +- (NSUnitFrequency *) gigahertz { return nil; } +- (NSUnitFrequency *) megahertz { return nil; } +- (NSUnitFrequency *) kilohertz { return nil; } +- (NSUnitFrequency *) hertz { return nil; } +- (NSUnitFrequency *) millihertz { return nil; } +- (NSUnitFrequency *) microhertz { return nil; } +- (NSUnitFrequency *) nanohertz { return nil; } + +@end + +@implementation NSUnitFuelEfficiency +/* + Base unit - litersPer100Kilometers + */ + +- (NSUnitFuelEfficiency *) litersPer100Kilometers { return nil; } +- (NSUnitFuelEfficiency *) milesPerImperialGallon { return nil; } +- (NSUnitFuelEfficiency *) milesPerGallon { return nil; } + +@end + +@implementation NSUnitLength +/* + Base unit - meters + */ + +- (NSUnitLength *) megameters { return nil; } +- (NSUnitLength *) kilometers { return nil; } +- (NSUnitLength *) hectometers { return nil; } +- (NSUnitLength *) decameters { return nil; } +- (NSUnitLength *) meters { return nil; } +- (NSUnitLength *) decimeters { return nil; } +- (NSUnitLength *) centimeters { return nil; } +- (NSUnitLength *) millimeters { return nil; } +- (NSUnitLength *) micrometers { return nil; } +- (NSUnitLength *) nanometers { return nil; } +- (NSUnitLength *) picometers { return nil; } +- (NSUnitLength *) inches { return nil; } +- (NSUnitLength *) feet { return nil; } +- (NSUnitLength *) yards { return nil; } +- (NSUnitLength *) miles { return nil; } +- (NSUnitLength *) scandinavianMiles { return nil; } +- (NSUnitLength *) lightyears { return nil; } +- (NSUnitLength *) nauticalMiles { return nil; } +- (NSUnitLength *) fathoms { return nil; } +- (NSUnitLength *) furlongs { return nil; } +- (NSUnitLength *) astronomicalUnits { return nil; } +- (NSUnitLength *) parsecs { return nil; } + +@end + +@implementation NSUnitIlluminance +/* + Base unit - lux + */ + +- (NSUnitIlluminance *) lux { return nil; } + +@end + +@implementation NSUnitMass +/* + Base unit - kilograms + */ + +- (NSUnitMass *) kilograms { return nil; } +- (NSUnitMass *) grams { return nil; } +- (NSUnitMass *) decigrams { return nil; } +- (NSUnitMass *) centigrams { return nil; } +- (NSUnitMass *) milligrams { return nil; } +- (NSUnitMass *) micrograms { return nil; } +- (NSUnitMass *) nanograms { return nil; } +- (NSUnitMass *) picograms { return nil; } +- (NSUnitMass *) ounces { return nil; } +- (NSUnitMass *) poundsMass { return nil; } +- (NSUnitMass *) stones { return nil; } +- (NSUnitMass *) metricTons { return nil; } +- (NSUnitMass *) shortTons { return nil; } +- (NSUnitMass *) carats { return nil; } +- (NSUnitMass *) ouncesTroy { return nil; } +- (NSUnitMass *) slugs { return nil; } + +@end + +@implementation NSUnitPower +/* + Base unit - watts + */ + +- (NSUnitPower *) terawatts { return nil; } +- (NSUnitPower *) gigawatts { return nil; } +- (NSUnitPower *) megawatts { return nil; } +- (NSUnitPower *) kilowatts { return nil; } +- (NSUnitPower *) watts { return nil; } +- (NSUnitPower *) milliwatts { return nil; } +- (NSUnitPower *) microwatts { return nil; } +- (NSUnitPower *) nanowatts { return nil; } +- (NSUnitPower *) picowatts { return nil; } +- (NSUnitPower *) femtowatts { return nil; } +- (NSUnitPower *) horsepower { return nil; } + +@end + +@implementation NSUnitPressure +/* + Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) + */ + +- (NSUnitPressure *) newtonsPerMetersSquared { return nil; } +- (NSUnitPressure *) gigapascals { return nil; } +- (NSUnitPressure *) megapascals { return nil; } +- (NSUnitPressure *) kilopascals { return nil; } +- (NSUnitPressure *) hectopascals { return nil; } +- (NSUnitPressure *) inchesOfMercury { return nil; } +- (NSUnitPressure *) bars { return nil; } +- (NSUnitPressure *) millibars { return nil; } +- (NSUnitPressure *) millimetersOfMercury { return nil; } +- (NSUnitPressure *) poundsForcePerSquareInch { return nil; } + +@end + +@implementation NSUnitSpeed +/* + Base unit - metersPerSecond + */ + +- (NSUnitSpeed *) metersPerSecond { return nil; } +- (NSUnitSpeed *) kilometersPerHour { return nil; } +- (NSUnitSpeed *) milesPerHour { return nil; } +- (NSUnitSpeed *) knots { return nil; } + +@end + +@implementation NSUnitTemperature +/* + Base unit - kelvin + */ +- (NSUnitTemperature *) kelvin { return nil; } +- (NSUnitTemperature *) celsius { return nil; } +- (NSUnitTemperature *) fahrenheit { return nil; } + + +@end + +@implementation NSUnitVolume +/* + Base unit - liters + */ + +- (NSUnitVolume *) megaliters { return nil; } +- (NSUnitVolume *) kiloliters { return nil; } +- (NSUnitVolume *) liters { return nil; } +- (NSUnitVolume *) deciliters { return nil; } +- (NSUnitVolume *) centiliters { return nil; } +- (NSUnitVolume *) milliliters { return nil; } +- (NSUnitVolume *) cubicKilometers { return nil; } +- (NSUnitVolume *) cubicMeters { return nil; } +- (NSUnitVolume *) cubicDecimeters { return nil; } +- (NSUnitVolume *) cubicCentimeters { return nil; } +- (NSUnitVolume *) cubicMillimeters { return nil; } +- (NSUnitVolume *) cubicInches { return nil; } +- (NSUnitVolume *) cubicFeet { return nil; } +- (NSUnitVolume *) cubicYards { return nil; } +- (NSUnitVolume *) cubicMiles { return nil; } +- (NSUnitVolume *) acreFeet { return nil; } +- (NSUnitVolume *) bushels { return nil; } +- (NSUnitVolume *) teaspoons { return nil; } +- (NSUnitVolume *) tablespoons { return nil; } +- (NSUnitVolume *) fluidOunces { return nil; } +- (NSUnitVolume *) cups { return nil; } +- (NSUnitVolume *) pints { return nil; } +- (NSUnitVolume *) quarts { return nil; } +- (NSUnitVolume *) gallons { return nil; } +- (NSUnitVolume *) imperialTeaspoons { return nil; } +- (NSUnitVolume *) imperialTablespoons { return nil; } +- (NSUnitVolume *) imperialFluidOunces { return nil; } +- (NSUnitVolume *) imperialPints { return nil; } +- (NSUnitVolume *) imperialQuarts { return nil; } +- (NSUnitVolume *) imperialGallons { return nil; } +- (NSUnitVolume *) metricCups { return nil; } + +@end From 9bcf4ea8ad2ac6345df47e4325ef6498bb3802e8 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Fri, 4 Oct 2019 04:05:34 -0400 Subject: [PATCH 11/79] Fix issue with initializer --- Source/NSUnit.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 946f57e4c..38885dfcf 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -28,6 +28,12 @@ // Abstract conversion... @implementation NSUnitConverter +- (instancetype) init +{ + self = [super init]; + return self; +} + - (double)baseUnitValueFromValue:(double)value { return 0.0; @@ -178,7 +184,12 @@ - (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *) converter { - return nil; + self = [super initWithSymbol: symbol]; + if(self != nil) + { + ASSIGN(_converter, converter); + } + return self; } + (instancetype) baseUnit From 51d001ce9648c1ecae5dac5cb45c9eba5f679d02 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 5 Oct 2019 23:09:12 -0400 Subject: [PATCH 12/79] jrmu suggested changing comment format --- Headers/Foundation/NSUnit.h | 2 +- Source/NSUnit.m | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 94b6e518b..cdf896af6 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -68,7 +68,7 @@ extern "C" { // Dimension using units.... @interface NSDimension : NSUnit { - NSUInteger _reserved; + double _value; NSUnitConverter *_converter; } diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 38885dfcf..8a53681ed 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -205,15 +205,14 @@ Base unit - metersPerSecondSquared */ + - (NSUnitAcceleration *) metersPerSecondSquared { return nil; } - (NSUnitAcceleration *) gravity { return nil; } @end @implementation NSUnitAngle -/* - Base unit - degrees - */ +// Base unit - degrees - (NSUnitAngle *) degrees { return nil; } - (NSUnitAngle *) arcMinutes { return nil; } From 5c259ba752f6486e70e49f03140e869ffe01c1aa Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 00:37:30 -0400 Subject: [PATCH 13/79] Change all comments to // --- Source/NSUnit.m | 99 +++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 66 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 8a53681ed..8eb5a032c 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -200,20 +200,17 @@ // Predefined.... -@implementation NSUnitAcceleration -/* - Base unit - metersPerSecondSquared - */ - +@implementation NSUnitAcceleration +// Base unit - metersPerSecondSquared - (NSUnitAcceleration *) metersPerSecondSquared { return nil; } - (NSUnitAcceleration *) gravity { return nil; } @end @implementation NSUnitAngle -// Base unit - degrees +// Base unit - degrees - (NSUnitAngle *) degrees { return nil; } - (NSUnitAngle *) arcMinutes { return nil; } - (NSUnitAngle *) arcSeconds { return nil; } @@ -224,10 +221,8 @@ @end @implementation NSUnitArea -/* - Base unit - squareMeters - */ +// Base unit - squareMeters - (NSUnitArea *) squareMegameters { return nil; } - (NSUnitArea *) squareKilometers { return nil; } - (NSUnitArea *) squareMeters { return nil; } @@ -246,10 +241,8 @@ @end @implementation NSUnitConcentrationMass -/* - Base unit - gramsPerLiter - */ +// Base unit - gramsPerLiter - (NSUnitConcentrationMass *) gramsPerLiter { return nil; } - (NSUnitConcentrationMass *) milligramsPerDeciliter { return nil; } @@ -258,18 +251,15 @@ @end @implementation NSUnitDispersion -/* - Base unit - partsPerMillion - */ + +// Base unit - partsPerMillion - (NSUnitDispersion *) partsPerMillion { return nil; } @end @implementation NSUnitDuration -/* - Base unit - seconds - */ +// Base unit - seconds - (NSUnitDuration *) seconds { return nil; } - (NSUnitDuration *) minutes { return nil; } - (NSUnitDuration *) hours { return nil; } @@ -277,10 +267,8 @@ @end @implementation NSUnitElectricCharge -/* - Base unit - coulombs - */ +// Base unit - coulombs - (NSUnitElectricCharge *) coulombs { return nil; } - (NSUnitElectricCharge *) megaampereHours { return nil; } - (NSUnitElectricCharge *) kiloampereHours { return nil; } @@ -291,10 +279,8 @@ @end @implementation NSUnitElectricCurrent -/* - Base unit - amperes - */ +// Base unit - amperes - (NSUnitElectricCurrent *) megaamperes { return nil; } - (NSUnitElectricCurrent *) kiloamperes { return nil; } - (NSUnitElectricCurrent *) amperes { return nil; } @@ -304,10 +290,8 @@ @end @implementation NSUnitElectricPotentialDifference -/* - Base unit - volts - */ +// Base unit - volts - (NSUnitElectricPotentialDifference *) megavolts { return nil; } - (NSUnitElectricPotentialDifference *) kilovolts { return nil; } - (NSUnitElectricPotentialDifference *) volts { return nil; } @@ -317,10 +301,8 @@ @end @implementation NSUnitElectricResistance -/* - Base unit - ohms - */ +// Base unit - ohms - (NSUnitElectricResistance *) megaohms { return nil; } - (NSUnitElectricResistance *) kiloohms { return nil; } - (NSUnitElectricResistance *) ohms { return nil; } @@ -330,10 +312,8 @@ @end @implementation NSUnitEnergy -/* - Base unit - joules - */ +// Base unit - joules - (NSUnitEnergy *) kilojoules { return nil; } - (NSUnitEnergy *) joules { return nil; } - (NSUnitEnergy *) kilocalories { return nil; } @@ -343,9 +323,8 @@ @end @implementation NSUnitFrequency -/* - Base unit - hertz - */ + +// Base unit - hertz - (NSUnitFrequency *) terahertz { return nil; } - (NSUnitFrequency *) gigahertz { return nil; } @@ -359,9 +338,8 @@ @end @implementation NSUnitFuelEfficiency -/* - Base unit - litersPer100Kilometers - */ + +// Base unit - litersPer100Kilometers - (NSUnitFuelEfficiency *) litersPer100Kilometers { return nil; } - (NSUnitFuelEfficiency *) milesPerImperialGallon { return nil; } @@ -370,9 +348,8 @@ @end @implementation NSUnitLength -/* - Base unit - meters - */ + +// Base unit - meters - (NSUnitLength *) megameters { return nil; } - (NSUnitLength *) kilometers { return nil; } @@ -400,18 +377,16 @@ @end @implementation NSUnitIlluminance -/* - Base unit - lux - */ + +// Base unit - lux - (NSUnitIlluminance *) lux { return nil; } @end @implementation NSUnitMass -/* - Base unit - kilograms - */ + +// Base unit - kilograms - (NSUnitMass *) kilograms { return nil; } - (NSUnitMass *) grams { return nil; } @@ -433,9 +408,8 @@ @end @implementation NSUnitPower -/* - Base unit - watts - */ + +// Base unit - watts - (NSUnitPower *) terawatts { return nil; } - (NSUnitPower *) gigawatts { return nil; } @@ -451,10 +425,9 @@ @end -@implementation NSUnitPressure -/* - Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) - */ +@implementation NSUnitPressure + +// Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) - (NSUnitPressure *) newtonsPerMetersSquared { return nil; } - (NSUnitPressure *) gigapascals { return nil; } @@ -470,10 +443,8 @@ @end @implementation NSUnitSpeed -/* - Base unit - metersPerSecond - */ +// Base unit - metersPerSecond - (NSUnitSpeed *) metersPerSecond { return nil; } - (NSUnitSpeed *) kilometersPerHour { return nil; } - (NSUnitSpeed *) milesPerHour { return nil; } @@ -481,22 +452,18 @@ @end -@implementation NSUnitTemperature -/* - Base unit - kelvin - */ +@implementation NSUnitTemperature + +// Base unit - kelvin - (NSUnitTemperature *) kelvin { return nil; } - (NSUnitTemperature *) celsius { return nil; } - (NSUnitTemperature *) fahrenheit { return nil; } - @end @implementation NSUnitVolume -/* - Base unit - liters - */ +// Base unit - liters - (NSUnitVolume *) megaliters { return nil; } - (NSUnitVolume *) kiloliters { return nil; } - (NSUnitVolume *) liters { return nil; } From 05509ad74b7c2dcb0927885505fa11ce22d8e3a6 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 11:48:21 -0400 Subject: [PATCH 14/79] Implement NSUnitAcceleration --- Headers/Foundation/NSUnit.h | 326 ++++++++++++++++----------------- Source/NSUnit.m | 346 +++++++++++++++++++----------------- 2 files changed, 346 insertions(+), 326 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index cdf896af6..b7627c2aa 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -84,8 +84,8 @@ extern "C" { Base unit - metersPerSecondSquared */ -- (NSUnitAcceleration *) metersPerSecondSquared; -- (NSUnitAcceleration *) gravity; ++ (NSUnitAcceleration *) metersPerSecondSquared; ++ (NSUnitAcceleration *) gravity; @end @@ -94,12 +94,12 @@ extern "C" { Base unit - degrees */ -- (NSUnitAngle *) degrees; -- (NSUnitAngle *) arcMinutes; -- (NSUnitAngle *) arcSeconds; -- (NSUnitAngle *) radians; -- (NSUnitAngle *) gradians; -- (NSUnitAngle *) revolutions; ++ (NSUnitAngle *) degrees; ++ (NSUnitAngle *) arcMinutes; ++ (NSUnitAngle *) arcSeconds; ++ (NSUnitAngle *) radians; ++ (NSUnitAngle *) gradians; ++ (NSUnitAngle *) revolutions; @end @@ -108,20 +108,20 @@ extern "C" { 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; ++ (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 @@ -130,8 +130,8 @@ extern "C" { Base unit - gramsPerLiter */ -- (NSUnitConcentrationMass *) gramsPerLiter; -- (NSUnitConcentrationMass *) milligramsPerDeciliter; ++ (NSUnitConcentrationMass *) gramsPerLiter; ++ (NSUnitConcentrationMass *) milligramsPerDeciliter; + (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole; @@ -141,7 +141,7 @@ extern "C" { /* Base unit - partsPerMillion */ -- (NSUnitDispersion *) partsPerMillion; ++ (NSUnitDispersion *) partsPerMillion; @end @@ -150,9 +150,9 @@ extern "C" { Base unit - seconds */ -- (NSUnitDuration *) seconds; -- (NSUnitDuration *) minutes; -- (NSUnitDuration *) hours; ++ (NSUnitDuration *) seconds; ++ (NSUnitDuration *) minutes; ++ (NSUnitDuration *) hours; @end @@ -161,12 +161,12 @@ extern "C" { Base unit - coulombs */ -- (NSUnitElectricCharge *) coulombs; -- (NSUnitElectricCharge *) megaampereHours; -- (NSUnitElectricCharge *) kiloampereHours; -- (NSUnitElectricCharge *) ampereHours; -- (NSUnitElectricCharge *) milliampereHours; -- (NSUnitElectricCharge *) microampereHours; ++ (NSUnitElectricCharge *) coulombs; ++ (NSUnitElectricCharge *) megaampereHours; ++ (NSUnitElectricCharge *) kiloampereHours; ++ (NSUnitElectricCharge *) ampereHours; ++ (NSUnitElectricCharge *) milliampereHours; ++ (NSUnitElectricCharge *) microampereHours; @end @@ -175,11 +175,11 @@ extern "C" { Base unit - amperes */ -- (NSUnitElectricCurrent *) megaamperes; -- (NSUnitElectricCurrent *) kiloamperes; -- (NSUnitElectricCurrent *) amperes; -- (NSUnitElectricCurrent *) milliamperes; -- (NSUnitElectricCurrent *) microamperes; ++ (NSUnitElectricCurrent *) megaamperes; ++ (NSUnitElectricCurrent *) kiloamperes; ++ (NSUnitElectricCurrent *) amperes; ++ (NSUnitElectricCurrent *) milliamperes; ++ (NSUnitElectricCurrent *) microamperes; @end @@ -188,11 +188,11 @@ extern "C" { Base unit - volts */ -- (NSUnitElectricPotentialDifference *) megavolts; -- (NSUnitElectricPotentialDifference *) kilovolts; -- (NSUnitElectricPotentialDifference *) volts; -- (NSUnitElectricPotentialDifference *) millivolts; -- (NSUnitElectricPotentialDifference *) microvolts; ++ (NSUnitElectricPotentialDifference *) megavolts; ++ (NSUnitElectricPotentialDifference *) kilovolts; ++ (NSUnitElectricPotentialDifference *) volts; ++ (NSUnitElectricPotentialDifference *) millivolts; ++ (NSUnitElectricPotentialDifference *) microvolts; @end @@ -201,11 +201,11 @@ extern "C" { Base unit - ohms */ -- (NSUnitElectricResistance *) megaohms; -- (NSUnitElectricResistance *) kiloohms; -- (NSUnitElectricResistance *) ohms; -- (NSUnitElectricResistance *) milliohms; -- (NSUnitElectricResistance *) microohms; ++ (NSUnitElectricResistance *) megaohms; ++ (NSUnitElectricResistance *) kiloohms; ++ (NSUnitElectricResistance *) ohms; ++ (NSUnitElectricResistance *) milliohms; ++ (NSUnitElectricResistance *) microohms; @end @@ -214,11 +214,11 @@ extern "C" { Base unit - joules */ -- (NSUnitEnergy *) kilojoules; -- (NSUnitEnergy *) joules; -- (NSUnitEnergy *) kilocalories; -- (NSUnitEnergy *) calories; -- (NSUnitEnergy *) kilowattHours; ++ (NSUnitEnergy *) kilojoules; ++ (NSUnitEnergy *) joules; ++ (NSUnitEnergy *) kilocalories; ++ (NSUnitEnergy *) calories; ++ (NSUnitEnergy *) kilowattHours; @end @@ -227,14 +227,14 @@ extern "C" { Base unit - hertz */ -- (NSUnitFrequency *) terahertz; -- (NSUnitFrequency *) gigahertz; -- (NSUnitFrequency *) megahertz; -- (NSUnitFrequency *) kilohertz; -- (NSUnitFrequency *) hertz; -- (NSUnitFrequency *) millihertz; -- (NSUnitFrequency *) microhertz; -- (NSUnitFrequency *) nanohertz; ++ (NSUnitFrequency *) terahertz; ++ (NSUnitFrequency *) gigahertz; ++ (NSUnitFrequency *) megahertz; ++ (NSUnitFrequency *) kilohertz; ++ (NSUnitFrequency *) hertz; ++ (NSUnitFrequency *) millihertz; ++ (NSUnitFrequency *) microhertz; ++ (NSUnitFrequency *) nanohertz; @end @@ -243,9 +243,9 @@ extern "C" { Base unit - litersPer100Kilometers */ -- (NSUnitFuelEfficiency *) litersPer100Kilometers; -- (NSUnitFuelEfficiency *) milesPerImperialGallon; -- (NSUnitFuelEfficiency *) milesPerGallon; ++ (NSUnitFuelEfficiency *) litersPer100Kilometers; ++ (NSUnitFuelEfficiency *) milesPerImperialGallon; ++ (NSUnitFuelEfficiency *) milesPerGallon; @end @@ -254,28 +254,28 @@ extern "C" { 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; ++ (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 @@ -284,7 +284,7 @@ extern "C" { Base unit - lux */ -- (NSUnitIlluminance *) lux; ++ (NSUnitIlluminance *) lux; @end @@ -293,22 +293,22 @@ extern "C" { Base unit - kilograms */ -- (NSUnitMass *) kilograms; -- (NSUnitMass *) grams; -- (NSUnitMass *) decigrams; -- (NSUnitMass *) centigrams; -- (NSUnitMass *) milligrams; -- (NSUnitMass *) micrograms; -- (NSUnitMass *) nanograms; -- (NSUnitMass *) picograms; -- (NSUnitMass *) ounces; -- (NSUnitMass *) poundsMass; -- (NSUnitMass *) stones; -- (NSUnitMass *) metricTons; -- (NSUnitMass *) shortTons; -- (NSUnitMass *) carats; -- (NSUnitMass *) ouncesTroy; -- (NSUnitMass *) slugs; ++ (NSUnitMass *) kilograms; ++ (NSUnitMass *) grams; ++ (NSUnitMass *) decigrams; ++ (NSUnitMass *) centigrams; ++ (NSUnitMass *) milligrams; ++ (NSUnitMass *) micrograms; ++ (NSUnitMass *) nanograms; ++ (NSUnitMass *) picograms; ++ (NSUnitMass *) ounces; ++ (NSUnitMass *) poundsMass; ++ (NSUnitMass *) stones; ++ (NSUnitMass *) metricTons; ++ (NSUnitMass *) shortTons; ++ (NSUnitMass *) carats; ++ (NSUnitMass *) ouncesTroy; ++ (NSUnitMass *) slugs; @end @@ -317,17 +317,17 @@ extern "C" { 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; ++ (NSUnitPower *) terawatts; ++ (NSUnitPower *) gigawatts; ++ (NSUnitPower *) megawatts; ++ (NSUnitPower *) kilowatts; ++ (NSUnitPower *) watts; ++ (NSUnitPower *) milliwatts; ++ (NSUnitPower *) microwatts; ++ (NSUnitPower *) nanowatts; ++ (NSUnitPower *) picowatts; ++ (NSUnitPower *) femtowatts; ++ (NSUnitPower *) horsepower; @end @@ -336,16 +336,16 @@ extern "C" { 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; ++ (NSUnitPressure *) newtonsPerMetersSquared; ++ (NSUnitPressure *) gigapascals; ++ (NSUnitPressure *) megapascals; ++ (NSUnitPressure *) kilopascals; ++ (NSUnitPressure *) hectopascals; ++ (NSUnitPressure *) inchesOfMercury; ++ (NSUnitPressure *) bars; ++ (NSUnitPressure *) millibars; ++ (NSUnitPressure *) millimetersOfMercury; ++ (NSUnitPressure *) poundsForcePerSquareInch; @end @@ -354,10 +354,10 @@ extern "C" { Base unit - metersPerSecond */ -- (NSUnitSpeed *) metersPerSecond; -- (NSUnitSpeed *) kilometersPerHour; -- (NSUnitSpeed *) milesPerHour; -- (NSUnitSpeed *) knots; ++ (NSUnitSpeed *) metersPerSecond; ++ (NSUnitSpeed *) kilometersPerHour; ++ (NSUnitSpeed *) milesPerHour; ++ (NSUnitSpeed *) knots; @end @@ -365,9 +365,9 @@ extern "C" { /* Base unit - kelvin */ -- (NSUnitTemperature *) kelvin; -- (NSUnitTemperature *) celsius; -- (NSUnitTemperature *) fahrenheit; ++ (NSUnitTemperature *) kelvin; ++ (NSUnitTemperature *) celsius; ++ (NSUnitTemperature *) fahrenheit; @end @@ -377,37 +377,37 @@ extern "C" { 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; ++ (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 diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 8eb5a032c..2b5e4021e 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -202,49 +202,69 @@ // Predefined.... @implementation NSUnitAcceleration ++ (instancetype) baseUnit +{ + return [self metersPerSecondSquared]; +} + // Base unit - metersPerSecondSquared -- (NSUnitAcceleration *) metersPerSecondSquared { return nil; } -- (NSUnitAcceleration *) gravity { return nil; } ++ (NSUnitAcceleration *) metersPerSecondSquared +{ + NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: 1.0 + constant: 0.0]; + NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"m/s^2" + converter: converter]; + return result; +} + ++ (NSUnitAcceleration *) gravity +{ + NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: 1.0 + constant: 9.81]; + NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"m/s^2" + converter: converter]; + return result; +} @end @implementation NSUnitAngle // Base unit - degrees -- (NSUnitAngle *) degrees { return nil; } -- (NSUnitAngle *) arcMinutes { return nil; } -- (NSUnitAngle *) arcSeconds { return nil; } -- (NSUnitAngle *) radians { return nil; } -- (NSUnitAngle *) gradians { return nil; } -- (NSUnitAngle *) revolutions { return nil; } ++ (NSUnitAngle *) degrees { return nil; } ++ (NSUnitAngle *) arcMinutes { return nil; } ++ (NSUnitAngle *) arcSeconds { return nil; } ++ (NSUnitAngle *) radians { return nil; } ++ (NSUnitAngle *) gradians { return nil; } ++ (NSUnitAngle *) revolutions { return nil; } @end @implementation NSUnitArea // Base unit - squareMeters -- (NSUnitArea *) squareMegameters { return nil; } -- (NSUnitArea *) squareKilometers { return nil; } -- (NSUnitArea *) squareMeters { return nil; } -- (NSUnitArea *) squareCentimeters { return nil; } -- (NSUnitArea *) squareMillimeters { return nil; } -- (NSUnitArea *) squareMicrometers { return nil; } -- (NSUnitArea *) squareNanometers { return nil; } -- (NSUnitArea *) squareInches { return nil; } -- (NSUnitArea *) squareFeet { return nil; } -- (NSUnitArea *) squareYards { return nil; } -- (NSUnitArea *) squareMiles { return nil; } -- (NSUnitArea *) acres { return nil; } -- (NSUnitArea *) ares { return nil; } -- (NSUnitArea *) hectares { return nil; } ++ (NSUnitArea *) squareMegameters { return nil; } ++ (NSUnitArea *) squareKilometers { return nil; } ++ (NSUnitArea *) squareMeters { return nil; } ++ (NSUnitArea *) squareCentimeters { return nil; } ++ (NSUnitArea *) squareMillimeters { return nil; } ++ (NSUnitArea *) squareMicrometers { return nil; } ++ (NSUnitArea *) squareNanometers { return nil; } ++ (NSUnitArea *) squareInches { return nil; } ++ (NSUnitArea *) squareFeet { return nil; } ++ (NSUnitArea *) squareYards { return nil; } ++ (NSUnitArea *) squareMiles { return nil; } ++ (NSUnitArea *) acres { return nil; } ++ (NSUnitArea *) ares { return nil; } ++ (NSUnitArea *) hectares { return nil; } @end @implementation NSUnitConcentrationMass // Base unit - gramsPerLiter -- (NSUnitConcentrationMass *) gramsPerLiter { return nil; } -- (NSUnitConcentrationMass *) milligramsPerDeciliter { return nil; } ++ (NSUnitConcentrationMass *) gramsPerLiter { return nil; } ++ (NSUnitConcentrationMass *) milligramsPerDeciliter { return nil; } + (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole { return nil; } @@ -253,72 +273,72 @@ @implementation NSUnitDispersion // Base unit - partsPerMillion -- (NSUnitDispersion *) partsPerMillion { return nil; } ++ (NSUnitDispersion *) partsPerMillion { return nil; } @end @implementation NSUnitDuration // Base unit - seconds -- (NSUnitDuration *) seconds { return nil; } -- (NSUnitDuration *) minutes { return nil; } -- (NSUnitDuration *) hours { return nil; } ++ (NSUnitDuration *) seconds { return nil; } ++ (NSUnitDuration *) minutes { return nil; } ++ (NSUnitDuration *) hours { return nil; } @end @implementation NSUnitElectricCharge // Base unit - coulombs -- (NSUnitElectricCharge *) coulombs { return nil; } -- (NSUnitElectricCharge *) megaampereHours { return nil; } -- (NSUnitElectricCharge *) kiloampereHours { return nil; } -- (NSUnitElectricCharge *) ampereHours { return nil; } -- (NSUnitElectricCharge *) milliampereHours { return nil; } -- (NSUnitElectricCharge *) microampereHours { return nil; } ++ (NSUnitElectricCharge *) coulombs { return nil; } ++ (NSUnitElectricCharge *) megaampereHours { return nil; } ++ (NSUnitElectricCharge *) kiloampereHours { return nil; } ++ (NSUnitElectricCharge *) ampereHours { return nil; } ++ (NSUnitElectricCharge *) milliampereHours { return nil; } ++ (NSUnitElectricCharge *) microampereHours { return nil; } @end @implementation NSUnitElectricCurrent // Base unit - amperes -- (NSUnitElectricCurrent *) megaamperes { return nil; } -- (NSUnitElectricCurrent *) kiloamperes { return nil; } -- (NSUnitElectricCurrent *) amperes { return nil; } -- (NSUnitElectricCurrent *) milliamperes { return nil; } -- (NSUnitElectricCurrent *) microamperes { return nil; } ++ (NSUnitElectricCurrent *) megaamperes { return nil; } ++ (NSUnitElectricCurrent *) kiloamperes { return nil; } ++ (NSUnitElectricCurrent *) amperes { return nil; } ++ (NSUnitElectricCurrent *) milliamperes { return nil; } ++ (NSUnitElectricCurrent *) microamperes { return nil; } @end @implementation NSUnitElectricPotentialDifference // Base unit - volts -- (NSUnitElectricPotentialDifference *) megavolts { return nil; } -- (NSUnitElectricPotentialDifference *) kilovolts { return nil; } -- (NSUnitElectricPotentialDifference *) volts { return nil; } -- (NSUnitElectricPotentialDifference *) millivolts { return nil; } -- (NSUnitElectricPotentialDifference *) microvolts { return nil; } ++ (NSUnitElectricPotentialDifference *) megavolts { return nil; } ++ (NSUnitElectricPotentialDifference *) kilovolts { return nil; } ++ (NSUnitElectricPotentialDifference *) volts { return nil; } ++ (NSUnitElectricPotentialDifference *) millivolts { return nil; } ++ (NSUnitElectricPotentialDifference *) microvolts { return nil; } @end @implementation NSUnitElectricResistance // Base unit - ohms -- (NSUnitElectricResistance *) megaohms { return nil; } -- (NSUnitElectricResistance *) kiloohms { return nil; } -- (NSUnitElectricResistance *) ohms { return nil; } -- (NSUnitElectricResistance *) milliohms { return nil; } -- (NSUnitElectricResistance *) microohms { return nil; } ++ (NSUnitElectricResistance *) megaohms { return nil; } ++ (NSUnitElectricResistance *) kiloohms { return nil; } ++ (NSUnitElectricResistance *) ohms { return nil; } ++ (NSUnitElectricResistance *) milliohms { return nil; } ++ (NSUnitElectricResistance *) microohms { return nil; } @end @implementation NSUnitEnergy // Base unit - joules -- (NSUnitEnergy *) kilojoules { return nil; } -- (NSUnitEnergy *) joules { return nil; } -- (NSUnitEnergy *) kilocalories { return nil; } -- (NSUnitEnergy *) calories { return nil; } -- (NSUnitEnergy *) kilowattHours { return nil; } ++ (NSUnitEnergy *) kilojoules { return nil; } ++ (NSUnitEnergy *) joules { return nil; } ++ (NSUnitEnergy *) kilocalories { return nil; } ++ (NSUnitEnergy *) calories { return nil; } ++ (NSUnitEnergy *) kilowattHours { return nil; } @end @@ -326,14 +346,14 @@ // Base unit - hertz -- (NSUnitFrequency *) terahertz { return nil; } -- (NSUnitFrequency *) gigahertz { return nil; } -- (NSUnitFrequency *) megahertz { return nil; } -- (NSUnitFrequency *) kilohertz { return nil; } -- (NSUnitFrequency *) hertz { return nil; } -- (NSUnitFrequency *) millihertz { return nil; } -- (NSUnitFrequency *) microhertz { return nil; } -- (NSUnitFrequency *) nanohertz { return nil; } ++ (NSUnitFrequency *) terahertz { return nil; } ++ (NSUnitFrequency *) gigahertz { return nil; } ++ (NSUnitFrequency *) megahertz { return nil; } ++ (NSUnitFrequency *) kilohertz { return nil; } ++ (NSUnitFrequency *) hertz { return nil; } ++ (NSUnitFrequency *) millihertz { return nil; } ++ (NSUnitFrequency *) microhertz { return nil; } ++ (NSUnitFrequency *) nanohertz { return nil; } @end @@ -341,9 +361,9 @@ // Base unit - litersPer100Kilometers -- (NSUnitFuelEfficiency *) litersPer100Kilometers { return nil; } -- (NSUnitFuelEfficiency *) milesPerImperialGallon { return nil; } -- (NSUnitFuelEfficiency *) milesPerGallon { return nil; } ++ (NSUnitFuelEfficiency *) litersPer100Kilometers { return nil; } ++ (NSUnitFuelEfficiency *) milesPerImperialGallon { return nil; } ++ (NSUnitFuelEfficiency *) milesPerGallon { return nil; } @end @@ -351,28 +371,28 @@ // Base unit - meters -- (NSUnitLength *) megameters { return nil; } -- (NSUnitLength *) kilometers { return nil; } -- (NSUnitLength *) hectometers { return nil; } -- (NSUnitLength *) decameters { return nil; } -- (NSUnitLength *) meters { return nil; } -- (NSUnitLength *) decimeters { return nil; } -- (NSUnitLength *) centimeters { return nil; } -- (NSUnitLength *) millimeters { return nil; } -- (NSUnitLength *) micrometers { return nil; } -- (NSUnitLength *) nanometers { return nil; } -- (NSUnitLength *) picometers { return nil; } -- (NSUnitLength *) inches { return nil; } -- (NSUnitLength *) feet { return nil; } -- (NSUnitLength *) yards { return nil; } -- (NSUnitLength *) miles { return nil; } -- (NSUnitLength *) scandinavianMiles { return nil; } -- (NSUnitLength *) lightyears { return nil; } -- (NSUnitLength *) nauticalMiles { return nil; } -- (NSUnitLength *) fathoms { return nil; } -- (NSUnitLength *) furlongs { return nil; } -- (NSUnitLength *) astronomicalUnits { return nil; } -- (NSUnitLength *) parsecs { return nil; } ++ (NSUnitLength *) megameters { return nil; } ++ (NSUnitLength *) kilometers { return nil; } ++ (NSUnitLength *) hectometers { return nil; } ++ (NSUnitLength *) decameters { return nil; } ++ (NSUnitLength *) meters { return nil; } ++ (NSUnitLength *) decimeters { return nil; } ++ (NSUnitLength *) centimeters { return nil; } ++ (NSUnitLength *) millimeters { return nil; } ++ (NSUnitLength *) micrometers { return nil; } ++ (NSUnitLength *) nanometers { return nil; } ++ (NSUnitLength *) picometers { return nil; } ++ (NSUnitLength *) inches { return nil; } ++ (NSUnitLength *) feet { return nil; } ++ (NSUnitLength *) yards { return nil; } ++ (NSUnitLength *) miles { return nil; } ++ (NSUnitLength *) scandinavianMiles { return nil; } ++ (NSUnitLength *) lightyears { return nil; } ++ (NSUnitLength *) nauticalMiles { return nil; } ++ (NSUnitLength *) fathoms { return nil; } ++ (NSUnitLength *) furlongs { return nil; } ++ (NSUnitLength *) astronomicalUnits { return nil; } ++ (NSUnitLength *) parsecs { return nil; } @end @@ -380,7 +400,7 @@ // Base unit - lux -- (NSUnitIlluminance *) lux { return nil; } ++ (NSUnitIlluminance *) lux { return nil; } @end @@ -388,22 +408,22 @@ // Base unit - kilograms -- (NSUnitMass *) kilograms { return nil; } -- (NSUnitMass *) grams { return nil; } -- (NSUnitMass *) decigrams { return nil; } -- (NSUnitMass *) centigrams { return nil; } -- (NSUnitMass *) milligrams { return nil; } -- (NSUnitMass *) micrograms { return nil; } -- (NSUnitMass *) nanograms { return nil; } -- (NSUnitMass *) picograms { return nil; } -- (NSUnitMass *) ounces { return nil; } -- (NSUnitMass *) poundsMass { return nil; } -- (NSUnitMass *) stones { return nil; } -- (NSUnitMass *) metricTons { return nil; } -- (NSUnitMass *) shortTons { return nil; } -- (NSUnitMass *) carats { return nil; } -- (NSUnitMass *) ouncesTroy { return nil; } -- (NSUnitMass *) slugs { return nil; } ++ (NSUnitMass *) kilograms { return nil; } ++ (NSUnitMass *) grams { return nil; } ++ (NSUnitMass *) decigrams { return nil; } ++ (NSUnitMass *) centigrams { return nil; } ++ (NSUnitMass *) milligrams { return nil; } ++ (NSUnitMass *) micrograms { return nil; } ++ (NSUnitMass *) nanograms { return nil; } ++ (NSUnitMass *) picograms { return nil; } ++ (NSUnitMass *) ounces { return nil; } ++ (NSUnitMass *) poundsMass { return nil; } ++ (NSUnitMass *) stones { return nil; } ++ (NSUnitMass *) metricTons { return nil; } ++ (NSUnitMass *) shortTons { return nil; } ++ (NSUnitMass *) carats { return nil; } ++ (NSUnitMass *) ouncesTroy { return nil; } ++ (NSUnitMass *) slugs { return nil; } @end @@ -411,17 +431,17 @@ // Base unit - watts -- (NSUnitPower *) terawatts { return nil; } -- (NSUnitPower *) gigawatts { return nil; } -- (NSUnitPower *) megawatts { return nil; } -- (NSUnitPower *) kilowatts { return nil; } -- (NSUnitPower *) watts { return nil; } -- (NSUnitPower *) milliwatts { return nil; } -- (NSUnitPower *) microwatts { return nil; } -- (NSUnitPower *) nanowatts { return nil; } -- (NSUnitPower *) picowatts { return nil; } -- (NSUnitPower *) femtowatts { return nil; } -- (NSUnitPower *) horsepower { return nil; } ++ (NSUnitPower *) terawatts { return nil; } ++ (NSUnitPower *) gigawatts { return nil; } ++ (NSUnitPower *) megawatts { return nil; } ++ (NSUnitPower *) kilowatts { return nil; } ++ (NSUnitPower *) watts { return nil; } ++ (NSUnitPower *) milliwatts { return nil; } ++ (NSUnitPower *) microwatts { return nil; } ++ (NSUnitPower *) nanowatts { return nil; } ++ (NSUnitPower *) picowatts { return nil; } ++ (NSUnitPower *) femtowatts { return nil; } ++ (NSUnitPower *) horsepower { return nil; } @end @@ -429,71 +449,71 @@ // Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) -- (NSUnitPressure *) newtonsPerMetersSquared { return nil; } -- (NSUnitPressure *) gigapascals { return nil; } -- (NSUnitPressure *) megapascals { return nil; } -- (NSUnitPressure *) kilopascals { return nil; } -- (NSUnitPressure *) hectopascals { return nil; } -- (NSUnitPressure *) inchesOfMercury { return nil; } -- (NSUnitPressure *) bars { return nil; } -- (NSUnitPressure *) millibars { return nil; } -- (NSUnitPressure *) millimetersOfMercury { return nil; } -- (NSUnitPressure *) poundsForcePerSquareInch { return nil; } ++ (NSUnitPressure *) newtonsPerMetersSquared { return nil; } ++ (NSUnitPressure *) gigapascals { return nil; } ++ (NSUnitPressure *) megapascals { return nil; } ++ (NSUnitPressure *) kilopascals { return nil; } ++ (NSUnitPressure *) hectopascals { return nil; } ++ (NSUnitPressure *) inchesOfMercury { return nil; } ++ (NSUnitPressure *) bars { return nil; } ++ (NSUnitPressure *) millibars { return nil; } ++ (NSUnitPressure *) millimetersOfMercury { return nil; } ++ (NSUnitPressure *) poundsForcePerSquareInch { return nil; } @end @implementation NSUnitSpeed // Base unit - metersPerSecond -- (NSUnitSpeed *) metersPerSecond { return nil; } -- (NSUnitSpeed *) kilometersPerHour { return nil; } -- (NSUnitSpeed *) milesPerHour { return nil; } -- (NSUnitSpeed *) knots { return nil; } ++ (NSUnitSpeed *) metersPerSecond { return nil; } ++ (NSUnitSpeed *) kilometersPerHour { return nil; } ++ (NSUnitSpeed *) milesPerHour { return nil; } ++ (NSUnitSpeed *) knots { return nil; } @end @implementation NSUnitTemperature // Base unit - kelvin -- (NSUnitTemperature *) kelvin { return nil; } -- (NSUnitTemperature *) celsius { return nil; } -- (NSUnitTemperature *) fahrenheit { return nil; } ++ (NSUnitTemperature *) kelvin { return nil; } ++ (NSUnitTemperature *) celsius { return nil; } ++ (NSUnitTemperature *) fahrenheit { return nil; } @end @implementation NSUnitVolume // Base unit - liters -- (NSUnitVolume *) megaliters { return nil; } -- (NSUnitVolume *) kiloliters { return nil; } -- (NSUnitVolume *) liters { return nil; } -- (NSUnitVolume *) deciliters { return nil; } -- (NSUnitVolume *) centiliters { return nil; } -- (NSUnitVolume *) milliliters { return nil; } -- (NSUnitVolume *) cubicKilometers { return nil; } -- (NSUnitVolume *) cubicMeters { return nil; } -- (NSUnitVolume *) cubicDecimeters { return nil; } -- (NSUnitVolume *) cubicCentimeters { return nil; } -- (NSUnitVolume *) cubicMillimeters { return nil; } -- (NSUnitVolume *) cubicInches { return nil; } -- (NSUnitVolume *) cubicFeet { return nil; } -- (NSUnitVolume *) cubicYards { return nil; } -- (NSUnitVolume *) cubicMiles { return nil; } -- (NSUnitVolume *) acreFeet { return nil; } -- (NSUnitVolume *) bushels { return nil; } -- (NSUnitVolume *) teaspoons { return nil; } -- (NSUnitVolume *) tablespoons { return nil; } -- (NSUnitVolume *) fluidOunces { return nil; } -- (NSUnitVolume *) cups { return nil; } -- (NSUnitVolume *) pints { return nil; } -- (NSUnitVolume *) quarts { return nil; } -- (NSUnitVolume *) gallons { return nil; } -- (NSUnitVolume *) imperialTeaspoons { return nil; } -- (NSUnitVolume *) imperialTablespoons { return nil; } -- (NSUnitVolume *) imperialFluidOunces { return nil; } -- (NSUnitVolume *) imperialPints { return nil; } -- (NSUnitVolume *) imperialQuarts { return nil; } -- (NSUnitVolume *) imperialGallons { return nil; } -- (NSUnitVolume *) metricCups { return nil; } ++ (NSUnitVolume *) megaliters { return nil; } ++ (NSUnitVolume *) kiloliters { return nil; } ++ (NSUnitVolume *) liters { return nil; } ++ (NSUnitVolume *) deciliters { return nil; } ++ (NSUnitVolume *) centiliters { return nil; } ++ (NSUnitVolume *) milliliters { return nil; } ++ (NSUnitVolume *) cubicKilometers { return nil; } ++ (NSUnitVolume *) cubicMeters { return nil; } ++ (NSUnitVolume *) cubicDecimeters { return nil; } ++ (NSUnitVolume *) cubicCentimeters { return nil; } ++ (NSUnitVolume *) cubicMillimeters { return nil; } ++ (NSUnitVolume *) cubicInches { return nil; } ++ (NSUnitVolume *) cubicFeet { return nil; } ++ (NSUnitVolume *) cubicYards { return nil; } ++ (NSUnitVolume *) cubicMiles { return nil; } ++ (NSUnitVolume *) acreFeet { return nil; } ++ (NSUnitVolume *) bushels { return nil; } ++ (NSUnitVolume *) teaspoons { return nil; } ++ (NSUnitVolume *) tablespoons { return nil; } ++ (NSUnitVolume *) fluidOunces { return nil; } ++ (NSUnitVolume *) cups { return nil; } ++ (NSUnitVolume *) pints { return nil; } ++ (NSUnitVolume *) quarts { return nil; } ++ (NSUnitVolume *) gallons { return nil; } ++ (NSUnitVolume *) imperialTeaspoons { return nil; } ++ (NSUnitVolume *) imperialTablespoons { return nil; } ++ (NSUnitVolume *) imperialFluidOunces { return nil; } ++ (NSUnitVolume *) imperialPints { return nil; } ++ (NSUnitVolume *) imperialQuarts { return nil; } ++ (NSUnitVolume *) imperialGallons { return nil; } ++ (NSUnitVolume *) metricCups { return nil; } @end From 9487a5620458d7b0ac7f32c572717587f3019e5c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 19:46:06 -0400 Subject: [PATCH 15/79] Correct symbol for gravity --- Source/NSUnit.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 2b5e4021e..1040fd6c1 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -221,7 +221,7 @@ { NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: 1.0 constant: 9.81]; - NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"m/s^2" + NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"g" converter: converter]; return result; } From db17eebdf0a900e844d657a7ce1757ea797e085e Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 22:33:23 -0400 Subject: [PATCH 16/79] Add implementations for NSUnitAngle --- Source/NSUnit.m | 82 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 1040fd6c1..93df591c5 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -26,6 +26,13 @@ #include #include +// Private methods... +@interface NSDimension (Private) +- (instancetype) initWithSymbol: (NSString *)symbol + coefficient: (double)coefficient + constant: (double)constant; +@end + // Abstract conversion... @implementation NSUnitConverter - (instancetype) init @@ -192,6 +199,18 @@ return self; } +- (instancetype) initWithSymbol: (NSString *)symbol + coefficient: (double)coefficient + constant: (double)constant +{ + NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: coefficient + constant: constant]; + NSDimension *result = [[[self class] alloc] initWithSymbol: symbol + converter: converter]; + return result; +} + + + (instancetype) baseUnit { return nil; @@ -210,19 +229,17 @@ // Base unit - metersPerSecondSquared + (NSUnitAcceleration *) metersPerSecondSquared { - NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: 1.0 - constant: 0.0]; NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"m/s^2" - converter: converter]; + coefficient: 1.0 + constant: 0.0]; return result; } + (NSUnitAcceleration *) gravity { - NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: 1.0 - constant: 9.81]; NSUnitAcceleration *result = [[NSUnitAcceleration alloc] initWithSymbol: @"g" - converter: converter]; + coefficient: 9.81 + constant: 0]; return result; } @@ -231,12 +248,53 @@ @implementation NSUnitAngle // Base unit - degrees -+ (NSUnitAngle *) degrees { return nil; } -+ (NSUnitAngle *) arcMinutes { return nil; } -+ (NSUnitAngle *) arcSeconds { return nil; } -+ (NSUnitAngle *) radians { return nil; } -+ (NSUnitAngle *) gradians { return nil; } -+ (NSUnitAngle *) revolutions { return nil; } ++ (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: 9.81]; + 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 From 37255f67615cf56dcf7a3cfd162deef43f3092c2 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 22:58:47 -0400 Subject: [PATCH 17/79] Add implementation of NSUnitArea. echo foxtrot golf hotel india --- Source/NSUnit.m | 125 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 14 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 93df591c5..cd4ef4808 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -301,20 +301,117 @@ @implementation NSUnitArea // Base unit - squareMeters -+ (NSUnitArea *) squareMegameters { return nil; } -+ (NSUnitArea *) squareKilometers { return nil; } -+ (NSUnitArea *) squareMeters { return nil; } -+ (NSUnitArea *) squareCentimeters { return nil; } -+ (NSUnitArea *) squareMillimeters { return nil; } -+ (NSUnitArea *) squareMicrometers { return nil; } -+ (NSUnitArea *) squareNanometers { return nil; } -+ (NSUnitArea *) squareInches { return nil; } -+ (NSUnitArea *) squareFeet { return nil; } -+ (NSUnitArea *) squareYards { return nil; } -+ (NSUnitArea *) squareMiles { return nil; } -+ (NSUnitArea *) acres { return nil; } -+ (NSUnitArea *) ares { return nil; } -+ (NSUnitArea *) hectares { return nil; } ++ (NSUnitArea *) squareMegameters +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareKilometers +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.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: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMillimeters +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMicrometers +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareNanometers +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareInches +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareFeet +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareYards +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) squareMiles +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) acres +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) ares +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} + ++ (NSUnitArea *) hectares +{ + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" + coefficient: 360.0 + constant: 0.0]; + return result; +} @end From c439c66e924594ccfdb07a231a1e0b1694d8c9ef Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 23:17:13 -0400 Subject: [PATCH 18/79] Add NSUnitArea implementations --- Source/NSUnit.m | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index cd4ef4808..02f7242e9 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -303,17 +303,17 @@ // Base unit - squareMeters + (NSUnitArea *) squareMegameters { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 - constant: 0.0]; + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"Mm^2" + coefficient: 1e12 + constant: 0.0]; return result; } + (NSUnitArea *) squareKilometers { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 - constant: 0.0]; + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"km^2" + coefficient: 1000000.0 + constant: 0.0]; return result; } @@ -327,88 +327,88 @@ + (NSUnitArea *) squareCentimeters { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"cm^2" + coefficient: 0.0001 constant: 0.0]; return result; } + (NSUnitArea *) squareMillimeters { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"mm^2" + coefficient: 0.000001 constant: 0.0]; return result; } + (NSUnitArea *) squareMicrometers { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"um^2" + coefficient: 1e-12 constant: 0.0]; return result; } + (NSUnitArea *) squareNanometers { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 - constant: 0.0]; + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"nm^2" + coefficient: 1e-18 + constant: 0.0]; return result; } + (NSUnitArea *) squareInches { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 - constant: 0.0]; + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"in^2" + coefficient: 0.00064516 + constant: 0.0]; return result; } + (NSUnitArea *) squareFeet { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 - constant: 0.0]; + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"ft^2" + coefficient: 0.092903 + constant: 0.0]; return result; } + (NSUnitArea *) squareYards { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 - constant: 0.0]; + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"yd^2" + coefficient: 0.836127 + constant: 0.0]; return result; } + (NSUnitArea *) squareMiles { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"mi^2" + coefficient: 2.59e+6 constant: 0.0]; return result; } + (NSUnitArea *) acres { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"acres" + coefficient: 4046.86 constant: 0.0]; return result; } + (NSUnitArea *) ares { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"ares" + coefficient: 100.0 constant: 0.0]; return result; } + (NSUnitArea *) hectares { - NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"rev" - coefficient: 360.0 + NSUnitArea *result = [[NSUnitArea alloc] initWithSymbol: @"hectares" + coefficient: 10000.0 constant: 0.0]; return result; } From 947b9f3a3f2a6f610f6b3669d9ae4e5d6275002f Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 23:22:17 -0400 Subject: [PATCH 19/79] Implement NSUnitConcentrationMass --- Source/NSUnit.m | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 02f7242e9..d0aa71df7 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -418,10 +418,29 @@ @implementation NSUnitConcentrationMass // Base unit - gramsPerLiter -+ (NSUnitConcentrationMass *) gramsPerLiter { return nil; } -+ (NSUnitConcentrationMass *) milligramsPerDeciliter { return nil; } ++ (NSUnitConcentrationMass *) gramsPerLiter +{ + NSUnitConcentrationMass *result = [[NSUnitConcentrationMass alloc] initWithSymbol: @"g/L" + coefficient: 1.0 + constant: 0.0]; + return result; +} -+ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole { return nil; } ++ (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 From 372e0a09d1466b8f83320be7e57cd454211211d6 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 6 Oct 2019 23:59:27 -0400 Subject: [PATCH 20/79] NSUnitDispersion implementation --- Source/NSUnit.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index d0aa71df7..63b907734 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -447,7 +447,14 @@ @implementation NSUnitDispersion // Base unit - partsPerMillion -+ (NSUnitDispersion *) partsPerMillion { return nil; } ++ (NSUnitDispersion *) partsPerMillion +{ + NSUnitDispersion *result = [[NSUnitDispersion alloc] initWithSymbol: @"ppm" + coefficient: 1.0 + constant: 0.0]; + return result; +} + @end From 03fc5f5348ab5cdccf618a8a941db4e6523109ab Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 00:03:12 -0400 Subject: [PATCH 21/79] NSUnitDuration implementation --- Source/NSUnit.m | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 63b907734..6df4520d7 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -455,15 +455,34 @@ return result; } - @end @implementation NSUnitDuration // Base unit - seconds -+ (NSUnitDuration *) seconds { return nil; } -+ (NSUnitDuration *) minutes { return nil; } -+ (NSUnitDuration *) hours { return nil; } ++ (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 From c4119fff6d3402fd7827b4a41aba4442a5e0edf5 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 00:15:41 -0400 Subject: [PATCH 22/79] NSUnitElectricCharge implementation --- Source/NSUnit.m | 54 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 6df4520d7..dd5593c40 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -489,12 +489,54 @@ @implementation NSUnitElectricCharge // Base unit - coulombs -+ (NSUnitElectricCharge *) coulombs { return nil; } -+ (NSUnitElectricCharge *) megaampereHours { return nil; } -+ (NSUnitElectricCharge *) kiloampereHours { return nil; } -+ (NSUnitElectricCharge *) ampereHours { return nil; } -+ (NSUnitElectricCharge *) milliampereHours { return nil; } -+ (NSUnitElectricCharge *) microampereHours { return nil; } ++ (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 From 063499cab4e999e68cbe4543447e984b7b78abd1 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 00:23:55 -0400 Subject: [PATCH 23/79] NSUnitIlluminance implementation --- Source/NSUnit.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index dd5593c40..f1f5d7473 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -537,7 +537,6 @@ return result; } - @end @implementation NSUnitElectricCurrent @@ -642,7 +641,14 @@ // Base unit - lux -+ (NSUnitIlluminance *) lux { return nil; } ++ (NSUnitIlluminance *) lux +{ + NSUnitIlluminance *result = [[NSUnitIlluminance alloc] initWithSymbol: @"lux" + coefficient: 1.0 + constant: 0.0]; + return result; +} + @end From 1902ca7c8d4fd4d4d50535647ff5d338f85f163b Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 00:24:24 -0400 Subject: [PATCH 24/79] NSUnitIlluminance implementation --- Source/NSUnit.m | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index f1f5d7473..e2ef0d344 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -649,7 +649,6 @@ return result; } - @end @implementation NSUnitMass From 652e5e7db96e7cb4a20d65ad8d218c2ab4c244f1 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 00:52:13 -0400 Subject: [PATCH 25/79] NSUnitElectricCurrent implementation --- Source/NSUnit.m | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index e2ef0d344..409e0cfa9 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -542,11 +542,45 @@ @implementation NSUnitElectricCurrent // Base unit - amperes -+ (NSUnitElectricCurrent *) megaamperes { return nil; } -+ (NSUnitElectricCurrent *) kiloamperes { return nil; } -+ (NSUnitElectricCurrent *) amperes { return nil; } -+ (NSUnitElectricCurrent *) milliamperes { return nil; } -+ (NSUnitElectricCurrent *) microamperes { return nil; } ++ (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.0036 + constant: 0.000001]; + return result; +} @end From da5e6a91e3a80a4a751e7738a0ca10a3e37b2a6a Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 01:04:55 -0400 Subject: [PATCH 26/79] NSUnitElectricPotentionDifference implementation --- Source/NSUnit.m | 53 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 409e0cfa9..483ef93ea 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -577,8 +577,8 @@ + (NSUnitElectricCurrent *) microamperes { NSUnitElectricCurrent *result = [[NSUnitElectricCurrent alloc] initWithSymbol: @"uA" - coefficient: 0.0036 - constant: 0.000001]; + coefficient: 0.000001 + constant: 0.0]; return result; } @@ -587,11 +587,50 @@ @implementation NSUnitElectricPotentialDifference // Base unit - volts -+ (NSUnitElectricPotentialDifference *) megavolts { return nil; } -+ (NSUnitElectricPotentialDifference *) kilovolts { return nil; } -+ (NSUnitElectricPotentialDifference *) volts { return nil; } -+ (NSUnitElectricPotentialDifference *) millivolts { return nil; } -+ (NSUnitElectricPotentialDifference *) microvolts { return nil; } ++ (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 From 4e42277542c22327485f6e8ebcb9cfd5cb45a758 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 01:11:29 -0400 Subject: [PATCH 27/79] temperature implementation --- Source/NSUnit.m | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 483ef93ea..c4c5cf88e 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -795,10 +795,29 @@ @implementation NSUnitTemperature // Base unit - kelvin -+ (NSUnitTemperature *) kelvin { return nil; } -+ (NSUnitTemperature *) celsius { return nil; } -+ (NSUnitTemperature *) fahrenheit { return nil; } ++ (NSUnitTemperature *) kelvin +{ + NSUnitTemperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"K" + coefficient: 1.0 + constant: 0.0]; + return result; +} ++ (NSUnitTemperature *) celsius +{ + NSUnitTerperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"C" + coefficient: 1.0 + constant: 273.15]; + return result; +} + ++ (NSUnitTemperature *) fahrenheit +{ + NSUnitTemperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"F" + coefficient: 0.55555555555556 + constant: 255.37222222222427]; + return result; +} @end @implementation NSUnitVolume From efe855603708134ccdbf2d44dd8bc05719249228 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 01:54:16 -0400 Subject: [PATCH 28/79] NSElectricResistance --- Source/NSUnit.m | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index c4c5cf88e..95e1ad611 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -638,10 +638,50 @@ // Base unit - ohms + (NSUnitElectricResistance *) megaohms { return nil; } +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"MOhm" + coefficient: 0.0 + constant: 100000.0]; + return result; +} + + (NSUnitElectricResistance *) kiloohms { return nil; } +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"kOhm" + coefficient: 0.0 + constant: 1000.000001]; + return result; +} + + (NSUnitElectricResistance *) ohms { return nil; } +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"Ohm" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + + (NSUnitElectricResistance *) milliohms { return nil; } +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"mOhm" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + + (NSUnitElectricResistance *) microohms { return nil; } +{ + NSUnitElectricResistance *result = + [[NSUnitElectricResistance alloc] initWithSymbol: @"uOhm" + coefficient: 0.0 + constant: 0.000001]; + return result; +} + @end From 93f053c15bb8047a8fae2a81b9922de0414b3c5b Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 02:00:45 -0400 Subject: [PATCH 29/79] Minor fixes --- Source/NSUnit.m | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 95e1ad611..cbeb9d4ad 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -637,7 +637,7 @@ @implementation NSUnitElectricResistance // Base unit - ohms -+ (NSUnitElectricResistance *) megaohms { return nil; } ++ (NSUnitElectricResistance *) megaohms { NSUnitElectricResistance *result = [[NSUnitElectricResistance alloc] initWithSymbol: @"MOhm" @@ -646,7 +646,7 @@ return result; } -+ (NSUnitElectricResistance *) kiloohms { return nil; } ++ (NSUnitElectricResistance *) kiloohms { NSUnitElectricResistance *result = [[NSUnitElectricResistance alloc] initWithSymbol: @"kOhm" @@ -655,7 +655,7 @@ return result; } -+ (NSUnitElectricResistance *) ohms { return nil; } ++ (NSUnitElectricResistance *) ohms { NSUnitElectricResistance *result = [[NSUnitElectricResistance alloc] initWithSymbol: @"Ohm" @@ -664,7 +664,7 @@ return result; } -+ (NSUnitElectricResistance *) milliohms { return nil; } ++ (NSUnitElectricResistance *) milliohms { NSUnitElectricResistance *result = [[NSUnitElectricResistance alloc] initWithSymbol: @"mOhm" @@ -673,7 +673,7 @@ return result; } -+ (NSUnitElectricResistance *) microohms { return nil; } ++ (NSUnitElectricResistance *) microohms { NSUnitElectricResistance *result = [[NSUnitElectricResistance alloc] initWithSymbol: @"uOhm" @@ -753,7 +753,6 @@ @implementation NSUnitIlluminance // Base unit - lux - + (NSUnitIlluminance *) lux { NSUnitIlluminance *result = [[NSUnitIlluminance alloc] initWithSymbol: @"lux" @@ -837,7 +836,7 @@ // Base unit - kelvin + (NSUnitTemperature *) kelvin { - NSUnitTemperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"K" + NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"K" coefficient: 1.0 constant: 0.0]; return result; @@ -845,7 +844,7 @@ + (NSUnitTemperature *) celsius { - NSUnitTerperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"C" + NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"C" coefficient: 1.0 constant: 273.15]; return result; @@ -853,7 +852,7 @@ + (NSUnitTemperature *) fahrenheit { - NSUnitTemperature *result = [[NSUnitIlluminance alloc] initWithSymbol: @"F" + NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"F" coefficient: 0.55555555555556 constant: 255.37222222222427]; return result; From 6114965737def7371a18f659fb9ceb6442c3e06d Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 02:49:28 -0400 Subject: [PATCH 30/79] NSUnitMass implementation --- Source/NSUnit.m | 143 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 127 insertions(+), 16 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index cbeb9d4ad..e502b34ab 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -767,22 +767,133 @@ // Base unit - kilograms -+ (NSUnitMass *) kilograms { return nil; } -+ (NSUnitMass *) grams { return nil; } -+ (NSUnitMass *) decigrams { return nil; } -+ (NSUnitMass *) centigrams { return nil; } -+ (NSUnitMass *) milligrams { return nil; } -+ (NSUnitMass *) micrograms { return nil; } -+ (NSUnitMass *) nanograms { return nil; } -+ (NSUnitMass *) picograms { return nil; } -+ (NSUnitMass *) ounces { return nil; } -+ (NSUnitMass *) poundsMass { return nil; } -+ (NSUnitMass *) stones { return nil; } -+ (NSUnitMass *) metricTons { return nil; } -+ (NSUnitMass *) shortTons { return nil; } -+ (NSUnitMass *) carats { return nil; } -+ (NSUnitMass *) ouncesTroy { return nil; } -+ (NSUnitMass *) slugs { return nil; } ++ (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 *) poundsMass +{ + 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 From 96accaf566753bf0ae410faec433f53492419966 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 03:16:01 -0400 Subject: [PATCH 31/79] NSUnitEnergy implementation --- Source/NSUnit.m | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index e502b34ab..b383cb2c0 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -688,11 +688,45 @@ @implementation NSUnitEnergy // Base unit - joules -+ (NSUnitEnergy *) kilojoules { return nil; } -+ (NSUnitEnergy *) joules { return nil; } -+ (NSUnitEnergy *) kilocalories { return nil; } -+ (NSUnitEnergy *) calories { return nil; } -+ (NSUnitEnergy *) kilowattHours { return nil; } ++ (NSUnitEnergy *) kilojoules +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kJ" + coefficient: 1000.0 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) joules +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"J" + coefficient: 1.0 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) kilocalories +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kCal" + coefficient: 4184.0 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) calories +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"cal" + coefficient: 4.184 + constant: 0.0]; + return result; +} + ++ (NSUnitEnergy *) kilowattHours +{ + NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kWh" + coefficient: 3600000.0 + constant: 0.0]; + return result; +} @end From 457c9d343767e4f8334310c1530a058ead3dd9b4 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 03:47:46 -0400 Subject: [PATCH 32/79] NSUnitFrequency implementation --- Source/NSUnit.m | 81 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index b383cb2c0..a19702f6f 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -690,7 +690,7 @@ // Base unit - joules + (NSUnitEnergy *) kilojoules { - NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kJ" + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"kJ" coefficient: 1000.0 constant: 0.0]; return result; @@ -698,7 +698,7 @@ + (NSUnitEnergy *) joules { - NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"J" + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"J" coefficient: 1.0 constant: 0.0]; return result; @@ -706,7 +706,7 @@ + (NSUnitEnergy *) kilocalories { - NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kCal" + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"kCal" coefficient: 4184.0 constant: 0.0]; return result; @@ -714,7 +714,7 @@ + (NSUnitEnergy *) calories { - NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"cal" + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"cal" coefficient: 4.184 constant: 0.0]; return result; @@ -722,7 +722,7 @@ + (NSUnitEnergy *) kilowattHours { - NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"kWh" + NSUnitEnergy *result = [[NSUnitEnergy alloc] initWithSymbol: @"kWh" coefficient: 3600000.0 constant: 0.0]; return result; @@ -734,14 +734,69 @@ // Base unit - hertz -+ (NSUnitFrequency *) terahertz { return nil; } -+ (NSUnitFrequency *) gigahertz { return nil; } -+ (NSUnitFrequency *) megahertz { return nil; } -+ (NSUnitFrequency *) kilohertz { return nil; } -+ (NSUnitFrequency *) hertz { return nil; } -+ (NSUnitFrequency *) millihertz { return nil; } -+ (NSUnitFrequency *) microhertz { return nil; } -+ (NSUnitFrequency *) nanohertz { return nil; } ++ (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 From 600e51a24f8d1508cebd65f259c356f18f2244c7 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 7 Oct 2019 09:57:59 -0400 Subject: [PATCH 33/79] NSUnitPower --- Source/NSUnit.m | 99 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 11 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index a19702f6f..3cdcce1db 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -990,17 +990,94 @@ // Base unit - watts -+ (NSUnitPower *) terawatts { return nil; } -+ (NSUnitPower *) gigawatts { return nil; } -+ (NSUnitPower *) megawatts { return nil; } -+ (NSUnitPower *) kilowatts { return nil; } -+ (NSUnitPower *) watts { return nil; } -+ (NSUnitPower *) milliwatts { return nil; } -+ (NSUnitPower *) microwatts { return nil; } -+ (NSUnitPower *) nanowatts { return nil; } -+ (NSUnitPower *) picowatts { return nil; } -+ (NSUnitPower *) femtowatts { return nil; } -+ (NSUnitPower *) horsepower { return nil; } ++ (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 From daeec9855467b845a58cd61b7a46f9bbc4c903d8 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 00:44:38 -0400 Subject: [PATCH 34/79] NSUnitSpeed --- Source/NSUnit.m | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 3cdcce1db..604b8de87 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -1101,10 +1101,37 @@ @implementation NSUnitSpeed // Base unit - metersPerSecond -+ (NSUnitSpeed *) metersPerSecond { return nil; } -+ (NSUnitSpeed *) kilometersPerHour { return nil; } -+ (NSUnitSpeed *) milesPerHour { return nil; } -+ (NSUnitSpeed *) knots { return nil; } ++ (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 From 3c1fcffae3ceee743039cd0e89a373f4307014fc Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 01:03:25 -0400 Subject: [PATCH 35/79] NSUnitFuelEfficiency --- Source/NSUnit.m | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 604b8de87..a233b3559 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -804,9 +804,29 @@ // Base unit - litersPer100Kilometers -+ (NSUnitFuelEfficiency *) litersPer100Kilometers { return nil; } -+ (NSUnitFuelEfficiency *) milesPerImperialGallon { return nil; } -+ (NSUnitFuelEfficiency *) milesPerGallon { return nil; } ++ (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 From 02872952dfe96823d7989efb1079d71dcbc0bb94 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 01:31:24 -0400 Subject: [PATCH 36/79] NSUnitPressure --- Source/NSUnit.m | 93 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 12 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index a233b3559..d2b9bcd25 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -1,7 +1,7 @@ /* Implementation of class NSUnit Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Mon Sep 30 15:58:21 EDT 2019 This file is part of the GNUstep Library. @@ -1098,23 +1098,92 @@ return result; } - @end @implementation NSUnitPressure // Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) -+ (NSUnitPressure *) newtonsPerMetersSquared { return nil; } -+ (NSUnitPressure *) gigapascals { return nil; } -+ (NSUnitPressure *) megapascals { return nil; } -+ (NSUnitPressure *) kilopascals { return nil; } -+ (NSUnitPressure *) hectopascals { return nil; } -+ (NSUnitPressure *) inchesOfMercury { return nil; } -+ (NSUnitPressure *) bars { return nil; } -+ (NSUnitPressure *) millibars { return nil; } -+ (NSUnitPressure *) millimetersOfMercury { return nil; } -+ (NSUnitPressure *) poundsForcePerSquareInch { return nil; } ++ (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 From 364076c109a02182248133ce503fc6563e35ab4d Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 02:07:20 -0400 Subject: [PATCH 37/79] NSUnitVolume --- Source/NSUnit.m | 295 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 258 insertions(+), 37 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index d2b9bcd25..47468e911 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -1230,61 +1230,282 @@ + (NSUnitTemperature *) kelvin { NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"K" - coefficient: 1.0 - constant: 0.0]; + coefficient: 1.0 + constant: 0.0]; return result; } + (NSUnitTemperature *) celsius { NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"C" - coefficient: 1.0 - constant: 273.15]; + coefficient: 1.0 + constant: 273.15]; return result; } + (NSUnitTemperature *) fahrenheit { NSUnitTemperature *result = [[NSUnitTemperature alloc] initWithSymbol: @"F" - coefficient: 0.55555555555556 - constant: 255.37222222222427]; + coefficient: 0.55555555555556 + constant: 255.37222222222427]; return result; } @end @implementation NSUnitVolume ++ (instancetype) baseUnit +{ + return [self liters]; +} // Base unit - liters -+ (NSUnitVolume *) megaliters { return nil; } -+ (NSUnitVolume *) kiloliters { return nil; } -+ (NSUnitVolume *) liters { return nil; } -+ (NSUnitVolume *) deciliters { return nil; } -+ (NSUnitVolume *) centiliters { return nil; } -+ (NSUnitVolume *) milliliters { return nil; } -+ (NSUnitVolume *) cubicKilometers { return nil; } -+ (NSUnitVolume *) cubicMeters { return nil; } -+ (NSUnitVolume *) cubicDecimeters { return nil; } -+ (NSUnitVolume *) cubicCentimeters { return nil; } -+ (NSUnitVolume *) cubicMillimeters { return nil; } -+ (NSUnitVolume *) cubicInches { return nil; } -+ (NSUnitVolume *) cubicFeet { return nil; } -+ (NSUnitVolume *) cubicYards { return nil; } -+ (NSUnitVolume *) cubicMiles { return nil; } -+ (NSUnitVolume *) acreFeet { return nil; } -+ (NSUnitVolume *) bushels { return nil; } -+ (NSUnitVolume *) teaspoons { return nil; } -+ (NSUnitVolume *) tablespoons { return nil; } -+ (NSUnitVolume *) fluidOunces { return nil; } -+ (NSUnitVolume *) cups { return nil; } -+ (NSUnitVolume *) pints { return nil; } -+ (NSUnitVolume *) quarts { return nil; } -+ (NSUnitVolume *) gallons { return nil; } -+ (NSUnitVolume *) imperialTeaspoons { return nil; } -+ (NSUnitVolume *) imperialTablespoons { return nil; } -+ (NSUnitVolume *) imperialFluidOunces { return nil; } -+ (NSUnitVolume *) imperialPints { return nil; } -+ (NSUnitVolume *) imperialQuarts { return nil; } -+ (NSUnitVolume *) imperialGallons { return nil; } -+ (NSUnitVolume *) metricCups { return nil; } ++ (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 From 884a146c1e9811b947b564ddc5b9d91341ff3dcf Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 02:28:50 -0400 Subject: [PATCH 38/79] NSUnitLength - complete implementation of all unit subclasses --- Source/NSUnit.m | 290 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 268 insertions(+), 22 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 47468e911..486e982bd 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -247,6 +247,11 @@ @implementation NSUnitAngle ++ (instancetype) baseUnit +{ + return [self degrees]; +} + // Base unit - degrees + (NSUnitAngle *) degrees { @@ -300,6 +305,11 @@ @implementation NSUnitArea ++ (instancetype) baseUnit +{ + return [self squareMeters]; +} + // Base unit - squareMeters + (NSUnitArea *) squareMegameters { @@ -417,6 +427,11 @@ @implementation NSUnitConcentrationMass ++ (instancetype) baseUnit +{ + return [self gramsPerLiter]; +} + // Base unit - gramsPerLiter + (NSUnitConcentrationMass *) gramsPerLiter { @@ -446,6 +461,11 @@ @implementation NSUnitDispersion ++ (instancetype) baseUnit +{ + return [self partsPerMillion]; +} + // Base unit - partsPerMillion + (NSUnitDispersion *) partsPerMillion { @@ -459,6 +479,11 @@ @implementation NSUnitDuration ++ (instancetype) baseUnit +{ + return [self seconds]; +} + // Base unit - seconds + (NSUnitDuration *) seconds { @@ -488,6 +513,11 @@ @implementation NSUnitElectricCharge ++ (instancetype) baseUnit +{ + return [self coulombs]; +} + // Base unit - coulombs + (NSUnitElectricCharge *) coulombs { @@ -541,6 +571,11 @@ @implementation NSUnitElectricCurrent ++ (instancetype) baseUnit +{ + return [self amperes]; +} + // Base unit - amperes + (NSUnitElectricCurrent *) megaamperes { @@ -586,6 +621,11 @@ @implementation NSUnitElectricPotentialDifference ++ (instancetype) baseUnit +{ + return [self volts]; +} + // Base unit - volts + (NSUnitElectricPotentialDifference *) megavolts { @@ -636,6 +676,11 @@ @implementation NSUnitElectricResistance ++ (instancetype) baseUnit +{ + return [self ohms]; +} + // Base unit - ohms + (NSUnitElectricResistance *) megaohms { @@ -687,6 +732,11 @@ @implementation NSUnitEnergy ++ (instancetype) baseUnit +{ + return [self joules]; +} + // Base unit - joules + (NSUnitEnergy *) kilojoules { @@ -732,6 +782,11 @@ @implementation NSUnitFrequency ++ (instancetype) baseUnit +{ + return [self hertz]; +} + // Base unit - hertz + (NSUnitFrequency *) terahertz @@ -802,6 +857,11 @@ @implementation NSUnitFuelEfficiency ++ (instancetype) baseUnit +{ + return [self litersPer100Kilometers]; +} + // Base unit - litersPer100Kilometers + (NSUnitFuelEfficiency *) litersPer100Kilometers @@ -832,35 +892,198 @@ @implementation NSUnitLength ++ (instancetype) baseUnit +{ + return [self meters]; +} + // Base unit - meters -+ (NSUnitLength *) megameters { return nil; } -+ (NSUnitLength *) kilometers { return nil; } -+ (NSUnitLength *) hectometers { return nil; } -+ (NSUnitLength *) decameters { return nil; } -+ (NSUnitLength *) meters { return nil; } -+ (NSUnitLength *) decimeters { return nil; } -+ (NSUnitLength *) centimeters { return nil; } -+ (NSUnitLength *) millimeters { return nil; } -+ (NSUnitLength *) micrometers { return nil; } -+ (NSUnitLength *) nanometers { return nil; } -+ (NSUnitLength *) picometers { return nil; } -+ (NSUnitLength *) inches { return nil; } -+ (NSUnitLength *) feet { return nil; } -+ (NSUnitLength *) yards { return nil; } -+ (NSUnitLength *) miles { return nil; } -+ (NSUnitLength *) scandinavianMiles { return nil; } -+ (NSUnitLength *) lightyears { return nil; } -+ (NSUnitLength *) nauticalMiles { return nil; } -+ (NSUnitLength *) fathoms { return nil; } -+ (NSUnitLength *) furlongs { return nil; } -+ (NSUnitLength *) astronomicalUnits { return nil; } -+ (NSUnitLength *) parsecs { return nil; } ++ (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 { @@ -874,6 +1097,11 @@ @implementation NSUnitMass ++ (instancetype) baseUnit +{ + return [self kilograms]; +} + // Base unit - kilograms + (NSUnitMass *) kilograms @@ -1008,6 +1236,11 @@ @implementation NSUnitPower ++ (instancetype) baseUnit +{ + return [self watts]; +} + // Base unit - watts + (NSUnitPower *) terawatts @@ -1102,6 +1335,11 @@ @implementation NSUnitPressure ++ (instancetype) baseUnit +{ + return [self newtonsPerMetersSquared]; +} + // Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) + (NSUnitPressure *) newtonsPerMetersSquared @@ -1188,6 +1426,10 @@ @end @implementation NSUnitSpeed ++ (instancetype) baseUnit +{ + return [self metersPerSecond]; +} // Base unit - metersPerSecond + (NSUnitSpeed *) metersPerSecond @@ -1225,6 +1467,10 @@ @end @implementation NSUnitTemperature ++ (instancetype) baseUnit +{ + return [self kelvin]; +} // Base unit - kelvin + (NSUnitTemperature *) kelvin From f56846b34260a0b75658ca7a4a868818ae213532 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 05:05:39 -0400 Subject: [PATCH 39/79] Implement calculations --- Source/NSUnit.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 486e982bd..000f6ea77 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -38,6 +38,9 @@ - (instancetype) init { self = [super init]; + if (self != nil) + { + } return self; } @@ -115,6 +118,16 @@ { return _constant; } + +- (double)baseUnitValueFromValue:(double)value +{ + return ((_coefficient * value) + _constant); +} + +- (double)valueFromBaseUnitValue:(double)baseUnitValue +{ + return ((baseUnitValue / _coefficient) - _constant); +} @end // Abstract unit... From 41f827fae1b48e5393f421acdd4b6f32d93faf76 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 05:26:01 -0400 Subject: [PATCH 40/79] compiling nsmeasurement --- Headers/Foundation/NSMeasurement.h | 25 ++++++++++++++++++-- Source/NSMeasurement.m | 37 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSMeasurement.h b/Headers/Foundation/NSMeasurement.h index d95c14239..596783403 100644 --- a/Headers/Foundation/NSMeasurement.h +++ b/Headers/Foundation/NSMeasurement.h @@ -2,7 +2,7 @@ /* Definition of class NSMeasurement Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Mon Sep 30 15:58:21 EDT 2019 This file is part of the GNUstep Library. @@ -27,6 +27,7 @@ #define _NSMeasurement_h_GNUSTEP_BASE_INCLUDE #include +#include #if defined(__cplusplus) extern "C" { @@ -34,7 +35,27 @@ extern "C" { #if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) -@interface NSMeasurement : NSObject +@interface NSMeasurement : NSObject + +// 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 diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index 91917bb94..c222f45cc 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -26,6 +26,43 @@ #include @implementation NSMeasurement +// Creating Measurements +- (instancetype)initWithDoubleValue: (double)doubleValue + unit: (NSUnit *)unit +{ + return nil; +} +// Accessing unit and value +- (NSUnit *) unit +{ + return nil; +} + +- (double) doubleValue +{ +} + +// Conversion +- (BOOL) canBeConvertedToUnit: (NSUnit *)unit +{ + return NO; +} + +- (NSMeasurement *)measurementByConvertingToUnit:(NSUnit *)unit +{ + return nil; +} + +// Operating +- (NSMeasurement *)measurementByAddingMeasurement:(NSMeasurement *)measurement +{ + return nil; +} + +- (NSMeasurement *)measurementBySubtractingMeasurement:(NSMeasurement *)measurement +{ + return nil; +} @end From c7d01e034870f86d45d34357780323a1a500f7ac Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 8 Oct 2019 07:57:03 -0400 Subject: [PATCH 41/79] Add initialization and change comment to reflect name. --- Headers/Foundation/NSMeasurement.h | 8 ++++- Source/NSMeasurement.m | 52 +++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/Headers/Foundation/NSMeasurement.h b/Headers/Foundation/NSMeasurement.h index 596783403..7f9abdc45 100644 --- a/Headers/Foundation/NSMeasurement.h +++ b/Headers/Foundation/NSMeasurement.h @@ -35,8 +35,14 @@ extern "C" { #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; diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index c222f45cc..804c17dc6 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -2,7 +2,7 @@ /* Implementation of class NSMeasurement Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Mon Sep 30 15:58:21 EDT 2019 This file is part of the GNUstep Library. @@ -24,34 +24,59 @@ */ #include +#include +#include @implementation NSMeasurement // Creating Measurements - (instancetype)initWithDoubleValue: (double)doubleValue unit: (NSUnit *)unit { - return nil; + 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 nil; + return _unit; } - (double) doubleValue { + return _doubleValue; } // Conversion - (BOOL) canBeConvertedToUnit: (NSUnit *)unit { - return NO; + return [unit isKindOfClass: [_unit class]]; } - (NSMeasurement *)measurementByConvertingToUnit:(NSUnit *)unit { - return nil; + NSMeasurement *result = nil; + if([self canBeConvertedToUnit: unit]) + { + // Do conversion... + } + else + { + [NSException raise: NSInvalidArgumentException + format: @"Cannot convert from %@ to %@", _unit, unit]; + } + return result; } // Operating @@ -64,5 +89,22 @@ { return nil; } + +// NSCopying +- (id) copyWithZone: (NSZone *)zone +{ + return [[[self class] allocWithZone: zone] initWithDoubleValue: _doubleValue + unit: _unit]; +} + +// NSCoding +- (void) encodeWithCoder: (NSCoder *)coder +{ +} + +- (id) initWithCoder: (NSCoder *)coder +{ + return self; +} @end From ac9a6850c8c633966ab4a48f6e0cceaaa56a8a65 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 9 Oct 2019 07:32:30 -0400 Subject: [PATCH 42/79] Add new formatter skeletons. --- Headers/Foundation/Foundation.h | 3 ++ Headers/Foundation/MISSING | 6 ---- Headers/Foundation/NSEnergyFormatter.h | 48 ++++++++++++++++++++++++++ Headers/Foundation/NSLengthFormatter.h | 48 ++++++++++++++++++++++++++ Source/GNUmakefile | 4 +++ Source/NSEnergyFormatter.m | 31 +++++++++++++++++ Source/NSLengthFormatter.m | 31 +++++++++++++++++ 7 files changed, 165 insertions(+), 6 deletions(-) create mode 100644 Headers/Foundation/NSEnergyFormatter.h create mode 100644 Headers/Foundation/NSLengthFormatter.h create mode 100644 Source/NSEnergyFormatter.m create mode 100644 Source/NSLengthFormatter.m diff --git a/Headers/Foundation/Foundation.h b/Headers/Foundation/Foundation.h index 9bb48ab71..c924faae1 100644 --- a/Headers/Foundation/Foundation.h +++ b/Headers/Foundation/Foundation.h @@ -61,6 +61,7 @@ #import #import #import +#import #import #import #import @@ -86,6 +87,7 @@ #import #import #import +#import #import #import #import @@ -138,6 +140,7 @@ #import #import #import +#import #import #import #import diff --git a/Headers/Foundation/MISSING b/Headers/Foundation/MISSING index a64d088bf..a39992fa3 100644 --- a/Headers/Foundation/MISSING +++ b/Headers/Foundation/MISSING @@ -22,7 +22,6 @@ NSBackgroundActivityScheduler.h NSDateComponentsFormatter.h NSDateIntervalFormatter.h NSDateInterval.h -NSEnergyFormatter.h NSExtensionContext.h NSExtensionItem.h NSExtensionRequestHandling.h @@ -30,15 +29,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 ------------------------------------------------------------- diff --git a/Headers/Foundation/NSEnergyFormatter.h b/Headers/Foundation/NSEnergyFormatter.h new file mode 100644 index 000000000..e0bc27fc2 --- /dev/null +++ b/Headers/Foundation/NSEnergyFormatter.h @@ -0,0 +1,48 @@ + +/* 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_0, GS_API_LATEST) + +@interface NSEnergyFormatter : NSFormatter + +@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..417eb659d --- /dev/null +++ b/Headers/Foundation/NSLengthFormatter.h @@ -0,0 +1,48 @@ + +/* Definition 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. +*/ + +#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_0, GS_API_LATEST) + +@interface NSLengthFormatter : NSFormatter + +@end + +#if defined(__cplusplus) +} +#endif + +#endif /* GS_API_MACOSX */ + +#endif /* _NSLengthFormatter_h_GNUSTEP_BASE_INCLUDE */ + diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 27cd54257..b2835e1d7 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -220,6 +220,7 @@ NSDictionary.m \ NSDistantObject.m \ NSDistributedLock.m \ NSDistributedNotificationCenter.m \ +NSEnergyFormatter.m \ NSEnumerator.m \ NSError.m \ NSException.m \ @@ -244,6 +245,7 @@ NSKeyedArchiver.m \ NSKeyedUnarchiver.m \ NSKeyValueCoding.m \ NSKeyValueObserving.m \ +NSLengthFormatter.m \ NSLocale.m \ NSLock.m \ NSLog.m \ @@ -413,6 +415,7 @@ NSDictionary.h \ NSDistantObject.h \ NSDistributedLock.h \ NSDistributedNotificationCenter.h \ +NSEnergyFormatter.h \ NSEnumerator.h \ NSError.h \ NSErrorRecoveryAttempting.h \ @@ -439,6 +442,7 @@ NSJSONSerialization.h \ NSKeyedArchiver.h \ NSKeyValueCoding.h \ NSKeyValueObserving.h \ +NSLengthFormtter.h \ NSLocale.h \ NSLock.h \ NSMapTable.h \ diff --git a/Source/NSEnergyFormatter.m b/Source/NSEnergyFormatter.m new file mode 100644 index 000000000..45b254d66 --- /dev/null +++ b/Source/NSEnergyFormatter.m @@ -0,0 +1,31 @@ + +/* Implementation 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. +*/ + +#include + +@implementation NSEnergyFormatter + +@end + diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m new file mode 100644 index 000000000..abd70ae10 --- /dev/null +++ b/Source/NSLengthFormatter.m @@ -0,0 +1,31 @@ + +/* 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 + +@implementation NSLengthFormatter + +@end + From 1b8d5562a1e8c650cd416e7979242e36dcd5e240 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 9 Oct 2019 11:46:05 -0400 Subject: [PATCH 43/79] Update MISSING file --- Headers/Foundation/MISSING | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/Headers/Foundation/MISSING b/Headers/Foundation/MISSING index a39992fa3..4c87acea7 100644 --- a/Headers/Foundation/MISSING +++ b/Headers/Foundation/MISSING @@ -35,35 +35,6 @@ NSObjectScripting.h NSOrthography.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 ------------------------------------------------------------- FoundationErrors: From e960b1be80422401c7178ab617c7639e8f54392d Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Fri, 11 Oct 2019 01:55:05 -0400 Subject: [PATCH 44/79] Implement add and subtract methods --- Headers/Foundation/MISSING | 2 -- Source/NSMeasurement.m | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Headers/Foundation/MISSING b/Headers/Foundation/MISSING index 4c87acea7..98a92d009 100644 --- a/Headers/Foundation/MISSING +++ b/Headers/Foundation/MISSING @@ -20,8 +20,6 @@ NSAppleEventDescriptor.h NSAppleEventManager.h NSBackgroundActivityScheduler.h NSDateComponentsFormatter.h -NSDateIntervalFormatter.h -NSDateInterval.h NSExtensionContext.h NSExtensionItem.h NSExtensionRequestHandling.h diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index 804c17dc6..437022982 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -61,15 +61,21 @@ // Conversion - (BOOL) canBeConvertedToUnit: (NSUnit *)unit { - return [unit isKindOfClass: [_unit class]]; + 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 { @@ -82,12 +88,28 @@ // Operating - (NSMeasurement *)measurementByAddingMeasurement:(NSMeasurement *)measurement { - return nil; + 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 { - return nil; + 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 From 36b209ff2eb60551c16fa3d637d1c375181d62e7 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Fri, 11 Oct 2019 01:59:46 -0400 Subject: [PATCH 45/79] Implement add and subtract methods --- Source/NSMeasurement.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index 437022982..b3bfc79ca 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -105,7 +105,7 @@ NSMeasurement *result = nil; double v = 0.0; - v = _doubleValue + [newMeasurement doubleValue]; + v = _doubleValue - [newMeasurement doubleValue]; result = [[NSMeasurement alloc] initWithDoubleValue: v unit: _unit]; AUTORELEASE(result); From a46edf36438551f538b54e865011d0305f9b1868 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Fri, 11 Oct 2019 08:58:14 -0400 Subject: [PATCH 46/79] Implement NSCoding --- Source/NSMeasurement.m | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index b3bfc79ca..57b26e904 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -26,6 +26,8 @@ #include #include #include +#include +#include @implementation NSMeasurement // Creating Measurements @@ -122,10 +124,33 @@ // NSCoding - (void) encodeWithCoder: (NSCoder *)coder { + if([coder allowsKeyedCoding]) + { + [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 From b1c868bbcb85757067eca193c04dea390ea44da3 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 12 Oct 2019 12:42:18 -0400 Subject: [PATCH 47/79] Add NSDateInterval.[hm] files. --- Headers/Foundation/Foundation.h | 1 + Headers/Foundation/NSDateInterval.h | 81 ++++++++++++++ Headers/Foundation/NSDateIntervalFormatter.h | 48 +++++++++ Source/GNUmakefile | 2 + Source/NSDateInterval.m | 106 +++++++++++++++++++ Source/NSDateIntervalFormatter.m | 31 ++++++ 6 files changed, 269 insertions(+) create mode 100644 Headers/Foundation/NSDateInterval.h create mode 100644 Headers/Foundation/NSDateIntervalFormatter.h create mode 100644 Source/NSDateInterval.m create mode 100644 Source/NSDateIntervalFormatter.m diff --git a/Headers/Foundation/Foundation.h b/Headers/Foundation/Foundation.h index c924faae1..d27814223 100644 --- a/Headers/Foundation/Foundation.h +++ b/Headers/Foundation/Foundation.h @@ -55,6 +55,7 @@ #import #import #import +#import #import #import #import diff --git a/Headers/Foundation/NSDateInterval.h b/Headers/Foundation/NSDateInterval.h new file mode 100644 index 000000000..672f2ebc2 --- /dev/null +++ b/Headers/Foundation/NSDateInterval.h @@ -0,0 +1,81 @@ + +/* Definition of class NSDateInterval + Copyright (C) 2019 Free Software Foundation, Inc. + + By: heron + 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 + +// 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..c04fc1b62 --- /dev/null +++ b/Headers/Foundation/NSDateIntervalFormatter.h @@ -0,0 +1,48 @@ + +/* 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_0, GS_API_LATEST) + +@interface NSDateIntervalFormatter : NSFormatter + +@end + +#if defined(__cplusplus) +} +#endif + +#endif /* GS_API_MACOSX */ + +#endif /* _NSDateIntervalFormatter_h_GNUSTEP_BASE_INCLUDE */ + diff --git a/Source/GNUmakefile b/Source/GNUmakefile index b2835e1d7..541d30f64 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -213,6 +213,7 @@ NSConnection.m \ NSData.m \ NSDate.m \ NSDateFormatter.m \ +NSDateInterval.m \ NSDebug.m \ NSDecimal.m \ NSDecimalNumber.m \ @@ -407,6 +408,7 @@ NSCompoundPredicate.h \ NSConnection.h \ NSData.h \ NSDateFormatter.h \ +NSDateInterval.h \ NSDate.h \ NSDebug.h \ NSDecimal.h \ diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m new file mode 100644 index 000000000..989dc367c --- /dev/null +++ b/Source/NSDateInterval.m @@ -0,0 +1,106 @@ + +/* Implementation of class NSDateInterval + Copyright (C) 2019 Free Software Foundation, Inc. + + By: heron + 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 + +@implementation NSDateInterval + +// Init +- (instancetype)init +{ +} + +- (instancetype)initWithStartDate:(NSDate *)startDate + duration:(NSTimeInterval)duration +{ +} + +- (instancetype)initWithStartDate:(NSDate *)startDate + endDate:(NSDate *)endDate +{ +} + +- (instancetype) initWithCoder: (NSCoder *)coder +{ +} + +- (void) encodeWithCoder: (NSCoder *)coder +{ +} + +- (id) copyWithZone: (NSZone *)zone +{ +} + +// 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 + diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m new file mode 100644 index 000000000..0ca18904f --- /dev/null +++ b/Source/NSDateIntervalFormatter.m @@ -0,0 +1,31 @@ + +/* Implementation 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. +*/ + +#include + +@implementation NSDateIntervalFormatter + +@end + From 49e2e14dd86a54ad30b87d1910d3f78b41455fa2 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 12 Oct 2019 12:44:15 -0400 Subject: [PATCH 48/79] Correct headers. --- Headers/Foundation/NSDateInterval.h | 2 +- Source/NSDateInterval.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSDateInterval.h b/Headers/Foundation/NSDateInterval.h index 672f2ebc2..2341ee4db 100644 --- a/Headers/Foundation/NSDateInterval.h +++ b/Headers/Foundation/NSDateInterval.h @@ -2,7 +2,7 @@ /* Definition of class NSDateInterval Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory Casamento Date: Wed Oct 9 16:24:13 EDT 2019 This file is part of the GNUstep Library. diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 989dc367c..2a15bffbd 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -2,7 +2,7 @@ /* Implementation of class NSDateInterval Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory Casamento Date: Wed Oct 9 16:24:13 EDT 2019 This file is part of the GNUstep Library. From 58a7201645c6375b5631fd5cf89d5d3d670415d8 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 12 Oct 2019 23:03:28 -0400 Subject: [PATCH 49/79] Implementation of most functions. --- Headers/Foundation/NSDateInterval.h | 7 ++- Source/NSDateInterval.m | 70 +++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/Headers/Foundation/NSDateInterval.h b/Headers/Foundation/NSDateInterval.h index 2341ee4db..f97c94972 100644 --- a/Headers/Foundation/NSDateInterval.h +++ b/Headers/Foundation/NSDateInterval.h @@ -36,7 +36,12 @@ extern "C" { #if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST) @interface NSDateInterval : NSObject - +{ + NSTimeInterval _duration; + NSDate *_startDate; + NSDate *_endDate; +} + // Init - (instancetype) init; diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 2a15bffbd..6619e80e2 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -24,26 +24,51 @@ */ #include +#include @implementation NSDateInterval // Init - (instancetype)init { + self = [super init]; + if(self != nil) + { + _startDate = nil; + _duration = 0.0; + } + return self; } - (instancetype)initWithStartDate:(NSDate *)startDate duration:(NSTimeInterval)duration { + self = [super init]; + if(self != nil) + { + ASSIGNCOPY(_startDate, startDate); + ASSIGNCOPY(_endDate, [startDate dateByAddingTimeInterval: duration]); + _duration = duration; + } + return self; } - (instancetype)initWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate { + self = [super init]; + if(self != nil) + { + ASSIGNCOPY(_startDate, startDate); + ASSIGNCOPY(_endDate, endDate); + _duration = [endDate timeIntervalSinceDate: startDate]; + } + return self; } - (instancetype) initWithCoder: (NSCoder *)coder { + return nil; } - (void) encodeWithCoder: (NSCoder *)coder @@ -52,54 +77,99 @@ - (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 _endDate; } - (void) setEndDate: (NSDate *)endDate { + ASSIGNCOPY(_endDate, endDate); + _duration = [endDate timeIntervalSinceDate: _startDate]; } - (NSTimeInterval) duration { + return _duration; } - (void) setDuration: (NSTimeInterval)duration { + NSDate *newEndDate = [_startDate dateByAddingTimeInterval: duration]; + _duration = duration; + [self setEndDate: newEndDate]; } // Compare - (NSComparisonResult) compare: (NSDateInterval *)dateInterval { + // NSOrderedAscending + if([_startDate isEqualToDate: [dateInterval startDate]] && + _duration < [dateInterval duration]) + return NSOrderedAscending; + if([_startDate compare: [dateInterval startDate]] == NSOrderedAscending) + return NSOrderedAscending; + + // NSOrderedSame + if([self isEqualToDateInterval: dateInterval]) + return NSOrderedSame; + + if([_startDate isEqualToDate: [dateInterval startDate]] && + _duration > [dateInterval duration]) + return NSOrderedDescending; + if([_startDate compare: [dateInterval startDate]] == NSOrderedDescending) + return NSOrderedDescending; + + return 0; } - (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 { + return nil; } // Contain - (BOOL) containsDate: (NSDate *)date { + return ([_startDate compare: date] == NSOrderedSame || + [_endDate compare: date] == NSOrderedSame || + ([_startDate compare: date] == NSOrderedAscending && + [_endDate compare: date] == NSOrderedDescending)); + } @end From 7fdf11935499e92ba3bf2f28b1fc38a55a46a036 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 16 Oct 2019 07:44:58 -0400 Subject: [PATCH 50/79] Complete implementation of intersectionWithDateInterval: --- Source/NSDateInterval.m | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 6619e80e2..b17489a96 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -25,6 +25,7 @@ #include #include +#include @implementation NSDateInterval @@ -129,16 +130,19 @@ if([_startDate isEqualToDate: [dateInterval startDate]] && _duration < [dateInterval duration]) return NSOrderedAscending; + if([_startDate compare: [dateInterval startDate]] == NSOrderedAscending) return NSOrderedAscending; - // NSOrderedSame + // NSOrderedSame if([self isEqualToDateInterval: dateInterval]) return NSOrderedSame; + // NSOrderedDescending if([_startDate isEqualToDate: [dateInterval startDate]] && _duration > [dateInterval duration]) return NSOrderedDescending; + if([_startDate compare: [dateInterval startDate]] == NSOrderedDescending) return NSOrderedDescending; @@ -159,7 +163,44 @@ - (NSDateInterval *) intersectionWithDateInterval: (NSDateInterval *)dateInterval { - return nil; + NSDateInterval *result = nil; + NSArray *array = [NSArray arrayWithObjects: self, dateInterval, nil]; + NSArray *sortedArray = [array sortedArrayUsingSelector: @selector(compare:)]; + NSDateInterval *first = [sortedArray firstObject]; + NSDateInterval *last = [sortedArray lastObject]; + NSDate *intersectStartDate = nil; + NSDate *intersectEndDate = nil; + + // 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 From 94a80ec191ef900b3b206c6023b297a73337b89f Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 17 Oct 2019 09:28:44 -0400 Subject: [PATCH 51/79] Add partial implementation of NSMeasurementFormatter --- Headers/Foundation/NSMeasurementFormatter.h | 40 ++++++++++++++++-- Source/NSMeasurementFormatter.m | 45 +++++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/Headers/Foundation/NSMeasurementFormatter.h b/Headers/Foundation/NSMeasurementFormatter.h index d9ae8edd6..1e293e043 100644 --- a/Headers/Foundation/NSMeasurementFormatter.h +++ b/Headers/Foundation/NSMeasurementFormatter.h @@ -26,15 +26,47 @@ #ifndef _NSMeasurementFormatter_h_GNUSTEP_BASE_INCLUDE #define _NSMeasurementFormatter_h_GNUSTEP_BASE_INCLUDE -#include - #if defined(__cplusplus) extern "C" { #endif + +#include +#include -#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) + @class NSLocale, NSMeasurement, NSNumberFormatter, NSUnit; + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST) -@interface NSMeasurementFormatter : NSObject +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 diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m index 81cde7709..a4918b771 100644 --- a/Source/NSMeasurementFormatter.m +++ b/Source/NSMeasurementFormatter.m @@ -24,8 +24,53 @@ */ #include +#include +#include +#include +#include @implementation NSMeasurementFormatter +- (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 From 967fe214729269a3fe3e0196e155498b836a862e Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 17 Oct 2019 10:14:50 -0400 Subject: [PATCH 52/79] Add partial implementation of NSMeasurementFormatter --- Source/NSMeasurementFormatter.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m index a4918b771..6a575a801 100644 --- a/Source/NSMeasurementFormatter.m +++ b/Source/NSMeasurementFormatter.m @@ -33,42 +33,52 @@ - (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 { + return nil; } - (NSString *)stringFromUnit: (NSUnit *)unit { + return nil; } From 8dd3b32d9022da6429ceb127731d6a39fa85937d Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 19 Oct 2019 07:03:33 -0400 Subject: [PATCH 53/79] Add init --- Headers/Foundation/NSMeasurementFormatter.h | 4 ++-- Source/NSMeasurementFormatter.m | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSMeasurementFormatter.h b/Headers/Foundation/NSMeasurementFormatter.h index 1e293e043..33be1196f 100644 --- a/Headers/Foundation/NSMeasurementFormatter.h +++ b/Headers/Foundation/NSMeasurementFormatter.h @@ -33,9 +33,9 @@ extern "C" { #include #include - @class NSLocale, NSMeasurement, NSNumberFormatter, NSUnit; +@class NSLocale, NSMeasurement, NSNumberFormatter, NSUnit; -#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST) +#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST) enum { NSMeasurementFormatterUnitOptionsProvidedUnit = (1UL << 0), diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m index 6a575a801..2fdb1e957 100644 --- a/Source/NSMeasurementFormatter.m +++ b/Source/NSMeasurementFormatter.m @@ -31,6 +31,24 @@ @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; From 88ac70374a488f164b004b2b48226d2ad24a8ebc Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 19 Oct 2019 09:36:49 -0400 Subject: [PATCH 54/79] Add init... update comments --- Source/NSMeasurementFormatter.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m index 2fdb1e957..3e17f481f 100644 --- a/Source/NSMeasurementFormatter.m +++ b/Source/NSMeasurementFormatter.m @@ -2,7 +2,7 @@ /* Implementation of class NSMeasurementFormatter Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Mon Sep 30 15:58:21 EDT 2019 This file is part of the GNUstep Library. From 97f817167c3746f722100de7678bc8969a81609a Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sat, 19 Oct 2019 18:21:22 -0400 Subject: [PATCH 55/79] Finish preliminary version of NSMeasurementFormatter --- Source/NSMeasurementFormatter.m | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m index 3e17f481f..3da5ddfdd 100644 --- a/Source/NSMeasurementFormatter.m +++ b/Source/NSMeasurementFormatter.m @@ -91,14 +91,41 @@ - (NSString *)stringFromMeasurement: (NSMeasurement *)measurement { - return nil; + 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 nil; + 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 From 629a3c2d5c69b52d98a865bf56c798061c2651dd Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 20 Oct 2019 09:21:22 -0400 Subject: [PATCH 56/79] Consistent header for NSDateIntervalFormatter.h --- Headers/Foundation/Foundation.h | 3 ++ Headers/Foundation/NSDateIntervalFormatter.h | 45 +++++++++++++++++++- Source/GNUmakefile | 2 + Source/NSDateIntervalFormatter.m | 2 +- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/Foundation.h b/Headers/Foundation/Foundation.h index d27814223..c1fd568a0 100644 --- a/Headers/Foundation/Foundation.h +++ b/Headers/Foundation/Foundation.h @@ -56,6 +56,7 @@ #import #import #import +#import #import #import #import @@ -92,6 +93,8 @@ #import #import #import +#import +#import #import #import #import diff --git a/Headers/Foundation/NSDateIntervalFormatter.h b/Headers/Foundation/NSDateIntervalFormatter.h index c04fc1b62..ebd051540 100644 --- a/Headers/Foundation/NSDateIntervalFormatter.h +++ b/Headers/Foundation/NSDateIntervalFormatter.h @@ -32,9 +32,52 @@ extern "C" { #endif -#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) +#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 diff --git a/Source/GNUmakefile b/Source/GNUmakefile index 541d30f64..72831e3c2 100644 --- a/Source/GNUmakefile +++ b/Source/GNUmakefile @@ -214,6 +214,7 @@ NSData.m \ NSDate.m \ NSDateFormatter.m \ NSDateInterval.m \ +NSDateIntervalFormatter.m \ NSDebug.m \ NSDecimal.m \ NSDecimalNumber.m \ @@ -409,6 +410,7 @@ NSConnection.h \ NSData.h \ NSDateFormatter.h \ NSDateInterval.h \ +NSDateIntervalFormatter.h \ NSDate.h \ NSDebug.h \ NSDecimal.h \ diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m index 0ca18904f..184a51762 100644 --- a/Source/NSDateIntervalFormatter.m +++ b/Source/NSDateIntervalFormatter.m @@ -2,7 +2,7 @@ /* Implementation of class NSDateIntervalFormatter Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Wed Oct 9 16:23:55 EDT 2019 This file is part of the GNUstep Library. From 66277860cc2c43589258cec404a84e66f5710830 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Sun, 20 Oct 2019 10:08:22 -0400 Subject: [PATCH 57/79] DateInterval formatter clean build. Still needs some logic --- Source/NSDateIntervalFormatter.m | 85 ++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m index 184a51762..f9979f5f0 100644 --- a/Source/NSDateIntervalFormatter.m +++ b/Source/NSDateIntervalFormatter.m @@ -24,8 +24,93 @@ */ #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 +{ + NSString *result = nil; + NSDate *fromDate = [dateInterval startDate]; + NSDate *toDate = [dateInterval endDate]; + + result = [NSString stringWithFormat: @"%@ - %@", fromDate, toDate]; + return result; +} @end From f34c95eddad9d7734cdd0570aefcca21f17b9d0b Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Mon, 21 Oct 2019 16:55:51 -0400 Subject: [PATCH 58/79] Remove _endDate from NSDateInterval --- Source/NSDateInterval.m | 11 ++++------- Source/NSUnit.m | 2 ++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index b17489a96..20b66d574 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -48,7 +48,6 @@ if(self != nil) { ASSIGNCOPY(_startDate, startDate); - ASSIGNCOPY(_endDate, [startDate dateByAddingTimeInterval: duration]); _duration = duration; } return self; @@ -102,12 +101,11 @@ - (NSDate *) endDate { - return _endDate; + return [_startDate dateByAddingTimeInterval: _duration]; } - (void) setEndDate: (NSDate *)endDate { - ASSIGNCOPY(_endDate, endDate); _duration = [endDate timeIntervalSinceDate: _startDate]; } @@ -118,9 +116,7 @@ - (void) setDuration: (NSTimeInterval)duration { - NSDate *newEndDate = [_startDate dateByAddingTimeInterval: duration]; _duration = duration; - [self setEndDate: newEndDate]; } // Compare @@ -206,10 +202,11 @@ // Contain - (BOOL) containsDate: (NSDate *)date { + NSDate *endDate = [self endDate]; return ([_startDate compare: date] == NSOrderedSame || - [_endDate compare: date] == NSOrderedSame || + [endDate compare: date] == NSOrderedSame || ([_startDate compare: date] == NSOrderedAscending && - [_endDate compare: date] == NSOrderedDescending)); + [endDate compare: date] == NSOrderedDescending)); } diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 000f6ea77..3f029834d 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -220,6 +220,8 @@ constant: constant]; NSDimension *result = [[[self class] alloc] initWithSymbol: symbol converter: converter]; + AUTORELEASE(converter); + AUTORELEASE(result); return result; } From 9a8c079c5512ecf6c580c403a9076ffdea2a33a6 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 22 Oct 2019 11:38:47 -0400 Subject: [PATCH 59/79] Formatting changes --- Source/NSDateIntervalFormatter.m | 4 ++-- Source/NSMeasurementFormatter.m | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m index f9979f5f0..b41982ea6 100644 --- a/Source/NSDateIntervalFormatter.m +++ b/Source/NSDateIntervalFormatter.m @@ -94,7 +94,7 @@ } // Create strings -- (NSString *)stringFromDate:(NSDate *)fromDate toDate:(NSDate *)toDate +- (NSString *) stringFromDate: (NSDate *)fromDate toDate: (NSDate *)toDate { NSDateInterval *interval = [[NSDateInterval alloc] initWithStartDate: fromDate endDate: toDate]; @@ -102,7 +102,7 @@ return [self stringFromDateInterval: interval]; } -- (NSString *)stringFromDateInterval:(NSDateInterval *)dateInterval +- (NSString *) stringFromDateInterval: (NSDateInterval *)dateInterval { NSString *result = nil; NSDate *fromDate = [dateInterval startDate]; diff --git a/Source/NSMeasurementFormatter.m b/Source/NSMeasurementFormatter.m index 3da5ddfdd..1f1d32534 100644 --- a/Source/NSMeasurementFormatter.m +++ b/Source/NSMeasurementFormatter.m @@ -1,4 +1,3 @@ - /* Implementation of class NSMeasurementFormatter Copyright (C) 2019 Free Software Foundation, Inc. From 2103216abcc2145723609a1d77d5e247c2a73cc0 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Tue, 22 Oct 2019 15:00:43 -0400 Subject: [PATCH 60/79] Add setters/getters --- Headers/Foundation/NSEnergyFormatter.h | 36 +++++++++++++++- Source/NSDateIntervalFormatter.m | 1 - Source/NSEnergyFormatter.m | 58 +++++++++++++++++++++++++- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/Headers/Foundation/NSEnergyFormatter.h b/Headers/Foundation/NSEnergyFormatter.h index e0bc27fc2..ad086cfea 100644 --- a/Headers/Foundation/NSEnergyFormatter.h +++ b/Headers/Foundation/NSEnergyFormatter.h @@ -32,10 +32,44 @@ extern "C" { #endif -#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) +#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) diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m index b41982ea6..02b828dd2 100644 --- a/Source/NSDateIntervalFormatter.m +++ b/Source/NSDateIntervalFormatter.m @@ -1,4 +1,3 @@ - /* Implementation of class NSDateIntervalFormatter Copyright (C) 2019 Free Software Foundation, Inc. diff --git a/Source/NSEnergyFormatter.m b/Source/NSEnergyFormatter.m index 45b254d66..e99867913 100644 --- a/Source/NSEnergyFormatter.m +++ b/Source/NSEnergyFormatter.m @@ -1,8 +1,7 @@ - /* Implementation of class NSEnergyFormatter Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Tue Oct 8 13:30:10 EDT 2019 This file is part of the GNUstep Library. @@ -27,5 +26,60 @@ @implementation NSEnergyFormatter +- (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 +{ + return nil; +} + +- (NSString *) stringFromJoules: (double)numberInJoules +{ + return nil; +} + +- (NSString *) unitStringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit +{ + return nil; +} + +- (NSString *) unitStringFromJoules: (double)numberInJoules usedUnit: (NSEnergyFormatterUnit *)unitp +{ + return nil; +} + +- (BOOL) getObjectValue:(id *)obj forString: (NSString *)string errorDescription: (NSString **)error +{ + return NO; +} + @end From f46219ca3f60e6145851759ffcbdc3d5d00296d5 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 23 Oct 2019 11:01:15 -0400 Subject: [PATCH 61/79] Remove end date --- Headers/Foundation/NSDateInterval.h | 1 - Source/NSDateInterval.m | 2 -- 2 files changed, 3 deletions(-) diff --git a/Headers/Foundation/NSDateInterval.h b/Headers/Foundation/NSDateInterval.h index f97c94972..962a9bbd7 100644 --- a/Headers/Foundation/NSDateInterval.h +++ b/Headers/Foundation/NSDateInterval.h @@ -39,7 +39,6 @@ extern "C" { { NSTimeInterval _duration; NSDate *_startDate; - NSDate *_endDate; } // Init diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 20b66d574..8bbda9a4d 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -1,4 +1,3 @@ - /* Implementation of class NSDateInterval Copyright (C) 2019 Free Software Foundation, Inc. @@ -60,7 +59,6 @@ if(self != nil) { ASSIGNCOPY(_startDate, startDate); - ASSIGNCOPY(_endDate, endDate); _duration = [endDate timeIntervalSinceDate: startDate]; } return self; From 0f26d53101148440f5fb7470bb6abc4815eaed1a Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 23 Oct 2019 11:03:58 -0400 Subject: [PATCH 62/79] Unit correction. --- Source/NSUnit.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 3f029834d..f14a58891 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -288,7 +288,7 @@ { NSUnitAngle *result = [[NSUnitAngle alloc] initWithSymbol: @"\"" coefficient: 0.00027778 - constant: 9.81]; + constant: 0.0]; return result; } From fd1fb807d087ef6f8ecb073180a5fb9868abe08f Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 23 Oct 2019 16:03:52 -0400 Subject: [PATCH 63/79] Initial skeleton for NSLengthFormatter. --- Headers/Foundation/NSLengthFormatter.h | 41 +++++++++++++++++++++-- Source/NSLengthFormatter.m | 45 ++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/Headers/Foundation/NSLengthFormatter.h b/Headers/Foundation/NSLengthFormatter.h index 417eb659d..68d91c7e7 100644 --- a/Headers/Foundation/NSLengthFormatter.h +++ b/Headers/Foundation/NSLengthFormatter.h @@ -1,8 +1,7 @@ - /* Definition of class NSLengthFormatter Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Tue Oct 8 13:30:33 EDT 2019 This file is part of the GNUstep Library. @@ -32,9 +31,45 @@ extern "C" { #endif -#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST) +#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; +} + +- (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 diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m index abd70ae10..cb0aac40e 100644 --- a/Source/NSLengthFormatter.m +++ b/Source/NSLengthFormatter.m @@ -27,5 +27,50 @@ @implementation NSLengthFormatter +- (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 +{ + return NO; +} + @end From 9ef1c7b0ac05c50cb905ab6f3e9f352c5b701730 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 23 Oct 2019 16:49:50 -0400 Subject: [PATCH 64/79] Skeletal implementation --- Headers/Foundation/NSLengthFormatter.h | 1 + Source/NSLengthFormatter.m | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/Headers/Foundation/NSLengthFormatter.h b/Headers/Foundation/NSLengthFormatter.h index 68d91c7e7..209fb0573 100644 --- a/Headers/Foundation/NSLengthFormatter.h +++ b/Headers/Foundation/NSLengthFormatter.h @@ -50,6 +50,7 @@ typedef NSInteger NSLengthFormatterUnit; { BOOL _isForPersonHeightUse; NSNumberFormatter *_numberFormatter; + NSFormattingUnitStyle _unitStyle; } - (NSNumberFormatter *) numberFormatter; diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m index cb0aac40e..70d08dfc7 100644 --- a/Source/NSLengthFormatter.m +++ b/Source/NSLengthFormatter.m @@ -29,42 +29,52 @@ - (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 { + return nil; } - (NSString *) stringFromMeters: (double)numberInMeters { + return nil; } - (NSString *) unitStringFromValue: (double)value unit: (NSLengthFormatterUnit)unit { + return nil; } - (NSString *) unitStringFromMeters: (double)numberInMeters usedUnit: (NSLengthFormatterUnit *)unit { + return nil; } - (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error From 7092968ed56c668aec49af9766a442803527bd19 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Wed, 23 Oct 2019 23:42:50 -0400 Subject: [PATCH 65/79] NSMassFormatter skeleton --- Headers/Foundation/NSMassFormatter.h | 39 +++++++++++++++++++- Source/NSMassFormatter.m | 55 ++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/Headers/Foundation/NSMassFormatter.h b/Headers/Foundation/NSMassFormatter.h index 6fc43889f..e58f0e78c 100644 --- a/Headers/Foundation/NSMassFormatter.h +++ b/Headers/Foundation/NSMassFormatter.h @@ -26,16 +26,51 @@ #ifndef _NSMassFormatter_h_GNUSTEP_BASE_INCLUDE #define _NSMassFormatter_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) +#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) diff --git a/Source/NSMassFormatter.m b/Source/NSMassFormatter.m index 27df3c32f..427575314 100644 --- a/Source/NSMassFormatter.m +++ b/Source/NSMassFormatter.m @@ -27,5 +27,60 @@ @implementation NSMassFormatter +- (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; +{ + return nil; +} + +- (NSString *)stringFromKilograms: (double)numberInKilograms; +{ + return nil; +} + +- (NSString *)unitStringFromValue: (double)value unit: (NSMassFormatterUnit)unit; +{ + return nil; +} + +- (NSString *)unitStringFromKilograms: (double)numberInKilograms usedUnit: (NSMassFormatterUnit *)unit +{ + return nil; +} + +- (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error +{ + return NO; +} + @end From 98830d39623c335e479b6ef20784bb694a180f8c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 00:03:40 -0400 Subject: [PATCH 66/79] Add init --- Source/NSEnergyFormatter.m | 12 ++++++++++++ Source/NSLengthFormatter.m | 12 ++++++++++++ Source/NSMassFormatter.m | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Source/NSEnergyFormatter.m b/Source/NSEnergyFormatter.m index e99867913..d6d4046e4 100644 --- a/Source/NSEnergyFormatter.m +++ b/Source/NSEnergyFormatter.m @@ -26,6 +26,18 @@ @implementation NSEnergyFormatter +- (instancetype) init +{ + self = [super init]; + if(self != nil) + { + _numberFormatter = nil; + _unitStyle = NSFormattingUnitStyleMedium; + _isForFoodEnergyUse = NO; + } + return self; +} + - (NSNumberFormatter *) numberFormatter { return _numberFormatter; diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m index 70d08dfc7..c21318496 100644 --- a/Source/NSLengthFormatter.m +++ b/Source/NSLengthFormatter.m @@ -27,6 +27,18 @@ @implementation NSLengthFormatter +- (instancetype) init +{ + self = [super init]; + if(self != nil) + { + _numberFormatter = nil; + _unitStyle = NSFormattingUnitStyleMedium; + _isForPersonHeightUse = NO; + } + return self; +} + - (NSNumberFormatter *) numberFormatter { return _numberFormatter; diff --git a/Source/NSMassFormatter.m b/Source/NSMassFormatter.m index 427575314..0354a13a4 100644 --- a/Source/NSMassFormatter.m +++ b/Source/NSMassFormatter.m @@ -27,6 +27,18 @@ @implementation NSMassFormatter +- (instancetype) init +{ + self = [super init]; + if(self != nil) + { + _numberFormatter = nil; + _unitStyle = NSFormattingUnitStyleMedium; + _isForPersonMassUse = NO; + } + return self; +} + - (NSNumberFormatter *) numberFormatter { return _numberFormatter; From de73db605c2dcf09e67c83be78c6609d8c2595c7 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 00:17:10 -0400 Subject: [PATCH 67/79] Add dealloc --- Source/NSLengthFormatter.m | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m index c21318496..4ecb427c2 100644 --- a/Source/NSLengthFormatter.m +++ b/Source/NSLengthFormatter.m @@ -39,6 +39,12 @@ return self; } +- (void) dealloc +{ + RELEASE(_numberFormatter); + [super dealloc]; +} + - (NSNumberFormatter *) numberFormatter { return _numberFormatter; From ea21e4821817253dc3a5911eb51d0aa1c767e5eb Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 14:18:47 -0400 Subject: [PATCH 68/79] Implement length formatter in terms of NSMeasurementFormatter --- Headers/Foundation/NSLengthFormatter.h | 2 +- Headers/Foundation/NSUnit.h | 3 +- Source/NSDateInterval.m | 3 +- Source/NSLengthFormatter.m | 66 ++++++++++++++++++++++++-- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/Headers/Foundation/NSLengthFormatter.h b/Headers/Foundation/NSLengthFormatter.h index 209fb0573..e1dae4b83 100644 --- a/Headers/Foundation/NSLengthFormatter.h +++ b/Headers/Foundation/NSLengthFormatter.h @@ -70,7 +70,7 @@ typedef NSInteger NSLengthFormatterUnit; - (NSString *) unitStringFromMeters: (double)numberInMeters usedUnit: (NSLengthFormatterUnit *)unit; -- (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error; +- (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error; @end diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index b7627c2aa..a35112aa0 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -1,7 +1,7 @@ /* Definition of class NSUnit Copyright (C) 2019 Free Software Foundation, Inc. - By: heron + By: Gregory John Casamento Date: Mon Sep 30 15:58:21 EDT 2019 This file is part of the GNUstep Library. @@ -58,7 +58,6 @@ extern "C" { NSString *_symbol; } -+ (instancetype)new; - (instancetype)init; - (instancetype)initWithSymbol:(NSString *) symbol; - (NSString *) symbol; diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 8bbda9a4d..4c790a776 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -34,8 +34,9 @@ self = [super init]; if(self != nil) { - _startDate = nil; + _startDate = [NSDate date]; _duration = 0.0; + RETAIN(_startDate); } return self; } diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m index 4ecb427c2..78360bb08 100644 --- a/Source/NSLengthFormatter.m +++ b/Source/NSLengthFormatter.m @@ -24,6 +24,9 @@ */ #include +#include +#include +#include @implementation NSLengthFormatter @@ -77,25 +80,78 @@ - (NSString *) stringFromValue: (double)value unit: (NSLengthFormatterUnit)unit { - return nil; + 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 nil; + NSUnit *u = nil; + NSMeasurement *m = nil; + NSMeasurementFormatter *mf = nil; + + u = [NSUnitLength meters]; + m = [[NSMeasurement alloc] initWithDoubleValue: numberInMeters + unit: u]; + AUTORELEASE(m); + mf = [[NSMeasurementFormatter alloc] init]; + AUTORELEASE(mf); + [mf setUnitStyle: _unitStyle]; + [mf setNumberFormatter: _numberFormatter]; + + return [mf stringFromMeasurement: m]; } - (NSString *) unitStringFromValue: (double)value unit: (NSLengthFormatterUnit)unit { - return nil; + return [self stringFromValue: value unit: unit]; } - (NSString *) unitStringFromMeters: (double)numberInMeters usedUnit: (NSLengthFormatterUnit *)unit { - return nil; + return [self stringFromValue: numberInMeters unit: NSLengthFormatterUnitMeter]; } -- (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error +- (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error { return NO; } From 0eb0c75022bdc8fd806a4f3eb22c4a390a9e212c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 14:34:26 -0400 Subject: [PATCH 69/79] Date interval fixes --- Source/NSDateInterval.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 4c790a776..1b17ff56d 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -25,6 +25,7 @@ #include #include #include +#include @implementation NSDateInterval @@ -48,7 +49,13 @@ if(self != nil) { ASSIGNCOPY(_startDate, startDate); + if(duration < 0) + { + [NSException raise: NSInvalidArgumentException + format: @"Duration %f is less than zero", duration]; + } _duration = duration; + } return self; } @@ -61,6 +68,12 @@ { ASSIGNCOPY(_startDate, startDate); _duration = [endDate timeIntervalSinceDate: startDate]; + if(_duration < 0) + { + [NSException raise: NSInvalidArgumentException + format: @"Duration %f is less than zero", _duration]; + } + } return self; } From 4dc072a25af3061e37cb99b9e322847d7f774fb0 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 14:38:50 -0400 Subject: [PATCH 70/79] Make initWithSymbol:coefficient:converter: into a full initializer. Use self instead of creating a new object. --- Source/NSUnit.m | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index f14a58891..38bfe4fb8 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -218,13 +218,12 @@ { NSUnitConverterLinear *converter = [[NSUnitConverterLinear alloc] initWithCoefficient: coefficient constant: constant]; - NSDimension *result = [[[self class] alloc] initWithSymbol: symbol - converter: converter]; - AUTORELEASE(converter); - AUTORELEASE(result); - return result; -} + self = [self initWithSymbol: symbol + converter: converter]; + AUTORELEASE(converter); + return self; +} + (instancetype) baseUnit { From 2e943461f86a4058e9c3d71bba2ca24df3584a16 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 14:50:36 -0400 Subject: [PATCH 71/79] Fix base unit value --- Source/NSUnit.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/NSUnit.m b/Source/NSUnit.m index 38bfe4fb8..d4bbec9f9 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -126,7 +126,7 @@ - (double)valueFromBaseUnitValue:(double)baseUnitValue { - return ((baseUnitValue / _coefficient) - _constant); + return (baseUnitValue - _constant) * _coefficient; //((baseUnitValue / _coefficient) - _constant); } @end From 7accf0410315a2904068d5ab0226dce203c295f3 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 14:58:43 -0400 Subject: [PATCH 72/79] Simplify compare --- Headers/Foundation/NSDateInterval.h | 1 - Source/NSDateInterval.m | 41 ++++++++++++++++------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/Headers/Foundation/NSDateInterval.h b/Headers/Foundation/NSDateInterval.h index 962a9bbd7..a7e6082b1 100644 --- a/Headers/Foundation/NSDateInterval.h +++ b/Headers/Foundation/NSDateInterval.h @@ -1,4 +1,3 @@ - /* Definition of class NSDateInterval Copyright (C) 2019 Free Software Foundation, Inc. diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 1b17ff56d..a0e168eee 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -134,27 +134,32 @@ // Compare - (NSComparisonResult) compare: (NSDateInterval *)dateInterval { - // NSOrderedAscending + NSComparisonResult result = NSOrderedSame; + if([_startDate isEqualToDate: [dateInterval startDate]] && _duration < [dateInterval duration]) - return NSOrderedAscending; + { + 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; + } - if([_startDate compare: [dateInterval startDate]] == NSOrderedAscending) - return NSOrderedAscending; - - // NSOrderedSame - if([self isEqualToDateInterval: dateInterval]) - return NSOrderedSame; - - // NSOrderedDescending - if([_startDate isEqualToDate: [dateInterval startDate]] && - _duration > [dateInterval duration]) - return NSOrderedDescending; - - if([_startDate compare: [dateInterval startDate]] == NSOrderedDescending) - return NSOrderedDescending; - - return 0; + return result; } - (BOOL) isEqualToDateInterval: (NSDateInterval *)dateInterval From 645fa0c0945e015b450650ad94204f79884dd734 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 17:06:06 -0400 Subject: [PATCH 73/79] Final implementations of formatters. --- Headers/Foundation/NSEnergyFormatter.h | 1 - Headers/Foundation/NSUnit.h | 2 +- Source/NSEnergyFormatter.m | 45 ++++++++++++++++++++++---- Source/NSLengthFormatter.m | 18 ++--------- Source/NSMassFormatter.m | 43 +++++++++++++++++++++--- Source/NSUnit.m | 2 +- 6 files changed, 82 insertions(+), 29 deletions(-) diff --git a/Headers/Foundation/NSEnergyFormatter.h b/Headers/Foundation/NSEnergyFormatter.h index ad086cfea..a105ab347 100644 --- a/Headers/Foundation/NSEnergyFormatter.h +++ b/Headers/Foundation/NSEnergyFormatter.h @@ -1,4 +1,3 @@ - /* Definition of class NSEnergyFormatter Copyright (C) 2019 Free Software Foundation, Inc. diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index a35112aa0..57a65b075 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -301,7 +301,7 @@ extern "C" { + (NSUnitMass *) nanograms; + (NSUnitMass *) picograms; + (NSUnitMass *) ounces; -+ (NSUnitMass *) poundsMass; ++ (NSUnitMass *) pounds; + (NSUnitMass *) stones; + (NSUnitMass *) metricTons; + (NSUnitMass *) shortTons; diff --git a/Source/NSEnergyFormatter.m b/Source/NSEnergyFormatter.m index d6d4046e4..f599515a7 100644 --- a/Source/NSEnergyFormatter.m +++ b/Source/NSEnergyFormatter.m @@ -23,6 +23,9 @@ */ #include +#include +#include +#include @implementation NSEnergyFormatter @@ -67,28 +70,56 @@ { _isForFoodEnergyUse = flag; } - - (NSString *) stringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit { - return nil; + 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 nil; + return [self stringFromValue: numberInJoules unit: NSEnergyFormatterUnitJoule]; } - (NSString *) unitStringFromValue: (double)value unit: (NSEnergyFormatterUnit)unit { - return nil; + return [self stringFromValue: value unit: unit]; } -- (NSString *) unitStringFromJoules: (double)numberInJoules usedUnit: (NSEnergyFormatterUnit *)unitp +- (NSString *) unitStringFromJoules: (double)numberInJoules usedUnit: (NSEnergyFormatterUnit *)unit { - return nil; + *unit = NSEnergyFormatterUnitJoule; + return [self stringFromValue: numberInJoules unit: *unit]; } -- (BOOL) getObjectValue:(id *)obj forString: (NSString *)string errorDescription: (NSString **)error +- (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error { return NO; } diff --git a/Source/NSLengthFormatter.m b/Source/NSLengthFormatter.m index 78360bb08..6e7f93c26 100644 --- a/Source/NSLengthFormatter.m +++ b/Source/NSLengthFormatter.m @@ -125,20 +125,7 @@ - (NSString *) stringFromMeters: (double)numberInMeters { - NSUnit *u = nil; - NSMeasurement *m = nil; - NSMeasurementFormatter *mf = nil; - - u = [NSUnitLength meters]; - m = [[NSMeasurement alloc] initWithDoubleValue: numberInMeters - unit: u]; - AUTORELEASE(m); - mf = [[NSMeasurementFormatter alloc] init]; - AUTORELEASE(mf); - [mf setUnitStyle: _unitStyle]; - [mf setNumberFormatter: _numberFormatter]; - - return [mf stringFromMeasurement: m]; + return [self stringFromValue: numberInMeters unit: NSLengthFormatterUnitMeter]; } - (NSString *) unitStringFromValue: (double)value unit: (NSLengthFormatterUnit)unit @@ -148,7 +135,8 @@ - (NSString *) unitStringFromMeters: (double)numberInMeters usedUnit: (NSLengthFormatterUnit *)unit { - return [self stringFromValue: numberInMeters unit: NSLengthFormatterUnitMeter]; + *unit = NSLengthFormatterUnitMeter; + return [self stringFromValue: numberInMeters unit: *unit]; } - (BOOL)getObjectValue: (id *)obj forString: (NSString *)string errorDescription: (NSString **)error diff --git a/Source/NSMassFormatter.m b/Source/NSMassFormatter.m index 0354a13a4..5252d37e8 100644 --- a/Source/NSMassFormatter.m +++ b/Source/NSMassFormatter.m @@ -24,6 +24,9 @@ */ #include +#include +#include +#include @implementation NSMassFormatter @@ -71,22 +74,54 @@ - (NSString *)stringFromValue: (double)value unit: (NSMassFormatterUnit)unit; { - return nil; + 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 nil; + return [self stringFromValue: numberInKilograms unit: NSMassFormatterUnitKilogram]; } - (NSString *)unitStringFromValue: (double)value unit: (NSMassFormatterUnit)unit; { - return nil; + return [self stringFromValue: value unit: unit]; } - (NSString *)unitStringFromKilograms: (double)numberInKilograms usedUnit: (NSMassFormatterUnit *)unit { - return nil; + *unit = NSMassFormatterUnitKilogram; + return [self stringFromValue: numberInKilograms unit: *unit]; } - (BOOL)getObjectValue: (id*)obj forString: (NSString *)string errorDescription: (NSString **)error diff --git a/Source/NSUnit.m b/Source/NSUnit.m index d4bbec9f9..adb66dd72 100644 --- a/Source/NSUnit.m +++ b/Source/NSUnit.m @@ -1190,7 +1190,7 @@ return result; } -+ (NSUnitMass *) poundsMass ++ (NSUnitMass *) pounds { NSUnitMass *result = [[NSUnitMass alloc] initWithSymbol: @"lb" coefficient: 0.453592 From 19c305c06c7fd1de2a028cdbd0ef91dc86f5445c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 18:15:37 -0400 Subject: [PATCH 74/79] Remove uneeded declarations --- Headers/Foundation/NSMeasurement.h | 11 ++++---- Headers/Foundation/NSUnit.h | 42 +++++++++++++++--------------- Source/NSMeasurement.m | 8 +++--- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/Headers/Foundation/NSMeasurement.h b/Headers/Foundation/NSMeasurement.h index 7f9abdc45..822a993fa 100644 --- a/Headers/Foundation/NSMeasurement.h +++ b/Headers/Foundation/NSMeasurement.h @@ -1,4 +1,3 @@ - /* Definition of class NSMeasurement Copyright (C) 2019 Free Software Foundation, Inc. @@ -44,8 +43,8 @@ extern "C" { } // Creating Measurements -- (instancetype)initWithDoubleValue: (double)doubleValue - unit: (NSUnit *)unit; +- (instancetype) initWithDoubleValue: (double)doubleValue + unit: (NSUnit *)unit; // Accessing unit and value @@ -56,12 +55,12 @@ extern "C" { // Conversion - (BOOL) canBeConvertedToUnit: (NSUnit *)unit; -- (NSMeasurement *)measurementByConvertingToUnit:(NSUnit *)unit; +- (NSMeasurement *) measurementByConvertingToUnit: (NSUnit *)unit; // Operating -- (NSMeasurement *)measurementByAddingMeasurement:(NSMeasurement *)measurement; +- (NSMeasurement *) measurementByAddingMeasurement: (NSMeasurement *)measurement; -- (NSMeasurement *)measurementBySubtractingMeasurement:(NSMeasurement *)measurement; +- (NSMeasurement *) measurementBySubtractingMeasurement: (NSMeasurement *)measurement; @end diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 57a65b075..b207560a8 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -78,7 +78,7 @@ extern "C" { @end // Predefined.... -@interface NSUnitAcceleration : NSDimension +@interface NSUnitAcceleration : NSDimension /* Base unit - metersPerSecondSquared */ @@ -88,7 +88,7 @@ extern "C" { @end -@interface NSUnitAngle : NSDimension +@interface NSUnitAngle : NSDimension /* Base unit - degrees */ @@ -102,7 +102,7 @@ extern "C" { @end -@interface NSUnitArea : NSDimension +@interface NSUnitArea : NSDimension /* Base unit - squareMeters */ @@ -124,7 +124,7 @@ extern "C" { @end -@interface NSUnitConcentrationMass : NSDimension +@interface NSUnitConcentrationMass : NSDimension /* Base unit - gramsPerLiter */ @@ -136,7 +136,7 @@ extern "C" { @end -@interface NSUnitDispersion : NSDimension +@interface NSUnitDispersion : NSDimension /* Base unit - partsPerMillion */ @@ -144,7 +144,7 @@ extern "C" { @end -@interface NSUnitDuration : NSDimension +@interface NSUnitDuration : NSDimension /* Base unit - seconds */ @@ -155,7 +155,7 @@ extern "C" { @end -@interface NSUnitElectricCharge : NSDimension +@interface NSUnitElectricCharge : NSDimension /* Base unit - coulombs */ @@ -169,7 +169,7 @@ extern "C" { @end -@interface NSUnitElectricCurrent : NSDimension +@interface NSUnitElectricCurrent : NSDimension /* Base unit - amperes */ @@ -182,7 +182,7 @@ extern "C" { @end -@interface NSUnitElectricPotentialDifference : NSDimension +@interface NSUnitElectricPotentialDifference : NSDimension /* Base unit - volts */ @@ -195,7 +195,7 @@ extern "C" { @end -@interface NSUnitElectricResistance : NSDimension +@interface NSUnitElectricResistance : NSDimension /* Base unit - ohms */ @@ -208,7 +208,7 @@ extern "C" { @end -@interface NSUnitEnergy : NSDimension +@interface NSUnitEnergy : NSDimension /* Base unit - joules */ @@ -221,7 +221,7 @@ extern "C" { @end -@interface NSUnitFrequency : NSDimension +@interface NSUnitFrequency : NSDimension /* Base unit - hertz */ @@ -237,7 +237,7 @@ extern "C" { @end -@interface NSUnitFuelEfficiency : NSDimension +@interface NSUnitFuelEfficiency : NSDimension /* Base unit - litersPer100Kilometers */ @@ -248,7 +248,7 @@ extern "C" { @end -@interface NSUnitLength : NSDimension +@interface NSUnitLength : NSDimension /* Base unit - meters */ @@ -278,7 +278,7 @@ extern "C" { @end -@interface NSUnitIlluminance : NSDimension +@interface NSUnitIlluminance : NSDimension /* Base unit - lux */ @@ -287,7 +287,7 @@ extern "C" { @end -@interface NSUnitMass : NSDimension +@interface NSUnitMass : NSDimension /* Base unit - kilograms */ @@ -311,7 +311,7 @@ extern "C" { @end -@interface NSUnitPower : NSDimension +@interface NSUnitPower : NSDimension /* Base unit - watts */ @@ -330,7 +330,7 @@ extern "C" { @end -@interface NSUnitPressure : NSDimension +@interface NSUnitPressure : NSDimension /* Base unit - newtonsPerMetersSquared (equivalent to 1 pascal) */ @@ -348,7 +348,7 @@ extern "C" { @end -@interface NSUnitSpeed : NSDimension +@interface NSUnitSpeed : NSDimension /* Base unit - metersPerSecond */ @@ -360,7 +360,7 @@ extern "C" { @end -@interface NSUnitTemperature : NSDimension +@interface NSUnitTemperature : NSDimension /* Base unit - kelvin */ @@ -371,7 +371,7 @@ extern "C" { @end -@interface NSUnitVolume : NSDimension +@interface NSUnitVolume : NSDimension /* Base unit - liters */ diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index 57b26e904..059d96701 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -1,4 +1,3 @@ - /* Implementation of class NSMeasurement Copyright (C) 2019 Free Software Foundation, Inc. @@ -67,7 +66,7 @@ [unit respondsToSelector: @selector(converter)]); } -- (NSMeasurement *)measurementByConvertingToUnit:(NSUnit *)unit +- (NSMeasurement *) measurementByConvertingToUnit: (NSUnit *)unit { NSMeasurement *result = nil; double val = 0.0; @@ -88,7 +87,7 @@ } // Operating -- (NSMeasurement *)measurementByAddingMeasurement:(NSMeasurement *)measurement +- (NSMeasurement *) measurementByAddingMeasurement: (NSMeasurement *)measurement { NSMeasurement *newMeasurement = [measurement measurementByConvertingToUnit: _unit]; NSMeasurement *result = nil; @@ -101,7 +100,7 @@ return result; } -- (NSMeasurement *)measurementBySubtractingMeasurement:(NSMeasurement *)measurement +- (NSMeasurement *) measurementBySubtractingMeasurement: (NSMeasurement *)measurement { NSMeasurement *newMeasurement = [measurement measurementByConvertingToUnit: _unit]; NSMeasurement *result = nil; @@ -126,6 +125,7 @@ { if([coder allowsKeyedCoding]) { + // Verify that this is the correct encoding... [coder encodeObject: _unit forKey: @"unit"]; [coder encodeDouble: _doubleValue forKey: @"doubleValue"]; } From d5bf551f37d98741508863ffefef3f3d33c4792e Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 18:16:59 -0400 Subject: [PATCH 75/79] Remove uneeded declarations --- Headers/Foundation/NSUnit.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index b207560a8..8d83e85d5 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -35,8 +35,8 @@ extern "C" { // Unit converter @interface NSUnitConverter : NSObject -- (double)baseUnitValueFromValue:(double)value; -- (double)valueFromBaseUnitValue:(double)baseUnitValue; +- (double) baseUnitValueFromValue: (double)value; +- (double) valueFromBaseUnitValue: (double)baseUnitValue; @end // Linea converter... for things like C <-> F conversion... @@ -58,8 +58,8 @@ extern "C" { NSString *_symbol; } -- (instancetype)init; -- (instancetype)initWithSymbol:(NSString *) symbol; +- (instancetype) init; +- (instancetype) initWithSymbol: (NSString *)symbol; - (NSString *) symbol; @end @@ -72,7 +72,7 @@ extern "C" { } - (NSUnitConverter *) converter; -- (instancetype) initWithSymbol: (NSString *) symbol converter: (NSUnitConverter *) converter ; +- (instancetype) initWithSymbol: (NSString *)symbol converter: (NSUnitConverter *)converter ; + (instancetype) baseUnit; @end From 5f060018eb2d7f9f93289cd23ce9628cdc21ab25 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 18:17:59 -0400 Subject: [PATCH 76/79] Remove uneeded declarations --- Headers/Foundation/NSUnit.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Headers/Foundation/NSUnit.h b/Headers/Foundation/NSUnit.h index 8d83e85d5..f5d80a972 100644 --- a/Headers/Foundation/NSUnit.h +++ b/Headers/Foundation/NSUnit.h @@ -132,7 +132,7 @@ extern "C" { + (NSUnitConcentrationMass *) gramsPerLiter; + (NSUnitConcentrationMass *) milligramsPerDeciliter; -+ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole:(double)gramsPerMole; ++ (NSUnitConcentrationMass *) millimolesPerLiterWithGramsPerMole: (double)gramsPerMole; @end From 2b3846e76d203bfa545c0f2ebf362d34dc182b8b Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 18:22:10 -0400 Subject: [PATCH 77/79] Add TODOs --- Source/NSDateInterval.m | 16 +++------------- Source/NSMeasurement.m | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index a0e168eee..08136b640 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -63,23 +63,13 @@ - (instancetype)initWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate { - self = [super init]; - if(self != nil) - { - ASSIGNCOPY(_startDate, startDate); - _duration = [endDate timeIntervalSinceDate: startDate]; - if(_duration < 0) - { - [NSException raise: NSInvalidArgumentException - format: @"Duration %f is less than zero", _duration]; - } - - } - return self; + return [self initWithStartDate: startDate + duration: [endDate timeIntervalSinceDate: startDate]]; } - (instancetype) initWithCoder: (NSCoder *)coder { + // TODO: Implement encoding return nil; } diff --git a/Source/NSMeasurement.m b/Source/NSMeasurement.m index 059d96701..76d925daa 100644 --- a/Source/NSMeasurement.m +++ b/Source/NSMeasurement.m @@ -125,7 +125,7 @@ { if([coder allowsKeyedCoding]) { - // Verify that this is the correct encoding... + // TODO: Verify that this is the correct encoding... [coder encodeObject: _unit forKey: @"unit"]; [coder encodeDouble: _doubleValue forKey: @"doubleValue"]; } From 058762c8c5c7a4aea08a8c3c779ef202954fc60c Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 18:51:21 -0400 Subject: [PATCH 78/79] Simplify method --- Source/NSDateIntervalFormatter.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m index 02b828dd2..1d6bebddb 100644 --- a/Source/NSDateIntervalFormatter.m +++ b/Source/NSDateIntervalFormatter.m @@ -106,9 +106,10 @@ NSString *result = nil; NSDate *fromDate = [dateInterval startDate]; NSDate *toDate = [dateInterval endDate]; + + // Add formatting of NSDate here. - result = [NSString stringWithFormat: @"%@ - %@", fromDate, toDate]; - return result; + return [NSString stringWithFormat: @"%@ - %@", fromDate, toDate]; } @end From a251bbbb58bdfe7fc50a982067a5e8411e8192e4 Mon Sep 17 00:00:00 2001 From: Gregory John Casamento Date: Thu, 24 Oct 2019 19:38:19 -0400 Subject: [PATCH 79/79] Minor fixes --- Source/NSDateInterval.m | 8 ++++---- Source/NSDateIntervalFormatter.m | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/NSDateInterval.m b/Source/NSDateInterval.m index 08136b640..da8b1f476 100644 --- a/Source/NSDateInterval.m +++ b/Source/NSDateInterval.m @@ -167,12 +167,12 @@ - (NSDateInterval *) intersectionWithDateInterval: (NSDateInterval *)dateInterval { NSDateInterval *result = nil; - NSArray *array = [NSArray arrayWithObjects: self, dateInterval, nil]; - NSArray *sortedArray = [array sortedArrayUsingSelector: @selector(compare:)]; - NSDateInterval *first = [sortedArray firstObject]; - NSDateInterval *last = [sortedArray lastObject]; + 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 || diff --git a/Source/NSDateIntervalFormatter.m b/Source/NSDateIntervalFormatter.m index 1d6bebddb..f8dda781c 100644 --- a/Source/NSDateIntervalFormatter.m +++ b/Source/NSDateIntervalFormatter.m @@ -103,7 +103,6 @@ - (NSString *) stringFromDateInterval: (NSDateInterval *)dateInterval { - NSString *result = nil; NSDate *fromDate = [dateInterval startDate]; NSDate *toDate = [dateInterval endDate];