0001 // 0002 // DispatchData.swift 0003 // DispatchKit <https://github.com/anpol/DispatchKit> 0004 // 0005 // Copyright (c) 2014 Andrei Polushin. All rights reserved. 0006 // 0007 0008 import Foundation 0009 0010 public struct DispatchData<T
DispatchData.swift:15 return DispatchData(rawValue: dispatch_data_empty)DispatchData.swift:14 public static var Empty: DispatchData {DispatchData.swift:94 return DispatchData(rawValue: rawValue)DispatchData.swift:98 public typealias Region = (data: DispatchData, offset: Int)DispatchData.swift:107 return (DispatchData(rawValue: region), Scale.fromBytes(offset))DispatchData.swift:113 public func createMap() -> (owner: DispatchData, buffer: Buffer)! {DispatchData.swift:121 return (DispatchData(rawValue: owner), (UnsafePointer<T>(buffer), Scale.fromBytes(size)))DispatchData.swift:130 applier(region: (DispatchData<T>(rawValue: region), Scale.fromBytes(offset)),DispatchData.swift:138 public func + <T>(a: DispatchData<T>, b: DispatchData<T>) -> DispatchData<T>! {DispatchData.swift:138 public func + <T>(a: DispatchData<T>, b: DispatchData<T>) -> DispatchData<T>! {DispatchData.swift:138 public func + <T>(a: DispatchData<T>, b: DispatchData<T>) -> DispatchData<T>! {DispatchData.swift:143 return DispatchData<T>(rawValue: rawValue)DispatchIO.swift:65 queue: DispatchQueue, handler: (DispatchData<T>!, Int) -> Void) {DispatchIO.swift:69 handler(DispatchData<T>(rawValue: data), Int(error))DispatchIO.swift:73 public static func write<T>(fd: dispatch_fd_t, data: DispatchData<T>,DispatchIO.swift:74 queue: DispatchQueue, handler: (DispatchData<T>!, Int) -> Void) {DispatchIO.swift:78 handler(DispatchData<T>(rawValue: data), Int(error))DispatchIO.swift:84 queue: DispatchQueue, handler: (Bool, DispatchData<T>!, Int) -> Void) {DispatchIO.swift:88 handler(done, DispatchData<T>(rawValue: data), Int(error))DispatchIO.swift:92 public func write<T>(offset: off_t = 0, data: DispatchData<T>,DispatchIO.swift:93 queue: DispatchQueue, handler: (Bool, DispatchData<T>!, Int) -> Void) {DispatchIO.swift:97 handler(done, DispatchData<T>(rawValue: data), Int(error)): IntegerType>: DispatchObject { 0011 0012 typealias Scale
DispatchData.swift:12 typealias Scale = DispatchDataScale<T>DispatchData.swift:39 public init!(_ array: [T]) {DispatchData.swift:58 public init!(_ buffer: UnsafeMutablePointer<T>, _ count: Int, _ queue: dispatch_queue_t! = nil) {DispatchData.swift:71 public init!(_ buffer: UnsafePointer<T>, _ count: Int,DispatchData.swift:111 public typealias Buffer = (start: UnsafePointer<T>, count: Int)DispatchData.swift:121 return (DispatchData(rawValue: owner), (UnsafePointer<T>(buffer), Scale.fromBytes(size)))DispatchData.swift:130 applier(region: (DispatchData<T>(rawValue: region), Scale.fromBytes(offset)),DispatchData.swift:131 buffer: (UnsafePointer<T>(buffer), Scale.fromBytes(size)))= DispatchDataScale<T> 0013 0014 public static var Empty: DispatchData { 0015 return DispatchData(rawValue: dispatch_data_empty) 0016 } 0017 0018 @available(*, unavailable, renamed="rawValue") 0019 public var data: dispatch_data_t { 0020 return rawValue 0021 } 0022 0023 @available(*, unavailable, renamed="DispatchData(rawValue:)") 0024 public init(raw data: dispatch_data_t) { 0025 self.rawValue = data 0026 } 0027 0028 public let rawValue
DispatchData.swift:40 let size = Scale.toBytes(array.count)DispatchData.swift:59 let size = Scale.toBytes(count)DispatchData.swift:74 let size = Scale.toBytes(count)DispatchData.swift:83 return Scale.fromBytes(dispatch_data_get_size(rawValue))DispatchData.swift:87 let offset = Scale.toBytes(range.startIndex)DispatchData.swift:88 let length = Scale.toBytes(range.endIndex - range.startIndex)DispatchData.swift:103 guard let region = dispatch_data_copy_region(rawValue, Scale.toBytes(location), &offset) else {DispatchData.swift:107 return (DispatchData(rawValue: region), Scale.fromBytes(offset))DispatchData.swift:121 return (DispatchData(rawValue: owner), (UnsafePointer<T>(buffer), Scale.fromBytes(size)))DispatchData.swift:130 applier(region: (DispatchData<T>(rawValue: region), Scale.fromBytes(offset)),DispatchData.swift:131 buffer: (UnsafePointer<T>(buffer), Scale.fromBytes(size))): dispatch_data_t 0029 0030 public init
DispatchData.swift:31 self.rawValue = rawValueDispatchData.swift:48 self.rawValue = rawValueDispatchData.swift:67 self.rawValue = rawValueDispatchData.swift:79 self.rawValue = rawValueDispatchData.swift:83 return Scale.fromBytes(dispatch_data_get_size(rawValue))DispatchData.swift:90 guard let rawValue = dispatch_data_create_subrange(rawValue, offset, length) else {DispatchData.swift:103 guard let region = dispatch_data_copy_region(rawValue, Scale.toBytes(location), &offset) else {DispatchData.swift:117 guard let owner = dispatch_data_create_map(rawValue, &buffer, &size) else {DispatchData.swift:128 return dispatch_data_apply(rawValue) {DispatchData.swift:139 guard let rawValue = dispatch_data_create_concat(a.rawValue, b.rawValue) else {DispatchData.swift:139 guard let rawValue = dispatch_data_create_concat(a.rawValue, b.rawValue) else {DispatchIO.swift:76 dispatch_write(fd, data.rawValue, queue.rawValue) {DispatchIO.swift:95 dispatch_io_write(rawValue, offset, data.rawValue, queue.rawValue) {(rawValue: dispatch_data_t) { 0031 self.rawValue = rawValue 0032 } 0033 0034 /** 0035 * Copies the array's data and manages it internally. 0036 * 0037 * - parameter array: The array to be copied. 0038 */ 0039 public init!(_ array: [T]) { 0040 let size = Scale.toBytes(array.count) 0041 0042 guard let rawValue = array.withUnsafeBufferPointer({ p in 0043 dispatch_data_create(p.baseAddress, size, nil, nil) 0044 }) else { 0045 return nil 0046 } 0047 0048 self.rawValue = rawValue 0049 } 0050 0051 /** 0052 * Consumes a buffer previosly allocated by `UnsafeMutablePointer.alloc`_. 0053 * 0054 * - parameter buffer: 0055 * - parameter count: 0056 * - parameter queue: A queue on which to call `UnsafeMutablePointer.dealloc`_ for the buffer. 0057 */ 0058 public init!(_ buffer: UnsafeMutablePointer<T>, _ count: Int, _ queue: dispatch_queue_t! = nil) { 0059 let size = Scale.toBytes(count) 0060 0061 guard let rawValue = dispatch_data_create(buffer, size, queue, { 0062 buffer.dealloc(count) 0063 }) else { 0064 return nil 0065 } 0066 0067 self.rawValue = rawValue 0068 } 0069 0070 // The destructor is responsible to free the buffer. 0071 public init!(_ buffer: UnsafePointer<T>, _ count: Int, 0072 _ queue: dispatch_queue_t!, destructor: dispatch_block_t!) { 0073 0074 let size = Scale.toBytes(count) 0075 guard let rawValue = dispatch_data_create(buffer, size, queue, destructor) else { 0076 return nil 0077 } 0078 0079 self.rawValue = rawValue 0080 } 0081 0082 public var count: Int { 0083 return Scale.fromBytes(dispatch_data_get_size(rawValue)) 0084 } 0085 0086 public subscript(range: Range<Int>) -> DispatchData! { 0087 let offset = Scale.toBytes(range.startIndex) 0088 let length = Scale.toBytes(range.endIndex - range.startIndex) 0089 0090 guard let rawValue = dispatch_data_create_subrange(rawValue, offset, length) else { 0091 return nil 0092 } 0093 0094 return DispatchData(rawValue: rawValue) 0095 } 0096 0097 0098 public typealias Region
DispatchData.swift:15 return DispatchData(rawValue: dispatch_data_empty)DispatchData.swift:94 return DispatchData(rawValue: rawValue)DispatchData.swift:107 return (DispatchData(rawValue: region), Scale.fromBytes(offset))DispatchData.swift:121 return (DispatchData(rawValue: owner), (UnsafePointer<T>(buffer), Scale.fromBytes(size)))= (data: DispatchData, offset: Int) 0099 0100 public func copyRegion(location: Int) -> Region! { 0101 var offset: Int = 0 0102 0103 guard let region = dispatch_data_copy_region(rawValue, Scale.toBytes(location), &offset) else { 0104 return nil 0105 } 0106 0107 return (DispatchData(rawValue: region), Scale.fromBytes(offset)) 0108 } 0109 0110 0111 public typealias Buffer
DispatchData.swift:100 public func copyRegion(location: Int) -> Region! {DispatchData.swift:125 public typealias Applier = (region: Region, buffer: Buffer) -> Bool= (start: UnsafePointer<T>, count: Int) 0112 0113 public func createMap() -> (owner: DispatchData, buffer: Buffer)! { 0114 var buffer: UnsafePointer<Void> = nil 0115 var size: Int = 0 0116 0117 guard let owner = dispatch_data_create_map(rawValue, &buffer, &size) else { 0118 return nil 0119 } 0120 0121 return (DispatchData(rawValue: owner), (UnsafePointer<T>(buffer), Scale.fromBytes(size))) 0122 } 0123 0124 0125 public typealias Applier
DispatchData.swift:113 public func createMap() -> (owner: DispatchData, buffer: Buffer)! {DispatchData.swift:125 public typealias Applier = (region: Region, buffer: Buffer) -> Bool= (region: Region, buffer: Buffer) -> Bool 0126 0127 public func apply(applier: Applier) -> Bool { 0128 return dispatch_data_apply(rawValue) { 0129 (region, offset, buffer, size) -> Bool in 0130 applier(region: (DispatchData<T>(rawValue: region), Scale.fromBytes(offset)), 0131 buffer: (UnsafePointer<T>(buffer), Scale.fromBytes(size))) 0132 } 0133 } 0134 0135 } 0136 0137 0138 public func + <T>(a: DispatchData<T>, b: DispatchData<T>) -> DispatchData<T>! { 0139 guard let rawValue = dispatch_data_create_concat(a.rawValue, b.rawValue) else { 0140 return nil 0141 } 0142 0143 return DispatchData<T>(rawValue: rawValue) 0144 } 0145
DispatchData.swift:127 public func apply(applier: Applier) -> Bool {