-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCIGenericWrapper.swift
262 lines (229 loc) · 8.25 KB
/
SCIGenericWrapper.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2018. All rights reserved.
//
// Web: http://www.scichart.com
// Support: [email protected]
// Sales: [email protected]
//
// SCIGenericWrapper.swift is part of SCICHART®, High Performance Scientific Charts
// For full terms and conditions of the license, see http://www.scichart.com/scichart-eula/
//
// This source code is protected by international copyright law. Unauthorized
// reproduction, reverse-engineering, or distribution of all or any portion of
// this source code is strictly prohibited.
//
// This source code contains confidential and proprietary trade secrets of
// SciChart Ltd., and should at no time be copied, transferred, sold,
// distributed or made available without express written permission.
//******************************************************************************
/** \addtogroup SCIGenericType
* @{
*/
import Foundation
import SciChart
/**
@file SCIGenericType
*/
#if swift(>=3.0)
/**
* @brief It is wrapper function that constructs SCIGenericType
* @code
* let generic1 = SCIGeneric(0)
* let variable = 1
* let generic2 = SCIGeneric( variable )
* let generic3 = SCIGeneric( NSDate() )
* let doubleVariable = SCIGenericDouble(generic1)
* let intVariable = SCIGenericInt(generic2)
* let floatVariable = SCIGenericFloat(generic2)
* let date = SCIGenericDate(generic3)
* let timeIntervalSince1970 = SCIGenericDouble(generic3)
* @endcode
* @see SCIGenericType
*/
public protocol SCIGenericInfo {
func getInfoType() -> SCIDataType
}
extension Int16 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int16
}
}
extension Int32 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int32
}
}
extension Int : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int32
}
}
extension Int64 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int64
}
}
extension UInt : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int32
}
}
extension UInt8 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.byte
}
}
extension UInt16 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int16
}
}
extension UInt64 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int64
}
}
extension UInt32 : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.int32
}
}
extension Double : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.double
}
}
extension Float : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.float
}
}
extension Character : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.byte
}
}
extension CChar : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.byte
}
}
extension NSArray : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.array
}
}
extension NSDate : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.dateTime
}
}
extension Date : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.swiftDateTime
}
}
extension UnsafeMutablePointer : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
if let pointerType = pointee as? SCIGenericInfo {
switch pointerType.getInfoType() {
case .int16:
return SCIDataType.int16Ptr
case .int32:
return SCIDataType.int32Ptr
case .int64:
return SCIDataType.int64Ptr
case .byte:
return SCIDataType.charPtr
case .float:
return SCIDataType.floatPtr
case .double:
return SCIDataType.doublePtr
default:
return SCIDataType.voidPtr
}
}
return SCIDataType.voidPtr
}
}
extension UnsafeMutableRawPointer : SCIGenericInfo {
public func getInfoType() -> SCIDataType {
return SCIDataType.voidPtr
}
}
public func SCIGeneric<T: SCIGenericInfo>(_ x: T) -> SCIGenericType {
var data = x
var typeData = data.getInfoType()
if typeData == .swiftDateTime {
if let date = x as? Date {
let timeInterval = date.timeIntervalSince1970
var nsDate = NSDate.init(timeIntervalSince1970: timeInterval)
typeData = .dateTime
return SCI_constructGenericTypeWithInfo(&nsDate, typeData)
}
}
return SCI_constructGenericTypeWithInfo(&data, typeData)
}
public func SCIGeneric<T:SCIGenericInfo>(_ x: [T]) -> SCIGenericType {
let data = x
let unsafePointer = UnsafeMutablePointer(mutating: data)
return SCIGeneric(unsafePointer)
}
#else
/**
@brief It is wrapper function that constructs SCIGenericType
@code
let generic1 = SCIGeneric(0)
let variable = 1
let generic2 = SCIGeneric( variable )
let generic3 = SCIGeneric( NSDate() )
let doubleVariable = SCIGenericDouble(generic1)
let intVariable = SCIGenericInt(generic2)
let floatVariable = SCIGenericFloat(generic2)
let date = SCIGenericDate(generic3)
let timeIntervalSince1970 = SCIGenericDouble(generic3)
@endcode
@see SCIGenericType
*/
public func SCIGeneric<T>(x: T) -> SCIGenericType {
var data = x
if x is Double {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Double)
} else if x is Float {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Float)
} else if x is Int32 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int32)
} else if x is Int16 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int16)
} else if x is Int64 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int64)
} else if x is Int8 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Byte)
} else if x is NSDate {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.DateTime)
} else if x is NSArray {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Array)
} else if x is Int {
// TODO: implement correct unsigned type handling
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int32)
} else if x is UInt32 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int32)
} else if x is UInt16 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int16)
} else if x is UInt64 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int64)
} else if x is UInt8 {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Byte)
} else if x is UInt {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.Int32)
} else {
return SCI_constructGenericTypeWithInfo(&data, SCIDataType.None)
}
}
public func SCIGeneric<T:SCIGenericInfo>(_ x: [T]) -> SCIGenericType {
let data = x
let unsafePointer = UnsafeMutablePointer(mutating: data)
return SCIGeneric(unsafePointer)
}
#endif
/** @} */