This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
/
datatypes.bmx
279 lines (251 loc) · 7.55 KB
/
datatypes.bmx
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
Rem
Copyright (c) 2010 Christiaan Kras
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
End Rem
Rem
bbdoc: XML-RPC Data Type exception
End Rem
Type TXMLRPC_Value_Exception Extends TXMLRPC_Exception
End Type
Rem
bbdoc: Base type for all XML-RPC data types
End Rem
Type TXMLRPC_Value_Abstract Abstract
Field _type:Int
Rem
bbdoc: The name or id this value has been identified with in the response. read-only
End Rem
Field name:String
Rem
bbdoc: Convert a XMLRPC_VALUE from XMLRPC-EPI to a BlitzMax type
End Rem
Function XMLRPC_To_BlizMax:TXMLRPC_Value_Abstract(val:Byte Ptr) Final
Local dataType:Int = XMLRPC_GetValueType(val)
Local data:TXMLRPC_Value_Abstract
Select dataType
Case xmlrpc_none
data = New TXMLRPC_Value_None
Case xmlrpc_empty
data = New TXMLRPC_Value_Empty
Case xmlrpc_base64
data = New TXMLRPC_Value_Base64
Local cStr:Byte Ptr = XMLRPC_GetValueBase64(val)
If cStr
TXMLRPC_Value_Base64(data).value = String.FromCString(cStr)
XMLRPC_Free(cStr)
End If
Case xmlrpc_boolean
data = New TXMLRPC_Value_Boolean
TXMLRPC_Value_Boolean(data).value = XMLRPC_GetValueBoolean(val)
Case xmlrpc_datetime
data = New TXMLRPC_Value_Datetime
Local cStr:Byte Ptr = XMLRPC_GetValueDateTime_ISO8601(val)
If cStr
TXMLRPC_Value_Datetime(data).value = String.FromCString(cStr)
XMLRPC_Free(cStr)
End If
Case xmlrpc_double
data = New TXMLRPC_Value_Double
TXMLRPC_Value_Double(data).value = XMLRPC_GetValueDouble(val)
Case xmlrpc_int
data = New TXMLRPC_Value_Int
TXMLRPC_Value_Int(data).value = XMLRPC_GetValueInt(val)
Case xmlrpc_string
data = New TXMLRPC_Value_String
Local cStr:Byte Ptr = XMLRPC_GetValueString(val)
If cStr
TXMLRPC_Value_String(data).value = String.FromCString(cStr)
XMLRPC_Free(cStr)
End If
Case xmlrpc_vector
Local vectorType:Int = XMLRPC_GetVectorType(val)
Select vectorType
Case xmlrpc_vector_array
data = New TXMLRPC_Value_Array
Case xmlrpc_vector_struct
data = New TXMLRPC_Value_Struct
Case xmlrpc_vector_mixed
Throw New TXMLRPC_Value_Exception.Create("Not sure yet how to handle a xmlrpc_vector_mixed value")
Case xmlrpc_vector_none
Throw New TXMLRPC_Value_Exception.Create("Not sure yet how to handle a xmlrpc_vector_none value")
Default
Throw New TXMLRPC_Value_Exception.Create("Unknown vector type: " + vectorType)
End Select
If TXMLRPC_Value_Collection(data)
TXMLRPC_Value_Collection(data).SetData(val)
End If
Default
Throw New TXMLRPC_Value_Exception.Create("I don't know a XMLRPC_VALUE with number " + dataType)
End Select
If data
data._type = dataType
Local cStr:Byte Ptr = XMLRPC_GetValueID(val)
If cStr
data.name = String.FromCString(cStr)
XMLRPC_Free(cStr)
End If
End If
Return data
End Function
Rem
bbdoc: Convert data type to string
about: Uses reflection to see if a Field called value is available. If so, it tries to convert it to a string and returns it
End Rem
Method ToString:String()
Local r:TTypeId = TTypeId.ForObject(Self)
For Local fld:TField = EachIn r.EnumFields()
'Check if object has a Field called value
'If so, check it's type, convert it to a string and return it
If fld.Name() = "value"
Select fld.TypeId().Name()
Case "String"
Return fld.GetString(Self)
Case "Int"
Return String(fld.GetInt(Self))
Case "Byte"
Return String(fld.GetInt(Self))
Case "Long"
Return String(fld.GetLong(Self))
Case "Double"
Return String(fld.GetDouble(Self))
End Select
End If
Next
Return ""
' Throw New TXMLRPC_Value_Exception.Create("Can't convert datatype to string")
End Method
Rem
bbdoc: Return byte value
End Rem
Method GetByte:Byte()
Throw New TXMLRPC_Value_Exception.Create("Method GetByte not implemented for this type")
End Method
Rem
bbdoc: Return integer value
End Rem
Method GetInt:Int()
Throw New TXMLRPC_Value_Exception.Create("Method GetInt not implemented for this type")
End Method
Rem
bbdoc: Return double value
End Rem
Method GetDouble:Double()
Throw New TXMLRPC_Value_Exception.Create("Method GetDouble not implemented for this type")
End Method
Rem
bbdoc: Return string value
End Rem
Method GetString:String()
Throw New TXMLRPC_Value_Exception.Create("Method GetString not implemented for this type")
End Method
End Type
Rem
bbdoc: Represents none value
End Rem
Type TXMLRPC_Value_None Extends TXMLRPC_Value_Abstract
End Type
Rem
bbdoc: Represents an empty value
End Rem
Type TXMLRPC_Value_Empty Extends TXMLRPC_Value_Abstract
Field value:Object = Null
End Type
Rem
bbdoc: Represents a Base64 encoded string
End Rem
Type TXMLRPC_Value_Base64 Extends TXMLRPC_Value_Abstract
Field value:String
Method GetString:String()
Return Self.value
End Method
End Type
Rem
bbdoc: Represents a boolean value
End Rem
Type TXMLRPC_Value_Boolean Extends TXMLRPC_Value_Abstract
Field value:Byte
Method GetByte:Byte()
Return Self.value
End Method
End Type
Rem
bbdoc: Represents a datetime string
End Rem
Type TXMLRPC_Value_Datetime Extends TXMLRPC_Value_Abstract
Field value:String
Method GetString:String()
Return Self.value
End Method
End Type
Rem
bbdoc: Represents a double value
End Rem
Type TXMLRPC_Value_Double Extends TXMLRPC_Value_Abstract
Field value:Double
Method GetDouble:Double()
Return Self.value
End Method
End Type
Rem
bbdoc: Represents a integer value
End Rem
Type TXMLRPC_Value_Int Extends TXMLRPC_Value_Abstract
Field value:Int
Method GetInt:Int()
Return Self.value
End Method
End Type
Rem
bbdoc: Represents a string value
End Rem
Type TXMLRPC_Value_String Extends TXMLRPC_Value_Abstract
Field value:String
Method GetString:String()
Return Self.value
End Method
End Type
Rem
bbdoc: Represents a collection. This is a base type
End Rem
Type TXMLRPC_Value_Collection Extends TXMLRPC_Value_Abstract Abstract
Field data:TMap
Method SetData(el:Byte Ptr) Abstract
End Type
Rem
bbdoc: Represents an array
End Rem
Type TXMLRPC_Value_Array Extends TXMLRPC_Value_Collection
Method SetData(el:Byte Ptr)
Self.data = New TMap
If XMLRPC_VectorSize(el) > 0
Local map:TMap = TXMLRPC_Response_Data.IterateVector(el)
Local counter:Int = 0
For Local val:TXMLRPC_Value_Abstract = EachIn map.Values()
Self.data.Insert(String.FromInt(counter), val)
counter:+1
Next
End If
End Method
End Type
Rem
bbdoc: Represents an associative array
End Rem
Type TXMLRPC_Value_Struct Extends TXMLRPC_Value_Collection
Method SetData(el:Byte Ptr)
Self.data = TXMLRPC_Response_Data.IterateVector(el)
End Method
End Type