SimXMLDocument.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. //-----------------------------------------------------------------------------
  23. // Console implementation of STL map.
  24. //-----------------------------------------------------------------------------
  25. #ifndef _XMLDOC_H_
  26. #define _XMLDOC_H_
  27. #ifndef _SIMBASE_H_
  28. #include "console/simBase.h"
  29. #endif
  30. #ifndef _TVECTOR_H_
  31. #include "core/util/tVector.h"
  32. #endif // _TVECTOR_H_
  33. #ifndef TINYXML2_INCLUDED
  34. #include <tinyxml2.h>
  35. #endif // TINYXML2_INCLUDED
  36. #include "persistence/taml/fsTinyXml.h"
  37. class SimXMLDocument: public SimObject
  38. {
  39. // This typedef is required for tie ins with the script language.
  40. // --------------------------------------------------------------------------
  41. protected:
  42. typedef SimObject Parent;
  43. // --------------------------------------------------------------------------
  44. public:
  45. SimXMLDocument();
  46. ~SimXMLDocument();
  47. // These are overloaded functions from SimObject that we handle for
  48. // tie in to the script language. The .cc file has more in depth
  49. // comments on these.
  50. //-----------------------------------------------------------------------
  51. bool processArguments(S32 argc, ConsoleValue *argv);
  52. bool onAdd();
  53. void onRemove();
  54. static void initPersistFields();
  55. // Set this to default state at construction.
  56. void reset(void);
  57. // Read / write / parse XML.
  58. bool loadFile(const char* rFileName);
  59. bool saveFile(const char* rFileName);
  60. S32 parse(const char* rText);
  61. bool saveToString(String& str);
  62. // Clear XML document.
  63. void clear(void);
  64. // Get error description if it exists.
  65. const char* getErrorDesc(void) const;
  66. // Clear previously set error.
  67. void clearError(void);
  68. // Push first/last child element onto element stack.
  69. bool pushFirstChildElement(const char* rName);
  70. // Convert top stack element into sibling with given name.
  71. bool nextSiblingElement(const char* rName);
  72. // push child element at index onto stack.
  73. bool pushChildElement(S32 index);
  74. // Get element value
  75. const char* elementValue();
  76. // Pop last element off of stack.
  77. void popElement(void);
  78. // Get attribute from top element on element stack.
  79. const char* attribute(const char* rAttribute);
  80. // Does the attribute exist in the current element
  81. bool attributeExists(const char* rAttribute);
  82. // Obtain the name of the current element's first or last attribute
  83. const char* firstAttribute();
  84. const char* lastAttribute();
  85. // Move through the current element's attributes to obtain their names
  86. const char* nextAttribute();
  87. const char* prevAttribute();
  88. // Set attribute of top element on element stack.
  89. void setAttribute(const char* rAttribute, const char* rVal);
  90. // Set attributes of a simObject on top element of the stack.
  91. void setObjectAttributes(const char* objectID);
  92. // Remove attribute with given name from top element on stack.
  93. void removeAttribute(const char* rAttribute);
  94. // Create a new element and push it onto stack as a new level.
  95. void pushNewElement(const char* rName);
  96. // Create a new element and push it onto stack on current level.
  97. void addNewElement(const char* rName);
  98. // Write XML declaration to current level.
  99. void addHeader(void);
  100. // Write a XML comment to the current level.
  101. void addComment(const char* comment);
  102. // Read a comment from the current level at the specified index.
  103. const char* readComment( S32 index );
  104. // Write text to the current level.
  105. void addText(const char* text);
  106. // Retrieve text from the current level.
  107. const char* getText();
  108. // Remove Text
  109. void removeText();
  110. // Write data to the current level.
  111. void addData(const char* text);
  112. // Retrieve data from the current level.
  113. const char* getData();
  114. private:
  115. // Document.
  116. VfsXMLDocument* m_qDocument;
  117. // Stack of nodes.
  118. Vector<tinyxml2::XMLNode*> m_paNode;
  119. // The current attribute
  120. const tinyxml2::XMLAttribute* m_CurrentAttribute;
  121. public:
  122. DECLARE_CONOBJECT(SimXMLDocument);
  123. };
  124. #endif // _XMLDOC_H_
  125. ////EOF/////////////////////////////////////////////////////////////////////////