SimXMLDocument.h 5.4 KB

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