jsonapistruct.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /** @file */
  2. // -------------------------------------------------------------------------
  3. // object which allow to parse upon generic JSON structure and format it back
  4. //
  5. //
  6. class JsonApiStruct : Managed
  7. {
  8. void JsonApiStruct()
  9. {
  10. }
  11. void ~JsonApiStruct()
  12. {
  13. }
  14. /**
  15. \brief Event when expand (unpack) process starts
  16. */
  17. void OnExpand()
  18. {
  19. }
  20. /**
  21. \brief Event when pack starts - you will pack your stuff here
  22. */
  23. void OnPack()
  24. {
  25. Print( "OnPack() ");
  26. }
  27. /**
  28. \brief Verification event after successfull JSON packing
  29. */
  30. void OnBufferReady()
  31. {
  32. }
  33. /**
  34. \brief Event called when pending store operation is finished - callback from JsonApiHandle before handle release
  35. */
  36. void OnSuccess( int errorCode )
  37. {
  38. // errorCode is EJsonApiError
  39. }
  40. /**
  41. \brief Event called when pending store operation is finished - callback from JsonApiHandle before handle release
  42. */
  43. void OnError( int errorCode )
  44. {
  45. // errorCode is EJsonApiError
  46. }
  47. /**
  48. \brief Called when parsing object
  49. */
  50. void OnObject( string name )
  51. {
  52. Print( "OnObject: " + name );
  53. }
  54. /**
  55. \brief Called when parsing integer value
  56. */
  57. void OnInteger( string name, int value )
  58. {
  59. Print( "OnInteger: " + value );
  60. }
  61. /**
  62. \brief Called when parsing float value
  63. */
  64. void OnFloat( string name, float value )
  65. {
  66. Print( "OnFloat: " + value );
  67. }
  68. /**
  69. \brief Called when parsing boolean value
  70. */
  71. void OnBoolean( string name, bool value )
  72. {
  73. Print( "OnBoolean: " + value );
  74. }
  75. /**
  76. \brief Called when parsing string value
  77. */
  78. void OnString( string name, string value )
  79. {
  80. Print( "OnString: " + value );
  81. }
  82. /**
  83. \brief Called when parsing vector value
  84. */
  85. void OnVector( string name, vector value )
  86. {
  87. Print( "OnVector: " + value );
  88. }
  89. /**
  90. \brief Called when parsing array
  91. */
  92. void OnStartArray( string name )
  93. {
  94. Print( "OnStartArray: " + name );
  95. }
  96. /**
  97. \brief Called when array end, returns count of items
  98. */
  99. void OnEndArray( int itemCount )
  100. {
  101. Print( "OnEndArray: " + itemCount );
  102. }
  103. /**
  104. \brief Called when parsing object
  105. */
  106. void OnItemObject( int index, string name )
  107. {
  108. Print( "OnItemObject: " + name );
  109. }
  110. /**
  111. \brief Called when parsing integer value
  112. */
  113. void OnItemInteger( int index, int value )
  114. {
  115. Print( "OnItemInteger: " + value );
  116. }
  117. /**
  118. \brief Called when parsing float value
  119. */
  120. void OnItemFloat( int index, float value )
  121. {
  122. Print( "OnItemFloat: " + value );
  123. }
  124. /**
  125. \brief Called when parsing boolean value
  126. */
  127. void OnItemBoolean( int index, bool value )
  128. {
  129. Print( "OnItemBoolean: " + value );
  130. }
  131. /**
  132. \brief Called when parsing string value from array
  133. */
  134. void OnItemString( int index, string value )
  135. {
  136. Print( "OnItemString: " + value );
  137. }
  138. /**
  139. \brief Called when parsing vector value from array
  140. */
  141. void OnItemVector( int index, vector value )
  142. {
  143. Print( "OnItemVector: " + value );
  144. }
  145. /**
  146. \brief Register script variable for auto-feature
  147. */
  148. proto native void RegV( string name );
  149. /**
  150. \brief Push object to parse (only during parse operation)
  151. */
  152. proto native void Push( JsonApiStruct obj );
  153. /**
  154. \brief Start object at hierarchy - !!! Be cautious and doublecheck results when using this !!!
  155. */
  156. proto native void StartObject( string name );
  157. /**
  158. \brief End object at hierarchy - !!! Be cautious and doublecheck results when using this !!!
  159. */
  160. proto native void EndObject();
  161. /**
  162. \brief Add scripted object to hierarchy (calls through hierarchy)
  163. */
  164. proto native void StoreObject( string name, JsonApiStruct obj );
  165. /**
  166. \brief Add float value to hierarchy
  167. */
  168. proto native void StoreFloat( string name, float value );
  169. /**
  170. \brief Add integer value to hierarchy
  171. */
  172. proto native void StoreInteger( string name, int value );
  173. /**
  174. \brief Add boolean value to hierarchy
  175. */
  176. proto native void StoreBoolean( string name, bool value );
  177. /**
  178. \brief Add string value to hierarchy
  179. */
  180. proto native void StoreString( string name, string value );
  181. /**
  182. \brief Add vector value to hierarchy
  183. */
  184. proto native void StoreVector( string name, vector value );
  185. /**
  186. \brief Start array at hierarchy - !!! Be cautious and doublecheck results when using this !!!
  187. */
  188. proto native void StartArray( string name );
  189. /**
  190. \brief End array at hierarchy - !!! Be cautious and doublecheck results when using this !!!
  191. */
  192. proto native void EndArray();
  193. /**
  194. \brief Add scripted unnamed/ array object
  195. */
  196. proto native void ItemObject( JsonApiStruct obj );
  197. /**
  198. \brief Add unnamed/ array float value
  199. */
  200. proto native void ItemFloat( float value );
  201. /**
  202. \brief Add unnamed/ array integer value
  203. */
  204. proto native void ItemInteger( int value );
  205. /**
  206. \brief Add unnamed/ array boolean value
  207. */
  208. proto native void ItemBoolean( bool value );
  209. /**
  210. \brief Add unnamed/ array string value
  211. */
  212. proto native void ItemString( string value );
  213. /**
  214. \brief Add unnamed/ array vector value
  215. */
  216. proto native void ItemVector( vector value );
  217. /**
  218. \brief Call this when you've done packing or unpacking (interrupt operation)
  219. */
  220. proto native void SetDone();
  221. /**
  222. \brief Call this when you've done packing or unpacking + want to generate error - prevent to send invalid data etc.
  223. */
  224. proto native void SetFail();
  225. /**
  226. \brief Start object packing - when it can be done (when sending remote etc.)
  227. */
  228. proto native void Pack();
  229. /**
  230. \brief Start object packing now - for use at main thread only!
  231. */
  232. proto native void InstantPack();
  233. /**
  234. \brief Start object unpacking from RAW string data
  235. */
  236. proto native void ExpandFromRAW( string data );
  237. /**
  238. \brief Get packed JSON as string (!only if you called Pack() first, it may return null)
  239. */
  240. proto native string AsString();
  241. /**
  242. \brief Pack() and save JSON to file
  243. */
  244. proto native bool PackToFile( string FileName );
  245. /**
  246. \brief Save JSON to file (only If something was loaded or recieved previously!)
  247. */
  248. proto native bool SaveToFile( string FileName );
  249. /**
  250. \brief Load JSON from file and Expand
  251. */
  252. proto native bool LoadFromFile( string FileName );
  253. };