You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IWriterHelper.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #include "IWriter.h"
  3. namespace EBML {
  4. /**
  5. * \class IWriterHelper
  6. * \author Yann Renard (INRIA/IRISA)
  7. * \date 2006-08-07
  8. * \brief Helper to write basic EBML types
  9. *
  10. * This class may be used by the user in order to correctly
  11. * format simple types defined in the EBML description such
  12. * as integers, floats, strings etc... It directly uses the
  13. * EBML::IWriter connected instance so one could simply
  14. * use the helper in order to write his EBML stream.
  15. *
  16. * A similar class exists to help parsing process...
  17. * See EBML::IReaderHelper for more details.
  18. *
  19. * Be sure to look at http://ebml.sourceforge.net/specs/ in
  20. * order to understand what EBML is and how it should be used.
  21. *
  22. * \todo long double formating implementation
  23. * \todo date formating implementation
  24. * \todo utf8 string formating implementation
  25. */
  26. class EBML_API IWriterHelper
  27. {
  28. public:
  29. /** \name Writer connection */
  30. //@{
  31. /**
  32. * \brief Connects an EBML writer to this helper
  33. * \param writer [in] : The writer to connect
  34. * \return \e true on success.
  35. * \return \e false on error.
  36. *
  37. * This function gives the helper a handle to the writer
  38. * to use in order to forward requests. Thus, when the
  39. * user calls a helper function, the call is forwarded
  40. * to the correct writer that effictively does the work.
  41. * The aim of this helper is simply to transform standard
  42. * EBML types into bytes buffers.
  43. *
  44. * Once a writer is connected, it could be disconnected
  45. * thanks to the \c disconnect function. It must be done
  46. * before calling \c connect again.
  47. */
  48. virtual bool connect(IWriter* writer) = 0;
  49. /**
  50. * \brief Disconnects the currently connected EBML writer
  51. * \return \e true on success.
  52. * \return \e false on error.
  53. *
  54. * This function should be called to release the EBML
  55. * writer handle. The helper instance may then be used
  56. * with another EBML writer instance calling \c connect
  57. * again.
  58. */
  59. virtual bool disconnect() = 0;
  60. //@}
  61. /** \name Writer binding functions */
  62. //@{
  63. /**
  64. * \brief Child opening binding
  65. * \param identifier [in] : The identifier of the new child node
  66. * \return \e true on success.
  67. * \return \e false on error.
  68. *
  69. * This function simply forwards the call to the
  70. * corresponding EBML::IWriter function. See
  71. * EBML::IWriter::openChild for more details.
  72. */
  73. virtual bool openChild(const CIdentifier& identifier) = 0;
  74. /**
  75. * \brief Child closing binding
  76. * \return \e true on success.
  77. * \return \e false on error.
  78. *
  79. * This function simply forwards the call to the
  80. * corresponding EBML::IWriter function. See
  81. * EBML::IWriter::closeChild for more details.
  82. */
  83. virtual bool closeChild() = 0;
  84. //@}
  85. /**
  86. * \name Standard EBML formating
  87. * \brief EBML::IWriter::setChildData replacement
  88. * \return \e true on success.
  89. * \return \e false on error.
  90. *
  91. * Those functions should be used in place of the
  92. * basic EBML::IWriter::setChildData function. They
  93. * format standard EBML types into corresponding
  94. * buffers and then send those built buffers to
  95. * the writer using the EBML::IWriter::setChildData
  96. * function.
  97. */
  98. //@{
  99. /**
  100. * \brief Sets a signed integer as child data
  101. * \param value [in] : The integer value to set
  102. */
  103. virtual bool setInt(const int64_t value) = 0;
  104. /**
  105. * \brief Sets an unsigned integer as child data
  106. * \param value [in] : The integer value to set
  107. */
  108. virtual bool setUInt(const uint64_t value) = 0;
  109. /**
  110. * \brief Sets a 32 bits float value as child data
  111. * \param value [in] : The 32 bits float value to set
  112. */
  113. virtual bool setFloat(const float value) = 0;
  114. /**
  115. * \brief Sets a 64 bits float value as child data
  116. * \param value [in] : The 64 bits float value to set
  117. */
  118. virtual bool setDouble(const double value) = 0;
  119. // virtual bool setFloat80AsChildData( ??? value)=0;
  120. // virtual bool setDateAsChildData( ??? value)=0;
  121. /**
  122. * \brief Sets a buffer as child data
  123. * \param buffer [in] : The buffer to send to the writer
  124. * \param size [in] : The buffer size in bytes
  125. * \note This function simply calls the basic
  126. * EBML::IWriter::setChildData function with the
  127. * same two parameters.
  128. */
  129. virtual bool setBinary(const void* buffer, const size_t size) = 0;
  130. /**
  131. * \brief Sets an ASCII string as child data
  132. * \param value [in] : The ASCII string value to set
  133. */
  134. virtual bool setStr(const char* value) = 0;
  135. // virtual bool setUTF8StringAsChildData( ??? value)=0;
  136. //@}
  137. /**
  138. * \brief Tells this object it won't be used anymore
  139. *
  140. * Instances of this class can not be instanciated
  141. * another way than calling \c createWriterHelper. They
  142. * can not be deleted either because the destructor is.
  143. * protected. The library knows how to create and
  144. * delete an instance of this class... Calling
  145. * \c release will simply delete this instance and
  146. * handle necessary cleanings when needed.
  147. *
  148. * The current object is invalid after calling this
  149. * function. It can not be used anymore.
  150. *
  151. * \warning Releasing this obbject does not release the
  152. * connected writer instance !
  153. */
  154. virtual void release() = 0;
  155. protected:
  156. /**
  157. * \brief Virtual destructor - should be overloaded
  158. */
  159. virtual ~IWriterHelper() { }
  160. };
  161. /**
  162. * \brief Instanciation function for EBML writer helper objects
  163. * \return a pointer to the created instance on success.
  164. * \return \c NULL when something went wrong.
  165. */
  166. extern EBML_API IWriterHelper* createWriterHelper();
  167. } // namespace EBML