Kaynağa Gözat

Added support for more primitive types.

Brucey 2 yıl önce
ebeveyn
işleme
350e6b6594

+ 18 - 4
persistencexml.mod/persistencexml.bmx

@@ -183,7 +183,7 @@ Type TPersist
 		Local elementType:TTypeId = typeId.ElementType()
 		
 		Select elementType
-			Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId
+			Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId, UIntTypeId, ULongTypeId, LongIntTypeId, ULongIntTypeId
 
 				Local sb:TStringBuilder = new TStringBuilder()
 				
@@ -283,6 +283,12 @@ Type TPersist
 			Case ULongTypeId
 				t = "ulong"
 				fieldNode.setContent(f.GetULong(obj))
+			Case LongIntTypeId
+				t = "longint"
+				fieldNode.setContent(f.GetLongInt(obj))
+			Case ULongIntTypeId
+				t = "ulongint"
+				fieldNode.setContent(f.GetULongInt(obj))
 			Default
 				t = fieldType.Name()
 
@@ -550,6 +556,14 @@ Type TPersist
 							fieldObj.SetFloat(obj, fieldNode.GetContent().toFloat())
 						Case "double"
 							fieldObj.SetDouble(obj, fieldNode.GetContent().toDouble())
+						Case "uint"
+							fieldObj.SetUInt(obj, fieldNode.GetContent().toUInt())
+						Case "ulong"
+							fieldObj.SetULong(obj, fieldNode.GetContent().toULong())
+						Case "longint"
+							fieldObj.SetLongInt(obj, LongInt(fieldNode.GetContent().toLongInt())) ' FIXME : why do we need to cast here?
+						Case "ulongint"
+							fieldObj.SetULongInt(obj, fieldNode.GetContent().toULongInt())
 						Default
 							If fieldType.StartsWith("array:") Then
 
@@ -570,7 +584,7 @@ Type TPersist
 									
 									' for file Version 1+
 									Select arrayElementType
-										Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId
+										Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId, UIntTypeId, ULongTypeId, LongIntTypeId, ULongIntTypeId
 										
 											Local arrayList:String[]
 											Local content:String = fieldNode.GetContent().Trim()
@@ -633,7 +647,7 @@ Type TPersist
 										For Local arrayNode:TxmlNode = EachIn arrayList
 		
 											Select arrayElementType
-												Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId, StringTypeId
+												Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId, StringTypeId, UIntTypeId, ULongTypeId, LongIntTypeId, ULongIntTypeId
 													arrayType.SetArrayElement(arrayObj, i, arrayNode.GetContent())
 												Default
 													arrayType.SetArrayElement(arrayObj, i, DeSerializeObject("", arrayNode))
@@ -723,7 +737,7 @@ Type TPersist
 					Local arrayElementType:TTypeId = objType.ElementType()
 	
 					Select arrayElementType
-						Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId
+						Case ByteTypeId, ShortTypeId, IntTypeId, LongTypeId, FloatTypeId, DoubleTypeId, UIntTypeId, ULongTypeId, LongIntTypeId, ULongIntTypeId
 						
 							Local arrayList:String[] = node.GetContent().Split(" ")
 							

+ 9 - 3
persistencexml.mod/test/fields.bmx

@@ -13,6 +13,10 @@ Type FieldsTest Extends TTest
 	Const NUM_DOUBLE:Double = 9420.0394:Double
 	Const NUM_BYTE:Byte = 129
 	Const NUM_SHORT:Short = 40000
+	Const NUM_UINT:UInt = 123456
+	Const NUM_ULONG:ULong = 4473709551615:ULong
+	Const NUM_LONGINT:LongInt = 998800
+	Const NUM_ULONGINT:ULongInt = 560000
 	
 	Const STR_ONE:String = "ABCDEFG"
 	Const STR_TWO:String = "HIJKLMNOP"
@@ -41,8 +45,7 @@ Type FieldsTest Extends TTest
 	End Method
 
 	Method testNumbers() { test }
-
-		Local numbers:TNumbers = New TNumbers.Create(NUM_INT, NUM_LONG, NUM_FLOAT, NUM_DOUBLE, NUM_BYTE, NUM_SHORT)
+		Local numbers:TNumbers = New TNumbers.Create(NUM_INT, NUM_LONG, NUM_FLOAT, NUM_DOUBLE, NUM_BYTE, NUM_SHORT, NUM_UINT, NUM_ULONG, NUM_LONGINT, NUM_ULONGINT)
 		
 		Local s:String = persist.SerializeToString(numbers)
 
@@ -56,7 +59,10 @@ Type FieldsTest Extends TTest
 		assertEquals(NUM_DOUBLE, result.d)
 		assertEquals(NUM_BYTE, result.e)
 		assertEquals(NUM_SHORT, result.f)
-	
+		assertEquals(NUM_UINT, result.g)
+		assertEquals(NUM_ULONG, result.h)
+		assertEquals(NUM_LONGINT, result.i)
+		assertEquals(NUM_ULONGINT, result.j)
 	End Method
 	
 	Method testStrings() { test }

+ 9 - 1
persistencexml.mod/test/types.bmx

@@ -9,14 +9,22 @@ Type TNumbers
 	Field d:Double
 	Field e:Byte
 	Field f:Short
+	Field g:UInt
+	Field h:ULong
+	Field i:LongInt
+	Field j:ULongInt
 	
-	Method Create:TNumbers(a:Int, b:Long, c:Float, d:Double, e:Byte, f:Short)
+	Method Create:TNumbers(a:Int, b:Long, c:Float, d:Double, e:Byte, f:Short, g:UInt, h:ULong, i:LongInt, j:ULongInt)
 		Self.a = a
 		Self.b = b
 		Self.c = c
 		Self.d = d
 		Self.e = e
 		Self.f = f
+		Self.g = g
+		Self.h = h
+		Self.i = i
+		Self.j = j
 		Return Self
 	End Method