SimXMLDocument.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. ////////////////////////////////////////////////////////////////////////////////
  23. // Console implementation of STL map.
  24. ////////////////////////////////////////////////////////////////////////////////
  25. #ifndef _XMLDOC_H_
  26. #define _XMLDOC_H_
  27. #ifndef _SIMBASE_H_
  28. #include "sim/simBase.h"
  29. #endif
  30. #ifndef _VECTOR_H_
  31. #include "collection/vector.h"
  32. #endif // _VECTOR_H_
  33. #ifndef TINYXML_INCLUDED
  34. #include "persistence/tinyXML/tinyxml.h"
  35. #endif
  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, const char** 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. S32 loadFile(const char* rFileName);
  58. S32 saveFile(const char* rFileName);
  59. S32 parse(const char* rText);
  60. // Clear XML document.
  61. void clear(void);
  62. // Get error description if it exists.
  63. const char* getErrorDesc(void) const;
  64. // Clear previously set error.
  65. void clearError(void);
  66. // Push first/last child element onto element stack.
  67. bool pushFirstChildElement(const char* rName);
  68. // Convert top stack element into sibling with given name.
  69. bool nextSiblingElement(const char* rName);
  70. // push child element at index onto stack.
  71. bool pushChildElement(S32 index);
  72. // Get element value
  73. const char* elementValue();
  74. // Pop last element off of stack.
  75. void popElement(void);
  76. // Get attribute from top element on element stack.
  77. const char* attribute(const char* rAttribute);
  78. // Does the attribute exist in the current element
  79. bool attributeExists(const char* rAttribute);
  80. // Obtain the name of the current element's first or last attribute
  81. const char* firstAttribute();
  82. const char* lastAttribute();
  83. // Move through the current element's attributes to obtain their names
  84. const char* nextAttribute();
  85. const char* prevAttribute();
  86. // Set attribute of top element on element stack.
  87. void setAttribute(const char* rAttribute, const char* rVal);
  88. // Set attributes of a simObject on top element of the stack.
  89. void setObjectAttributes(const char* objectID);
  90. // Remove attribute with given name from top element on stack.
  91. void removeAttribute(const char* rAttribute);
  92. // Create a new element and push it onto stack as a new level.
  93. void pushNewElement(const char* rName);
  94. // Create a new element and push it onto stack on current level.
  95. void addNewElement(const char* rName);
  96. // Write XML declaration to current level.
  97. void addHeader(void);
  98. // Write a XML comment to the current level.
  99. void addComment(const char* comment);
  100. // Read a comment from the current level at the specified index.
  101. const char* readComment( S32 index );
  102. // Write text to the current level.
  103. void addText(const char* text);
  104. // Retrieve text from the current level.
  105. const char* getText();
  106. // Remove Text
  107. void removeText();
  108. // Write data to the current level.
  109. void addData(const char* text);
  110. // Retrieve data from the current level.
  111. const char* getData();
  112. private:
  113. // Document.
  114. TiXmlDocument* m_qDocument;
  115. // Stack of nodes.
  116. Vector<TiXmlElement*> m_paNode;
  117. // The current attribute
  118. TiXmlAttribute* m_CurrentAttribute;
  119. public:
  120. DECLARE_CONOBJECT(SimXMLDocument);
  121. };
  122. #endif // _XMLDOC_H_
  123. ////EOF/////////////////////////////////////////////////////////////////////////