ArkFoundation.swift 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. public struct URL: Equatable, Hashable {
  2. public var absoluteString: String
  3. public var path: String { absoluteString }
  4. public init?(string: String) {
  5. self.absoluteString = string
  6. }
  7. public init(fileURLWithPath path: String) {
  8. self.absoluteString = path
  9. }
  10. }
  11. public struct UUID: Equatable, Hashable {
  12. public let uuidString: String
  13. public init() {
  14. self.uuidString = "ark-uuid-mock" // Dummy for now
  15. }
  16. public init?(uuidString: String) {
  17. self.uuidString = uuidString
  18. }
  19. }
  20. public struct Date: Comparable, Hashable {
  21. public var timeIntervalSinceReferenceDate: Double
  22. public init() {
  23. self.timeIntervalSinceReferenceDate = 0 // Mock
  24. }
  25. public init(timeIntervalSinceReferenceDate: Double) {
  26. self.timeIntervalSinceReferenceDate = timeIntervalSinceReferenceDate
  27. }
  28. public static let distantPast = Date(timeIntervalSinceReferenceDate: -63114076800.0) // Year 0001
  29. public static let distantFuture = Date(timeIntervalSinceReferenceDate: 63113904000.0) // Year 4000
  30. public static func < (lhs: Date, rhs: Date) -> Bool {
  31. return lhs.timeIntervalSinceReferenceDate < rhs.timeIntervalSinceReferenceDate
  32. }
  33. }
  34. public struct Data: Equatable, Hashable, Codable {
  35. public var bytes: [UInt8]
  36. public var count: Int { bytes.count }
  37. public init() {
  38. self.bytes = []
  39. }
  40. public init(_ bytes: [UInt8]) {
  41. self.bytes = bytes
  42. }
  43. public mutating func append(_ newElements: [UInt8]) {
  44. bytes.append(contentsOf: newElements)
  45. }
  46. }
  47. public class JSONEncoder {
  48. public init() {}
  49. public func encode<T>(_ value: T) throws -> Data {
  50. return Data() // Dummy
  51. }
  52. }
  53. public class JSONDecoder {
  54. public init() {}
  55. public func decode<T>(_ type: T.Type, from data: Data) throws -> T {
  56. fatalError("Decoding not supported on baremetal")
  57. }
  58. }
  59. public class FileManager {
  60. public static let `default` = FileManager()
  61. public func fileExists(atPath path: String) -> Bool {
  62. return false // Dummy
  63. }
  64. }
  65. // MARK: - Dispatch & Foundation Utilities Mocks
  66. public typealias TimeInterval = Double
  67. public class DispatchQueue {
  68. public init(label: String) {}
  69. public func async(execute work: @escaping () -> Void) {
  70. // Execute inline for baremetal mock
  71. work()
  72. }
  73. }
  74. public class DispatchSemaphore {
  75. public init(value: Int) {}
  76. public enum WaitResult {
  77. case success
  78. case timedOut
  79. }
  80. public func wait(timeout: DispatchTime) -> WaitResult {
  81. return .success
  82. }
  83. public func wait() {
  84. _ = wait(timeout: DispatchTime.now())
  85. }
  86. public func signal() {}
  87. }
  88. public struct DispatchTime {
  89. public var uptimeNanoseconds: UInt64 = 0
  90. public static func now() -> DispatchTime {
  91. return DispatchTime()
  92. }
  93. }
  94. public class ProcessInfo {
  95. public static let processInfo = ProcessInfo()
  96. public var systemUptime: TimeInterval {
  97. // Return dummy time based on a counter
  98. return 0.0
  99. }
  100. public var processName: String {
  101. return "ArkApp"
  102. }
  103. }
  104. public class Thread {
  105. public static func sleep(forTimeInterval ti: TimeInterval) {
  106. // Do nothing in mock
  107. }
  108. }
  109. public class Mutex<T> {
  110. private var value: T
  111. public init(_ value: T) {
  112. self.value = value
  113. }
  114. public func withLock<R>(_ body: (inout T) throws -> R) rethrows -> R {
  115. return try body(&value)
  116. }
  117. }
  118. public struct Calendar: Equatable {
  119. public static let current = Calendar()
  120. }
  121. public struct TimeZone: Equatable {
  122. public static let current = TimeZone()
  123. }
  124. public struct Locale: Equatable {
  125. public static let current = Locale()
  126. }
  127. public class UserDefaults {
  128. public static let standard = UserDefaults()
  129. private var storage = [String: String]()
  130. public func set(_ value: String?, forKey key: String) {
  131. storage[key] = value
  132. }
  133. public func string(forKey key: String) -> String? {
  134. return storage[key]
  135. }
  136. public func synchronize() {}
  137. }
  138. public func sin(_ x: Double) -> Double {
  139. return 0.0 // Stub for baremetal
  140. }
  141. public func cos(_ x: Double) -> Double {
  142. return 1.0 // Stub for baremetal
  143. }
  144. public func atan2(_ y: Double, _ x: Double) -> Double {
  145. return 0.0 // Stub for baremetal
  146. }