example_02.bmx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. SuperStrict
  2. Framework Text.PersistenceXml
  3. Import BRL.StandardIO
  4. Type TRect
  5. Field x:Int
  6. Field y:Int
  7. Field w:Int
  8. Field h:Int
  9. Field ignoreMe:String = "Hello" {nopersist}
  10. End Type
  11. Type TObj
  12. Field text:String
  13. Field numbersi:Int[]
  14. Field numbersf:Float[]
  15. Field numbersd:Double[]
  16. Field numbersl:Long[]
  17. Field multi:String[,,]
  18. Field circularRef:TTest
  19. Field refNull:TTest
  20. Field emptyList:TList = New TList
  21. Field list:TList = New TList
  22. Field rect:TRect = New TRect
  23. Function Set:TObj()
  24. Local this:TObj = New TObj
  25. this.text = "woot"
  26. this.numbersi = [ 1, 2, 3, 4, 5, 6 ]
  27. this.numbersf = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]
  28. this.numbersd = [ 1.0:Double, 2.0:Double, 3.0:Double, 4.0:Double, 5.0:Double, 6.0:Double ]
  29. this.numbersl = [ 1:Long, 2:Long, 3:Long, 4:Long, 5:Long, 6:Long ]
  30. this.multi = New String[3,4,5]
  31. this.multi[0,0,0] = 22
  32. this.multi[1,2,2] = "<sd>"
  33. this.multi[2,3,4] = 44
  34. this.list.AddLast("Item 1")
  35. this.rect.x = 100
  36. this.rect.y = 200
  37. this.rect.w = 300
  38. this.rect.h = 400
  39. Return this
  40. End Function
  41. End Type
  42. Type TTest
  43. Field one:String
  44. Field two:Int
  45. Field three:Float
  46. Field four:Double
  47. Field five:Long
  48. Field obj:TObj
  49. Field rects:TRect[]
  50. Field list:TList
  51. Function Set:TTest()
  52. Local this:TTest = New TTest
  53. this.one = "Hello World"
  54. this.two = 155
  55. this.three = 3.33
  56. this.four = 2.95
  57. this.five = 222
  58. this.obj = TObj.Set()
  59. this.obj.circularRef = this
  60. this.rects = New TRect[2]
  61. 'rects[0] = New TRect ' <- null!
  62. this.rects[1] = New TRect
  63. this.rects[1].y = 125
  64. this.list = New TList
  65. ' make lots of objects
  66. For Local i:Int = 0 Until 1500
  67. this.list.AddLast(TObj.Set())
  68. Next
  69. Return this
  70. End Function
  71. End Type
  72. Local test:TTest = TTest.Set()
  73. Local obj:Object
  74. Local persist:TPersist = New TXMLPersistenceBuilder.Build()
  75. ' compress the data
  76. TPersist.compressed = True
  77. ' ++ Compression only works with "files"
  78. persist.SerializeToFile(test, "example2.bmo")
  79. persist.Free()
  80. Print "Saved..."
  81. ' ++ De-serialize from a file.
  82. obj = persist.DeSerializeFromFile("example2.bmo")