Skip to content

Commit b65b4c7

Browse files
authored
Merge pull request #3059 from corymosiman12/feature/linux-UnitInformationStorage
2 parents 759d9eb + f1935c7 commit b65b4c7

File tree

9 files changed

+407
-0
lines changed

9 files changed

+407
-0
lines changed

DarwinCompatibilityTests.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

176177
/* Begin PBXFileReference section */
177178
659FB6DF2405E65D00F5F63F /* TestBridging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestBridging.swift; path = Tests/Foundation/Tests/TestBridging.swift; sourceTree = "<group>"; };
179+
ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestUnitInformationStorage.swift; path = Tests/Foundation/Tests/TestUnitInformationStorage.swift; sourceTree = "<group>"; };
178180
B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestDataURLProtocol.swift; path = Tests/Foundation/Tests/TestDataURLProtocol.swift; sourceTree = "<group>"; };
179181
B917D31C20B0DB8B00728EE0 /* xdgTestHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = xdgTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
180182
B917D32320B0DB9700728EE0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -343,6 +345,7 @@
343345
B9C89EB81F6BF47D00087AF4 = {
344346
isa = PBXGroup;
345347
children = (
348+
ABB1293626D47D9E00401E6C /* TestUnitInformationStorage.swift */,
346349
B9F449292483FA1E00B30F02 /* TestNSURL.swift */,
347350
B91161AE242A385A00BD2907 /* TestDataURLProtocol.swift */,
348351
B94B08342401854E00B244E8 /* main.swift */,
@@ -710,6 +713,7 @@
710713
B94B07EF2401849B00B244E8 /* TestByteCountFormatter.swift in Sources */,
711714
B94B07F02401849B00B244E8 /* TestURL.swift in Sources */,
712715
B94B07F12401849B00B244E8 /* TestCachedURLResponse.swift in Sources */,
716+
ABB1293726D47D9E00401E6C /* TestUnitInformationStorage.swift in Sources */,
713717
B94B07F22401849B00B244E8 /* TestDecimal.swift in Sources */,
714718
B94B07F32401849B00B244E8 /* TestStream.swift in Sources */,
715719
B94B07F42401849B00B244E8 /* TestNSData.swift in Sources */,

Foundation.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@
403403
A058C2021E529CF100B07AA1 /* TestMassFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A058C2011E529CF100B07AA1 /* TestMassFormatter.swift */; };
404404
AA9E0E0B21FA6C5600963F4C /* PropertyListEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA9E0E0A21FA6C5600963F4C /* PropertyListEncoder.swift */; };
405405
AA9E0E0D21FA6E0700963F4C /* TestPropertyListEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA9E0E0C21FA6E0700963F4C /* TestPropertyListEncoder.swift */; };
406+
ABB1293526D4736B00401E6C /* TestUnitInformationStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABB1293426D4736B00401E6C /* TestUnitInformationStorage.swift */; };
406407
B907F36B20BB07A700013CBE /* NSString-ISO-8859-1-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B907F36A20BB07A700013CBE /* NSString-ISO-8859-1-data.txt */; };
407408
B90C57BB1EEEEA5A005208AE /* TestFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 525AECEB1BF2C96400D15BB0 /* TestFileManager.swift */; };
408409
B90C57BC1EEEEA5A005208AE /* TestThread.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E5835F31C20C9B500C81317 /* TestThread.swift */; };
@@ -1129,6 +1130,7 @@
11291130
A5A34B551C18C85D00FD972B /* TestByteCountFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestByteCountFormatter.swift; sourceTree = "<group>"; };
11301131
AA9E0E0A21FA6C5600963F4C /* PropertyListEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PropertyListEncoder.swift; sourceTree = "<group>"; };
11311132
AA9E0E0C21FA6E0700963F4C /* TestPropertyListEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestPropertyListEncoder.swift; sourceTree = "<group>"; };
1133+
ABB1293426D4736B00401E6C /* TestUnitInformationStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestUnitInformationStorage.swift; sourceTree = "<group>"; };
11321134
B167A6641ED7303F0040B09A /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
11331135
B907F36A20BB07A700013CBE /* NSString-ISO-8859-1-data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSString-ISO-8859-1-data.txt"; sourceTree = "<group>"; };
11341136
B91095781EEF237800A71930 /* NSString-UTF16-LE-data.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "NSString-UTF16-LE-data.txt"; sourceTree = "<group>"; };
@@ -1922,6 +1924,7 @@
19221924
84BA558D1C16F90900F48C54 /* TestTimeZone.swift */,
19231925
3E55A2321F52463B00082000 /* TestUnit.swift */,
19241926
CC5249BF1D341D23007CB54D /* TestUnitConverter.swift */,
1927+
ABB1293426D4736B00401E6C /* TestUnitInformationStorage.swift */,
19251928
5D0E1BDA237A1FE800C35C5A /* TestUnitVolume.swift */,
19261929
EA66F6431BF1619600136161 /* TestURL.swift */,
19271930
1581706222B1A29100348861 /* TestURLCache.swift */,
@@ -3216,6 +3219,7 @@
32163219
7D0DE86E211883F500540061 /* TestDateComponents.swift in Sources */,
32173220
5B13B3351C582D4C00651CE2 /* TestNSKeyedUnarchiver.swift in Sources */,
32183221
5B13B33D1C582D4C00651CE2 /* TestPipe.swift in Sources */,
3222+
ABB1293526D4736B00401E6C /* TestUnitInformationStorage.swift in Sources */,
32193223
F9E0BB371CA70B8000F7FF3C /* TestURLCredential.swift in Sources */,
32203224
5B13B3341C582D4C00651CE2 /* TestNSKeyedArchiver.swift in Sources */,
32213225
5B13B3441C582D4C00651CE2 /* TestNSSet.swift in Sources */,

Sources/Foundation/NSObjCRuntime.swift

+1
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ internal let _NSClassesRenamedByObjCAPINotes: [(class: AnyClass, objCName: Strin
313313
(UnitFrequency.self, "NSUnitFrequency"),
314314
(UnitFuelEfficiency.self, "NSUnitFuelEfficiency"),
315315
(UnitIlluminance.self, "NSUnitIlluminance"),
316+
(UnitInformationStorage.self, "NSUnitInformationStorage"),
316317
(UnitLength.self, "NSUnitLength"),
317318
(UnitMass.self, "NSUnitMass"),
318319
(UnitPower.self, "NSUnitPower"),

Sources/Foundation/Unit.swift

+319
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,325 @@ public final class UnitIlluminance : Dimension {
14571457
}
14581458
}
14591459

1460+
public final class UnitInformationStorage : Dimension {
1461+
1462+
/*
1463+
Base unit - bit
1464+
*/
1465+
1466+
private struct Symbol {
1467+
static let bytes = "B"
1468+
static let bits = "bit"
1469+
static let nibbles = "nibble"
1470+
static let yottabytes = "YB"
1471+
static let zettabytes = "ZB"
1472+
static let exabytes = "EB"
1473+
static let petabytes = "PB"
1474+
static let terabytes = "TB"
1475+
static let gigabytes = "GB"
1476+
static let megabytes = "MB"
1477+
static let kilobytes = "kB"
1478+
1479+
static let yottabits = "Yb"
1480+
static let zettabits = "Zb"
1481+
static let exabits = "Eb"
1482+
static let petabits = "Pb"
1483+
static let terabits = "Tb"
1484+
static let gigabits = "Gb"
1485+
static let megabits = "Mb"
1486+
static let kilobits = "kb"
1487+
1488+
static let yobibytes = "YiB"
1489+
static let zebibytes = "ZiB"
1490+
static let exbibytes = "EiB"
1491+
static let pebibytes = "PiB"
1492+
static let tebibytes = "TiB"
1493+
static let gibibytes = "GiB"
1494+
static let mebibytes = "MiB"
1495+
static let kibibytes = "KiB"
1496+
1497+
static let yobibits = "Yib"
1498+
static let zebibits = "Zib"
1499+
static let exbibits = "Eib"
1500+
static let pebibits = "Pib"
1501+
static let tebibits = "Tib"
1502+
static let gibibits = "Gib"
1503+
static let mebibits = "Mib"
1504+
static let kibibits = "Kib"
1505+
}
1506+
1507+
private struct Coefficient {
1508+
static let bytes = 8.0
1509+
static let bits = 1.0
1510+
static let nibbles = 4.0
1511+
static let yottabytes = 8.0*pow(1000.0, 8.0)
1512+
static let zettabytes = 8.0*pow(1000.0, 7.0)
1513+
static let exabytes = 8.0*pow(1000.0, 6.0)
1514+
static let petabytes = 8.0*pow(1000.0, 5.0)
1515+
static let terabytes = 8.0*pow(1000.0, 4.0)
1516+
static let gigabytes = 8.0*pow(1000.0, 3.0)
1517+
static let megabytes = 8.0*pow(1000.0, 2.0)
1518+
static let kilobytes = 8.0*1000
1519+
1520+
static let yottabits = pow(1000.0, 8.0)
1521+
static let zettabits = pow(1000.0, 7.0)
1522+
static let exabits = pow(1000.0, 6.0)
1523+
static let petabits = pow(1000.0, 5.0)
1524+
static let terabits = pow(1000.0, 4.0)
1525+
static let gigabits = pow(1000.0, 3.0)
1526+
static let megabits = pow(1000.0, 2.0)
1527+
static let kilobits = 1000.0
1528+
1529+
static let yobibytes = 8*pow(1024.0, 8.0)
1530+
static let zebibytes = 8*pow(1024.0, 7.0)
1531+
static let exbibytes = 8*pow(1024.0, 6.0)
1532+
static let pebibytes = 8*pow(1024.0, 5.0)
1533+
static let tebibytes = 8*pow(1024.0, 4.0)
1534+
static let gibibytes = 8*pow(1024.0, 3.0)
1535+
static let mebibytes = 8*pow(1024.0, 2.0)
1536+
static let kibibytes = 8*1024.0
1537+
1538+
static let yobibits = pow(1024.0, 8.0)
1539+
static let zebibits = pow(1024.0, 7.0)
1540+
static let exbibits = pow(1024.0, 6.0)
1541+
static let pebibits = pow(1024.0, 5.0)
1542+
static let tebibits = pow(1024.0, 4.0)
1543+
static let gibibits = pow(1024.0, 3.0)
1544+
static let mebibits = pow(1024.0, 2.0)
1545+
static let kibibits = 1024.0
1546+
}
1547+
1548+
private convenience init(symbol: String, coefficient: Double) {
1549+
self.init(symbol: symbol, converter: UnitConverterLinear(coefficient: coefficient))
1550+
}
1551+
1552+
public class var bytes: UnitInformationStorage {
1553+
get {
1554+
return UnitInformationStorage(symbol: Symbol.bytes, coefficient: Coefficient.bytes)
1555+
}
1556+
}
1557+
1558+
public class var bits: UnitInformationStorage {
1559+
get {
1560+
return UnitInformationStorage(symbol: Symbol.bits, coefficient: Coefficient.bits)
1561+
}
1562+
}
1563+
1564+
public class var nibbles: UnitInformationStorage {
1565+
get {
1566+
return UnitInformationStorage(symbol: Symbol.nibbles, coefficient: Coefficient.nibbles)
1567+
}
1568+
}
1569+
1570+
public class var yottabytes: UnitInformationStorage {
1571+
get {
1572+
return UnitInformationStorage(symbol: Symbol.yottabytes, coefficient: Coefficient.yottabytes)
1573+
}
1574+
}
1575+
1576+
public class var zettabytes: UnitInformationStorage {
1577+
get {
1578+
return UnitInformationStorage(symbol: Symbol.zettabytes, coefficient: Coefficient.zettabytes)
1579+
}
1580+
}
1581+
1582+
public class var exabytes: UnitInformationStorage {
1583+
get {
1584+
return UnitInformationStorage(symbol: Symbol.exabytes, coefficient: Coefficient.exabytes)
1585+
}
1586+
}
1587+
1588+
public class var petabytes: UnitInformationStorage {
1589+
get {
1590+
return UnitInformationStorage(symbol: Symbol.petabytes, coefficient: Coefficient.petabytes)
1591+
}
1592+
}
1593+
1594+
public class var terabytes: UnitInformationStorage {
1595+
get {
1596+
return UnitInformationStorage(symbol: Symbol.terabytes, coefficient: Coefficient.terabytes)
1597+
}
1598+
}
1599+
1600+
public class var gigabytes: UnitInformationStorage {
1601+
get {
1602+
return UnitInformationStorage(symbol: Symbol.gigabytes, coefficient: Coefficient.gigabytes)
1603+
}
1604+
}
1605+
1606+
public class var megabytes: UnitInformationStorage {
1607+
get {
1608+
return UnitInformationStorage(symbol: Symbol.megabytes, coefficient: Coefficient.megabytes)
1609+
}
1610+
}
1611+
1612+
public class var kilobytes: UnitInformationStorage {
1613+
get {
1614+
return UnitInformationStorage(symbol: Symbol.kilobytes, coefficient: Coefficient.kilobytes)
1615+
}
1616+
}
1617+
1618+
public class var yottabits: UnitInformationStorage {
1619+
get {
1620+
return UnitInformationStorage(symbol: Symbol.yottabits, coefficient: Coefficient.yottabits)
1621+
}
1622+
}
1623+
1624+
public class var zettabits: UnitInformationStorage {
1625+
get {
1626+
return UnitInformationStorage(symbol: Symbol.zettabits, coefficient: Coefficient.zettabits)
1627+
}
1628+
}
1629+
1630+
public class var exabits: UnitInformationStorage {
1631+
get {
1632+
return UnitInformationStorage(symbol: Symbol.exabits, coefficient: Coefficient.exabits)
1633+
}
1634+
}
1635+
1636+
public class var petabits: UnitInformationStorage {
1637+
get {
1638+
return UnitInformationStorage(symbol: Symbol.petabits, coefficient: Coefficient.petabits)
1639+
}
1640+
}
1641+
1642+
public class var terabits: UnitInformationStorage {
1643+
get {
1644+
return UnitInformationStorage(symbol: Symbol.terabits, coefficient: Coefficient.terabits)
1645+
}
1646+
}
1647+
1648+
public class var gigabits: UnitInformationStorage {
1649+
get {
1650+
return UnitInformationStorage(symbol: Symbol.gigabits, coefficient: Coefficient.gigabits)
1651+
}
1652+
}
1653+
1654+
public class var megabits: UnitInformationStorage {
1655+
get {
1656+
return UnitInformationStorage(symbol: Symbol.megabits, coefficient: Coefficient.megabits)
1657+
}
1658+
}
1659+
1660+
public class var kilobits: UnitInformationStorage {
1661+
get {
1662+
return UnitInformationStorage(symbol: Symbol.kilobits, coefficient: Coefficient.kilobits)
1663+
}
1664+
}
1665+
1666+
public class var yobibytes: UnitInformationStorage {
1667+
get {
1668+
return UnitInformationStorage(symbol: Symbol.yobibytes, coefficient: Coefficient.yobibytes)
1669+
}
1670+
}
1671+
1672+
public class var zebibytes: UnitInformationStorage {
1673+
get {
1674+
return UnitInformationStorage(symbol: Symbol.zebibytes, coefficient: Coefficient.zebibytes)
1675+
}
1676+
}
1677+
1678+
public class var exbibytes: UnitInformationStorage {
1679+
get {
1680+
return UnitInformationStorage(symbol: Symbol.exbibytes, coefficient: Coefficient.exbibytes)
1681+
}
1682+
}
1683+
1684+
public class var pebibytes: UnitInformationStorage {
1685+
get {
1686+
return UnitInformationStorage(symbol: Symbol.pebibytes, coefficient: Coefficient.pebibytes)
1687+
}
1688+
}
1689+
1690+
public class var tebibytes: UnitInformationStorage {
1691+
get {
1692+
return UnitInformationStorage(symbol: Symbol.tebibytes, coefficient: Coefficient.tebibytes)
1693+
}
1694+
}
1695+
1696+
public class var gibibytes: UnitInformationStorage {
1697+
get {
1698+
return UnitInformationStorage(symbol: Symbol.gibibytes, coefficient: Coefficient.gibibytes)
1699+
}
1700+
}
1701+
1702+
public class var mebibytes: UnitInformationStorage {
1703+
get {
1704+
return UnitInformationStorage(symbol: Symbol.mebibytes, coefficient: Coefficient.mebibytes)
1705+
}
1706+
}
1707+
1708+
public class var kibibytes: UnitInformationStorage {
1709+
get {
1710+
return UnitInformationStorage(symbol: Symbol.kibibytes, coefficient: Coefficient.kibibytes)
1711+
}
1712+
}
1713+
1714+
public class var yobibits: UnitInformationStorage {
1715+
get {
1716+
return UnitInformationStorage(symbol: Symbol.yobibits, coefficient: Coefficient.yobibits)
1717+
}
1718+
}
1719+
1720+
public class var zebibits: UnitInformationStorage {
1721+
get {
1722+
return UnitInformationStorage(symbol: Symbol.zebibits, coefficient: Coefficient.zebibits)
1723+
}
1724+
}
1725+
1726+
public class var exbibits: UnitInformationStorage {
1727+
get {
1728+
return UnitInformationStorage(symbol: Symbol.exbibits, coefficient: Coefficient.exbibits)
1729+
}
1730+
}
1731+
1732+
public class var pebibits: UnitInformationStorage {
1733+
get {
1734+
return UnitInformationStorage(symbol: Symbol.pebibits, coefficient: Coefficient.pebibits)
1735+
}
1736+
}
1737+
1738+
public class var tebibits: UnitInformationStorage {
1739+
get {
1740+
return UnitInformationStorage(symbol: Symbol.tebibits, coefficient: Coefficient.tebibits)
1741+
}
1742+
}
1743+
1744+
public class var gibibits: UnitInformationStorage {
1745+
get {
1746+
return UnitInformationStorage(symbol: Symbol.gibibits, coefficient: Coefficient.gibibits)
1747+
}
1748+
}
1749+
1750+
public class var mebibits: UnitInformationStorage {
1751+
get {
1752+
return UnitInformationStorage(symbol: Symbol.mebibits, coefficient: Coefficient.mebibits)
1753+
}
1754+
}
1755+
1756+
public class var kibibits: UnitInformationStorage {
1757+
get {
1758+
return UnitInformationStorage(symbol: Symbol.kibibits, coefficient: Coefficient.kibibits)
1759+
}
1760+
}
1761+
1762+
public override class func baseUnit() -> UnitInformationStorage {
1763+
return .bits
1764+
}
1765+
1766+
public override func isEqual(_ object: Any?) -> Bool {
1767+
guard let other = object as? UnitInformationStorage else {
1768+
return false
1769+
}
1770+
1771+
if self === other {
1772+
return true
1773+
}
1774+
1775+
return super.isEqual(object)
1776+
}
1777+
}
1778+
14601779
public final class UnitMass : Dimension {
14611780

14621781
/*

0 commit comments

Comments
 (0)