IXmlTextWriter.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*******************************************************************************
  2. The content of this file includes portions of the AUDIOKINETIC Wwise Technology
  3. released in source code form as part of the SDK installer package.
  4. Commercial License Usage
  5. Licensees holding valid commercial licenses to the AUDIOKINETIC Wwise Technology
  6. may use this file in accordance with the end user license agreement provided
  7. with the software or, alternatively, in accordance with the terms contained in a
  8. written agreement between you and Audiokinetic Inc.
  9. Apache License Usage
  10. Alternatively, this file may be used under the Apache License, Version 2.0 (the
  11. "Apache License"); you may not use this file except in compliance with the
  12. Apache License. You may obtain a copy of the Apache License at
  13. http://www.apache.org/licenses/LICENSE-2.0.
  14. Unless required by applicable law or agreed to in writing, software distributed
  15. under the Apache License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
  16. OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License for
  17. the specific language governing permissions and limitations under the License.
  18. Copyright (c) 2023 Audiokinetic Inc.
  19. *******************************************************************************/
  20. /// \file
  21. /// Persistance interface for Wwise plugins.
  22. #ifndef AK_XML_WRITER
  23. #define AK_XML_WRITER
  24. namespace AK
  25. {
  26. ///
  27. namespace XmlWriteState
  28. {
  29. /// WriteState
  30. enum WriteState
  31. {
  32. Attribute, ///< Attribute
  33. Closed, ///< Closed
  34. Content, ///< Content
  35. Element, ///< Element
  36. Prolog, ///< Prolog
  37. Start ///< Start
  38. };
  39. }
  40. /// Possible error codes when writing XML
  41. namespace XmlWriteReady
  42. {
  43. /// Possible error codes when writing XML
  44. enum WriteReady
  45. {
  46. Ready, ///< No error
  47. ErrorPathTooLong, ///< Path exceeds max length
  48. ErrorAccessDenied, ///< Cannot open file due to access permissions
  49. ErrorUnknown ///< Unknown error
  50. };
  51. }
  52. namespace XmlElementType
  53. {
  54. // These element types have an impact when outputting in alternate formats such as JSON.
  55. enum ElementType
  56. {
  57. Map, // Associative (Unique Keys)
  58. Array, // Enumerative
  59. MultiMap // Associative (Shared Keys)
  60. };
  61. };
  62. /// Interface for plugin persistance.
  63. /// \sa AK::Wwise::IAudioPlugin::Save
  64. class IXmlTextWriter
  65. {
  66. public:
  67. /// Destroys the text writer. You should not call this function.
  68. virtual void Destroy() = 0;
  69. /// \return True if the writer is ready.
  70. virtual bool IsReady() const = 0;
  71. virtual AK::XmlWriteReady::WriteReady GetReadyState() const = 0;
  72. virtual bool Append( AK::IXmlTextWriter* in_pWriterToAppend ) = 0;
  73. // Properties
  74. virtual AK::XmlWriteState::WriteState GetWriteState() const = 0;
  75. // Methods
  76. /// Writes the XML declaration.
  77. virtual void WriteStartDocument() = 0;
  78. /// Closes one element and pops the corresponding namespace scope.
  79. virtual void WriteEndDocument() = 0;
  80. /// Writes out a start tag with the specified local name.
  81. virtual void WriteStartElement( const CStringW& in_rcsElementName, /// The local name of the element.
  82. AK::XmlElementType::ElementType in_eType = AK::XmlElementType::Map /// Element type.
  83. ) = 0;
  84. /// Closes one element and pops the corresponding namespace scope.
  85. virtual void WriteEndElement() = 0;
  86. /// Writes an attribute with the specified value.
  87. virtual void WriteAttributeString( const CStringW& in_rcsAttribute, /// The local name of the attribute.
  88. const CStringW& in_rcsValue /// The value of the attribute.
  89. ) = 0;
  90. /// Writes the given text content.
  91. virtual void WriteString( const CStringW& in_rcsValue /// The text to write.
  92. ) = 0;
  93. /// Writes out a <![CDATA[...]]> block containing the specified text.
  94. virtual void WriteCData( const CStringW& in_rcsValue /// The text to place inside the CDATA block.
  95. ) = 0;
  96. /// Writes raw markup manually.
  97. virtual void WriteRaw( const CStringW& in_rcsValue /// String containing the text to write
  98. ) = 0;
  99. // Helpers
  100. /// Use this class to handle the WriteStartElement/WriteEndElement pair automatically in a C++ scope.
  101. class AutoStartEndElement
  102. {
  103. public:
  104. /// Calls WriteStartElement automatically
  105. AutoStartEndElement( const CStringW& in_rcsElementName, AK::IXmlTextWriter* in_pWriter, AK::XmlElementType::ElementType in_eType = AK::XmlElementType::Map )
  106. : m_pWriter( in_pWriter )
  107. {
  108. m_pWriter->WriteStartElement( in_rcsElementName, in_eType );
  109. }
  110. /// Calls WriteEndElement automatically
  111. ~AutoStartEndElement()
  112. {
  113. m_pWriter->WriteEndElement();
  114. }
  115. private:
  116. AK::IXmlTextWriter* m_pWriter;
  117. };
  118. };
  119. }
  120. #endif