SimXMLDocument_ScriptBinding.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(SimXMLDocument, SimObject)
  23. /*! Set this to default state at construction.
  24. @return No return value
  25. */
  26. ConsoleMethodWithDocs(SimXMLDocument, reset, ConsoleVoid, 2, 2, ())
  27. {
  28. object->reset();
  29. }
  30. /*! Load file from given filename.
  31. @param fileName The name of the desired file
  32. @return Returns 1 on success and 0 otherwise
  33. */
  34. ConsoleMethodWithDocs(SimXMLDocument, loadFile, ConsoleInt, 3, 3, (string fileName))
  35. {
  36. return object->loadFile( argv[2] );
  37. }
  38. /*! Save file to given filename.
  39. @param fileName A string presenting the filename to save the XML document as
  40. @return Returns 1 on success, and 0 otherwise
  41. */
  42. ConsoleMethodWithDocs(SimXMLDocument, saveFile, ConsoleInt, 3, 3, (string fileName))
  43. {
  44. return object->saveFile( argv[2] );
  45. }
  46. /*! Create document from XML string.
  47. @param txtXML The text of the XML document
  48. @return Returns 1 on success
  49. */
  50. ConsoleMethodWithDocs(SimXMLDocument, parse, ConsoleInt, 3, 3, (string txtXML))
  51. {
  52. return object->parse( argv[2] );
  53. }
  54. /*! Clear contents of XML document.
  55. @return No return value
  56. */
  57. ConsoleMethodWithDocs(SimXMLDocument, clear, ConsoleVoid, 2, 2, ())
  58. {
  59. object->clear();
  60. }
  61. /*! Get current error description.
  62. @return Returns a string with the error description
  63. */
  64. ConsoleMethodWithDocs(SimXMLDocument, getErrorDesc, ConsoleString, 2, 2, ())
  65. {
  66. // Create Returnable Buffer (duration of error description is unknown).
  67. char* pBuffer = Con::getReturnBuffer(256);
  68. // Format Buffer.
  69. dSprintf(pBuffer, 256, "%s", object->getErrorDesc());
  70. // Return Velocity.
  71. return pBuffer;
  72. }
  73. /*! Clear error description.
  74. @return No return value
  75. */
  76. ConsoleMethodWithDocs(SimXMLDocument, clearError, ConsoleVoid, 2, 2, ())
  77. {
  78. object->clearError();
  79. }
  80. /*! Push first child element with given name onto stack.
  81. @param name The name of the child element
  82. @return returns true on success, false otherwise.
  83. */
  84. ConsoleMethodWithDocs(SimXMLDocument, pushFirstChildElement, ConsoleBool, 3, 3, (string name))
  85. {
  86. return object->pushFirstChildElement( argv[2] );
  87. }
  88. /*! Push the child element at the given index onto stack.
  89. @param index A nonnegative integer representing the index of the child element
  90. @return Returns true on success, and false otherwise
  91. */
  92. ConsoleMethodWithDocs(SimXMLDocument, pushChildElement, ConsoleBool, 3, 3, (int index))
  93. {
  94. return object->pushChildElement( dAtoi( argv[2] ) );
  95. }
  96. /*! Set top element on stack to next element with given name.
  97. @param name The name of the element.
  98. @return Returns true on success, false otherwise
  99. */
  100. ConsoleMethodWithDocs(SimXMLDocument, nextSiblingElement, ConsoleBool, 3, 3, (string name))
  101. {
  102. return object->nextSiblingElement( argv[2] );
  103. }
  104. /*! Get element value if it exists.
  105. @return A string with the desired value, or empty if not found.
  106. */
  107. ConsoleMethodWithDocs(SimXMLDocument, elementValue, ConsoleString, 2, 2, ())
  108. {
  109. // Create Returnable Buffer (because duration of value is unknown).
  110. char* pBuffer = Con::getReturnBuffer(256);
  111. dSprintf(pBuffer, 256, "%s", object->elementValue());
  112. return pBuffer;
  113. }
  114. /*! Pop last element off of stack.
  115. @return No return value
  116. */
  117. ConsoleMethodWithDocs(SimXMLDocument, popElement, ConsoleVoid, 2, 2, ())
  118. {
  119. object->popElement();
  120. }
  121. /*! Get attribute value if it exists.
  122. @param attribute The desired SimXMLDocument attribute
  123. @return Returns the value of the attribute as a string, or an empty string on failure
  124. */
  125. ConsoleMethodWithDocs(SimXMLDocument, attribute, ConsoleString, 3, 3, (string attribute))
  126. {
  127. // Create Returnable Buffer (because duration of attribute is unknown).
  128. char* pBuffer = Con::getReturnBuffer(256);
  129. // Format Buffer.
  130. dSprintf(pBuffer, 256, "%s", object->attribute( argv[2] ));
  131. // Return Velocity.
  132. return pBuffer;
  133. }
  134. /*! Get attribute value if it exists.
  135. @param attribute The desired SimXMLDocument attribute
  136. @return Returns the value of the attribute converted to 32-bit floating-point value from string
  137. */
  138. ConsoleMethodWithDocs(SimXMLDocument, attributeF32, ConsoleFloat, 3, 3, (string attribute))
  139. {
  140. return dAtof( object->attribute( argv[2] ) );
  141. }
  142. /*! Get attribute value if it exists.
  143. @param attribute The desired SimXMLDocument attribute
  144. @return Returns the value of the attribute converted to 32-bit integer value from string
  145. */
  146. ConsoleMethodWithDocs(SimXMLDocument, attributeS32, ConsoleInt, 3, 3, (string attribute))
  147. {
  148. return dAtoi( object->attribute( argv[2] ) );
  149. }
  150. /*! Get true if named attribute exists.
  151. @param attribute The desired attribute's name
  152. @return Returns true if attribute exists and false otherwise
  153. */
  154. ConsoleMethodWithDocs(SimXMLDocument, attributeExists, ConsoleBool, 3, 3, (string attribute))
  155. {
  156. return object->attributeExists( argv[2] );
  157. }
  158. /*! Obtain the name of the current element's first attribute.
  159. @return A string with the name of the first attribute
  160. */
  161. ConsoleMethodWithDocs(SimXMLDocument, firstAttribute, ConsoleString, 2, 2, ())
  162. {
  163. const char* name = object->firstAttribute();
  164. // Create Returnable Buffer (because duration of attribute is unknown).
  165. char* pBuffer = Con::getReturnBuffer(dStrlen(name)+1);
  166. dStrcpy(pBuffer, name);
  167. return pBuffer;
  168. }
  169. /*! Obtain the name of the current element's last attribute.
  170. @return A string with the name of the last attribute
  171. */
  172. ConsoleMethodWithDocs(SimXMLDocument, lastAttribute, ConsoleString, 2, 2, ())
  173. {
  174. const char* name = object->lastAttribute();
  175. // Create Returnable Buffer (because duration of attribute is unknown).
  176. char* pBuffer = Con::getReturnBuffer(dStrlen(name)+1);
  177. dStrcpy(pBuffer, name);
  178. return pBuffer;
  179. }
  180. /*! Get the name of the next attribute for the current element after a call to firstAttribute().
  181. @return A string with the name of the next attribute
  182. */
  183. ConsoleMethodWithDocs(SimXMLDocument, nextAttribute, ConsoleString, 2, 2, ())
  184. {
  185. const char* name = object->nextAttribute();
  186. // Create Returnable Buffer (because duration of attribute is unknown).
  187. char* pBuffer = Con::getReturnBuffer(dStrlen(name)+1);
  188. dStrcpy(pBuffer, name);
  189. return pBuffer;
  190. }
  191. /*! Get the name of the previous attribute for the current element after a call to lastAttribute().
  192. @return A string with the name of the previous attribute
  193. */
  194. ConsoleMethodWithDocs(SimXMLDocument, prevAttribute, ConsoleString, 2, 2, ())
  195. {
  196. const char* name = object->prevAttribute();
  197. // Create Returnable Buffer (because duration of attribute is unknown).
  198. char* pBuffer = Con::getReturnBuffer(dStrlen(name)+1);
  199. dStrcpy(pBuffer, name);
  200. return pBuffer;
  201. }
  202. /*! Set attribute of top stack element to given value.
  203. @param attributeName The name of the attribute of the element you wish to set
  204. @param attributeValue The value you wish to set the given attribute to
  205. @return No return value.
  206. */
  207. ConsoleMethodWithDocs(SimXMLDocument, setAttribute, ConsoleVoid, 4, 4, (string attributeName, string attributeValue))
  208. {
  209. object->setAttribute(argv[2], argv[3]);
  210. }
  211. /*! Set attribute of top stack element to given value.
  212. @param attributeValue The value you wish to set the given attribute to
  213. @return No return value.
  214. */
  215. ConsoleMethodWithDocs(SimXMLDocument, setObjectAttributes, ConsoleVoid, 3, 3, (string attributeValue))
  216. {
  217. object->setObjectAttributes(argv[2]);
  218. }
  219. /*! Create new element as child of current stack element
  220. and push new element on to stack.
  221. @param name The anme of the new element
  222. @return No return value
  223. */
  224. ConsoleMethodWithDocs(SimXMLDocument, pushNewElement, ConsoleVoid, 3, 3, (string name))
  225. {
  226. object->pushNewElement( argv[2] );
  227. }
  228. /*! Create new element as child of current stack element
  229. and push new element on to stack.
  230. @param name The anme of the new element
  231. @return No return value
  232. */
  233. ConsoleMethodWithDocs(SimXMLDocument, addNewElement, ConsoleVoid, 3, 3, (string name))
  234. {
  235. object->addNewElement( argv[2] );
  236. }
  237. /*! Add XML header to document.
  238. @return No return value.
  239. */
  240. ConsoleMethodWithDocs(SimXMLDocument, addHeader, ConsoleVoid, 2, 2, ())
  241. {
  242. object->addHeader();
  243. }
  244. /*! Add the given comment as a child of current stack element.
  245. @param comment The desired comment to add
  246. @return No return value.
  247. */
  248. ConsoleMethodWithDocs(SimXMLDocument, addComment, ConsoleVoid, 3, 3, (string comment))
  249. {
  250. object->addComment(argv[2]);
  251. }
  252. /*! Returns the comment at the specified index.
  253. @param index The index of the desired comment as a nonnegative integer value
  254. @return The comment as a string
  255. */
  256. ConsoleMethodWithDocs(SimXMLDocument, readComment, ConsoleString, 3, 3, (S32 index))
  257. {
  258. return object->readComment( dAtoi( argv[2] ) );
  259. }
  260. /*! Add the given text as a child of current stack element.
  261. @param text The desired text to add
  262. @return No return value.
  263. */
  264. ConsoleMethodWithDocs(SimXMLDocument, addText, ConsoleVoid, 3, 3, (string text))
  265. {
  266. object->addText(argv[2]);
  267. }
  268. /*! Gets the text from the current stack element.
  269. @return Returns the desired text, or empty string on failure
  270. */
  271. ConsoleMethodWithDocs(SimXMLDocument, getText, ConsoleString, 2, 2, ())
  272. {
  273. const char* text = object->getText();
  274. if( !text )
  275. return "";
  276. char* pBuffer = Con::getReturnBuffer(dStrlen( text ) + 1);
  277. dStrcpy( pBuffer, text );
  278. return pBuffer;
  279. }
  280. /*! Remove any text on the current stack element.
  281. @return No return value
  282. */
  283. ConsoleMethodWithDocs(SimXMLDocument, removeText, ConsoleVoid, 2, 2, ())
  284. {
  285. object->removeText();
  286. }
  287. /*! Add the given text as a child of current stack element.
  288. @param The desired text to add
  289. @return No return value
  290. */
  291. ConsoleMethodWithDocs(SimXMLDocument, addData, ConsoleVoid, 3, 3, (string text))
  292. {
  293. object->addData(argv[2]);
  294. }
  295. /*! Gets the text from the current stack element.
  296. @return Returns the desired text or empty string if failed (no text)
  297. */
  298. ConsoleMethodWithDocs(SimXMLDocument, getData, ConsoleString, 2, 2, ())
  299. {
  300. const char* text = object->getData();
  301. if( !text )
  302. return "";
  303. char* pBuffer = Con::getReturnBuffer(dStrlen( text ) + 1);
  304. dStrcpy( pBuffer, text );
  305. return pBuffer;
  306. }
  307. ConsoleMethodGroupEndWithDocs(SimXMLDocument)