Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Units: Add UnitInformationStorage #3059

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions DarwinCompatibilityTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
659FB6E02405E65D00F5F63F /* TestBridging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 659FB6DF2405E65D00F5F63F /* TestBridging.swift */; };
ABB1293726D47D9E00401E6C /* TestUnitInformationStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */; };
B91161AF242A385A00BD2907 /* TestDataURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */; };
B917D32420B0DB9700728EE0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B917D32320B0DB9700728EE0 /* Foundation.framework */; };
B94B07402401847C00B244E8 /* FTPServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B94B073C2401847C00B244E8 /* FTPServer.swift */; };
@@ -175,6 +176,7 @@

/* Begin PBXFileReference section */
659FB6DF2405E65D00F5F63F /* TestBridging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestBridging.swift; path = Tests/Foundation/Tests/TestBridging.swift; sourceTree = "<group>"; };
ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestUnitInformationStorage.swift; path = Tests/Foundation/Tests/TestUnitInformationStorage.swift; sourceTree = "<group>"; };
B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestDataURLProtocol.swift; path = Tests/Foundation/Tests/TestDataURLProtocol.swift; sourceTree = "<group>"; };
B917D31C20B0DB8B00728EE0 /* xdgTestHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = xdgTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
B917D32320B0DB9700728EE0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -343,6 +345,7 @@
B9C89EB81F6BF47D00087AF4 = {
isa = PBXGroup;
children = (
ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */,
B9F449292483FA1E00B30F02 /* TestNSURL.swift */,
B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */,
B94B08342401854E00B244E8 /* main.swift */,
@@ -710,6 +713,7 @@
B94B07EF2401849B00B244E8 /* TestByteCountFormatter.swift in Sources */,
B94B07F02401849B00B244E8 /* TestURL.swift in Sources */,
B94B07F12401849B00B244E8 /* TestCachedURLResponse.swift in Sources */,
ABB1293726D47D9E00401E6C /* TestUnitInformationStorage.swift in Sources */,
B94B07F22401849B00B244E8 /* TestDecimal.swift in Sources */,
B94B07F32401849B00B244E8 /* TestStream.swift in Sources */,
B94B07F42401849B00B244E8 /* TestNSData.swift in Sources */,
4 changes: 4 additions & 0 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -403,6 +403,7 @@
A058C2021E529CF100B07AA1 /* TestMassFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A058C2011E529CF100B07AA1 /* TestMassFormatter.swift */; };
AA9E0E0B21FA6C5600963F4C /* PropertyListEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA9E0E0A21FA6C5600963F4C /* PropertyListEncoder.swift */; };
AA9E0E0D21FA6E0700963F4C /* TestPropertyListEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA9E0E0C21FA6E0700963F4C /* TestPropertyListEncoder.swift */; };
ABB1293526D4736B00401E6C /* TestUnitInformationStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB1293426D4736B00401E6C /* TestUnitInformationStorage.swift */; };
B907F36B20BB07A700013CBE /* NSString-ISO-8859-1-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B907F36A20BB07A700013CBE /* NSString-ISO-8859-1-data.txt */; };
B90C57BB1EEEEA5A005208AE /* TestFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AECEB1BF2C96400D15BB0 /* TestFileManager.swift */; };
B90C57BC1EEEEA5A005208AE /* TestThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5835F31C20C9B500C81317 /* TestThread.swift */; };
@@ -1129,6 +1130,7 @@
A5A34B551C18C85D00FD972B /* TestByteCountFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestByteCountFormatter.swift; sourceTree = "<group>"; };
AA9E0E0A21FA6C5600963F4C /* PropertyListEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PropertyListEncoder.swift; sourceTree = "<group>"; };
AA9E0E0C21FA6E0700963F4C /* TestPropertyListEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestPropertyListEncoder.swift; sourceTree = "<group>"; };
ABB1293426D4736B00401E6C /* TestUnitInformationStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUnitInformationStorage.swift; sourceTree = "<group>"; };
B167A6641ED7303F0040B09A /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
B907F36A20BB07A700013CBE /* NSString-ISO-8859-1-data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSString-ISO-8859-1-data.txt"; sourceTree = "<group>"; };
B91095781EEF237800A71930 /* NSString-UTF16-LE-data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSString-UTF16-LE-data.txt"; sourceTree = "<group>"; };
@@ -1922,6 +1924,7 @@
84BA558D1C16F90900F48C54 /* TestTimeZone.swift */,
3E55A2321F52463B00082000 /* TestUnit.swift */,
CC5249BF1D341D23007CB54D /* TestUnitConverter.swift */,
ABB1293426D4736B00401E6C /* TestUnitInformationStorage.swift */,
5D0E1BDA237A1FE800C35C5A /* TestUnitVolume.swift */,
EA66F6431BF1619600136161 /* TestURL.swift */,
1581706222B1A29100348861 /* TestURLCache.swift */,
@@ -3216,6 +3219,7 @@
7D0DE86E211883F500540061 /* TestDateComponents.swift in Sources */,
5B13B3351C582D4C00651CE2 /* TestNSKeyedUnarchiver.swift in Sources */,
5B13B33D1C582D4C00651CE2 /* TestPipe.swift in Sources */,
ABB1293526D4736B00401E6C /* TestUnitInformationStorage.swift in Sources */,
F9E0BB371CA70B8000F7FF3C /* TestURLCredential.swift in Sources */,
5B13B3341C582D4C00651CE2 /* TestNSKeyedArchiver.swift in Sources */,
5B13B3441C582D4C00651CE2 /* TestNSSet.swift in Sources */,
1 change: 1 addition & 0 deletions Sources/Foundation/NSObjCRuntime.swift
Original file line number Diff line number Diff line change
@@ -313,6 +313,7 @@ internal let _NSClassesRenamedByObjCAPINotes: [(class: AnyClass, objCName: Strin
(UnitFrequency.self, "NSUnitFrequency"),
(UnitFuelEfficiency.self, "NSUnitFuelEfficiency"),
(UnitIlluminance.self, "NSUnitIlluminance"),
(UnitInformationStorage.self, "NSUnitInformationStorage"),
(UnitLength.self, "NSUnitLength"),
(UnitMass.self, "NSUnitMass"),
(UnitPower.self, "NSUnitPower"),
319 changes: 319 additions & 0 deletions Sources/Foundation/Unit.swift
Original file line number Diff line number Diff line change
@@ -1457,6 +1457,325 @@ public final class UnitIlluminance : Dimension {
}
}

public final class UnitInformationStorage : Dimension {

/*
Base unit - bit
*/

private struct Symbol {
static let bytes = "B"
static let bits = "bit"
static let nibbles = "nibble"
static let yottabytes = "YB"
static let zettabytes = "ZB"
static let exabytes = "EB"
static let petabytes = "PB"
static let terabytes = "TB"
static let gigabytes = "GB"
static let megabytes = "MB"
static let kilobytes = "kB"

static let yottabits = "Yb"
static let zettabits = "Zb"
static let exabits = "Eb"
static let petabits = "Pb"
static let terabits = "Tb"
static let gigabits = "Gb"
static let megabits = "Mb"
static let kilobits = "kb"

static let yobibytes = "YiB"
static let zebibytes = "ZiB"
static let exbibytes = "EiB"
static let pebibytes = "PiB"
static let tebibytes = "TiB"
static let gibibytes = "GiB"
static let mebibytes = "MiB"
static let kibibytes = "KiB"

static let yobibits = "Yib"
static let zebibits = "Zib"
static let exbibits = "Eib"
static let pebibits = "Pib"
static let tebibits = "Tib"
static let gibibits = "Gib"
static let mebibits = "Mib"
static let kibibits = "Kib"
}

private struct Coefficient {
static let bytes = 8.0
static let bits = 1.0
static let nibbles = 4.0
static let yottabytes = 8.0*pow(1000.0, 8.0)
static let zettabytes = 8.0*pow(1000.0, 7.0)
static let exabytes = 8.0*pow(1000.0, 6.0)
static let petabytes = 8.0*pow(1000.0, 5.0)
static let terabytes = 8.0*pow(1000.0, 4.0)
static let gigabytes = 8.0*pow(1000.0, 3.0)
static let megabytes = 8.0*pow(1000.0, 2.0)
static let kilobytes = 8.0*1000

static let yottabits = pow(1000.0, 8.0)
static let zettabits = pow(1000.0, 7.0)
static let exabits = pow(1000.0, 6.0)
static let petabits = pow(1000.0, 5.0)
static let terabits = pow(1000.0, 4.0)
static let gigabits = pow(1000.0, 3.0)
static let megabits = pow(1000.0, 2.0)
static let kilobits = 1000.0

static let yobibytes = 8*pow(1024.0, 8.0)
static let zebibytes = 8*pow(1024.0, 7.0)
static let exbibytes = 8*pow(1024.0, 6.0)
static let pebibytes = 8*pow(1024.0, 5.0)
static let tebibytes = 8*pow(1024.0, 4.0)
static let gibibytes = 8*pow(1024.0, 3.0)
static let mebibytes = 8*pow(1024.0, 2.0)
static let kibibytes = 8*1024.0

static let yobibits = pow(1024.0, 8.0)
static let zebibits = pow(1024.0, 7.0)
static let exbibits = pow(1024.0, 6.0)
static let pebibits = pow(1024.0, 5.0)
static let tebibits = pow(1024.0, 4.0)
static let gibibits = pow(1024.0, 3.0)
static let mebibits = pow(1024.0, 2.0)
static let kibibits = 1024.0
}

private convenience init(symbol: String, coefficient: Double) {
self.init(symbol: symbol, converter: UnitConverterLinear(coefficient: coefficient))
}

public class var bytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.bytes, coefficient: Coefficient.bytes)
}
}

public class var bits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.bits, coefficient: Coefficient.bits)
}
}

public class var nibbles: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.nibbles, coefficient: Coefficient.nibbles)
}
}

public class var yottabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.yottabytes, coefficient: Coefficient.yottabytes)
}
}

public class var zettabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.zettabytes, coefficient: Coefficient.zettabytes)
}
}

public class var exabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.exabytes, coefficient: Coefficient.exabytes)
}
}

public class var petabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.petabytes, coefficient: Coefficient.petabytes)
}
}

public class var terabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.terabytes, coefficient: Coefficient.terabytes)
}
}

public class var gigabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.gigabytes, coefficient: Coefficient.gigabytes)
}
}

public class var megabytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.megabytes, coefficient: Coefficient.megabytes)
}
}

public class var kilobytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.kilobytes, coefficient: Coefficient.kilobytes)
}
}

public class var yottabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.yottabits, coefficient: Coefficient.yottabits)
}
}

public class var zettabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.zettabits, coefficient: Coefficient.zettabits)
}
}

public class var exabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.exabits, coefficient: Coefficient.exabits)
}
}

public class var petabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.petabits, coefficient: Coefficient.petabits)
}
}

public class var terabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.terabits, coefficient: Coefficient.terabits)
}
}

public class var gigabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.gigabits, coefficient: Coefficient.gigabits)
}
}

public class var megabits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.megabits, coefficient: Coefficient.megabits)
}
}

public class var kilobits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.kilobits, coefficient: Coefficient.kilobits)
}
}

public class var yobibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.yobibytes, coefficient: Coefficient.yobibytes)
}
}

public class var zebibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.zebibytes, coefficient: Coefficient.zebibytes)
}
}

public class var exbibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.exbibytes, coefficient: Coefficient.exbibytes)
}
}

public class var pebibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.pebibytes, coefficient: Coefficient.pebibytes)
}
}

public class var tebibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.tebibytes, coefficient: Coefficient.tebibytes)
}
}

public class var gibibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.gibibytes, coefficient: Coefficient.gibibytes)
}
}

public class var mebibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.mebibytes, coefficient: Coefficient.mebibytes)
}
}

public class var kibibytes: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.kibibytes, coefficient: Coefficient.kibibytes)
}
}

public class var yobibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.yobibits, coefficient: Coefficient.yobibits)
}
}

public class var zebibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.zebibits, coefficient: Coefficient.zebibits)
}
}

public class var exbibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.exbibits, coefficient: Coefficient.exbibits)
}
}

public class var pebibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.pebibits, coefficient: Coefficient.pebibits)
}
}

public class var tebibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.tebibits, coefficient: Coefficient.tebibits)
}
}

public class var gibibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.gibibits, coefficient: Coefficient.gibibits)
}
}

public class var mebibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.mebibits, coefficient: Coefficient.mebibits)
}
}

public class var kibibits: UnitInformationStorage {
get {
return UnitInformationStorage(symbol: Symbol.kibibits, coefficient: Coefficient.kibibits)
}
}

public override class func baseUnit() -> UnitInformationStorage {
return .bits
}

public override func isEqual(_ object: Any?) -> Bool {
guard let other = object as? UnitInformationStorage else {
return false
}

if self === other {
return true
}

return super.isEqual(object)
}
}

public final class UnitMass : Dimension {

/*
Loading