IAcReadWriteStream.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // DESCRIPTION: IAcReadStream and IAcWriteStream general purpose
  13. // filing interfaces
  14. #pragma once
  15. /// <summary>
  16. /// Interface for a readable stream.
  17. /// </summary>
  18. class __declspec(novtable) IAcReadStream
  19. {
  20. public:
  21. /// <summary>
  22. /// return codes
  23. /// </summary>
  24. enum {
  25. /// <summary>
  26. /// No errors occurred
  27. /// </summary>
  28. eOk = 0,
  29. /// <summary>
  30. /// This function is not supported for this stream object
  31. /// </summary>
  32. eNotSupported = 1,
  33. /// <summary>
  34. /// The stream is not open
  35. /// </summary>
  36. eNotOpen = 2,
  37. /// <summary>
  38. /// One of the arguments is an invalid value
  39. /// </summary>
  40. eInvalidArg = 3,
  41. /// <summary>
  42. /// The stream is at the end of the file
  43. /// </summary>
  44. eEndOfFile = 4,
  45. /// <summary>
  46. /// The disk to which the stream is writing is full
  47. /// </summary>
  48. eDiskFull = 5,
  49. /// <summary>
  50. /// The stream is disconnected
  51. /// </summary>
  52. eDisconnected = 6,
  53. /// <summary>
  54. /// Unknown error
  55. /// </summary>
  56. eJustAnError = 7
  57. };
  58. /// <summary>
  59. /// seek mode arguments
  60. /// </summary>
  61. enum {
  62. /// <summary>
  63. /// Seek from start of stream
  64. /// </summary>
  65. eFromStart = 0,
  66. /// <summary>
  67. /// Seek from current stream position
  68. /// </summary>
  69. eFromCurrent = 1,
  70. /// <summary>
  71. /// Seek from end of stream
  72. /// </summary>
  73. eFromEnd = 2
  74. };
  75. /// <summary>
  76. /// This function sets the stream position to be nDistance from the nMode stream
  77. /// location. If nDistance is negative, then the new position will be that distance
  78. /// earlier in the stream, otherwise it will be nDistance after the nMode location.
  79. /// </summary>
  80. /// <param name="nDistance">Input distance to seek from nMode position</param>
  81. /// <param name="nMode">Input seek mode</param>
  82. /// <returns>Returns a status (such as eOk) indicating the outcome of the seek operation.</returns>
  83. virtual int seek(__int64 nDistance, int nMode) {
  84. UNREFERENCED_PARAMETER(nDistance);
  85. UNREFERENCED_PARAMETER(nMode);
  86. return eNotSupported;
  87. }
  88. /// <summary>
  89. /// This function sets nOffset to the current stream position relative to the start of the stream.
  90. /// </summary>
  91. /// <returns>Returns the distance from the start of the stream to the current read/write position. Returns -1 by default.</returns>
  92. virtual __int64 tell() { return -1; }
  93. /// <summary>
  94. /// This function reads nNumBytes bytes of data from the stream and copies it into the location
  95. /// pointed to by pDestBuf. The value pointed to by pNumRead is set to the number of bytes
  96. /// actually read and copied to pDestBuf.
  97. /// Some implementations may return eOk when the number of bytes read is less than
  98. /// the number requested. Others may return eEndOfFile in that case.
  99. /// </summary>
  100. /// NOTE: when implementing a class derived from IAcReadStream, the read() method must be
  101. /// overridden, but all other IAcReadStream methods can be the default implementations.
  102. /// <param name="pDestBuf">Input pointer to location to copy stream data to</param>
  103. /// <param name="nNumBytes">Input number of bytes to read from stream</param>
  104. /// <param name="pNumRead">Output number of bytes read from stream</param>
  105. /// <returns>Returns a status (such as eOk) indicating the outcome of the read operation.</returns>
  106. virtual int read(void* pDestBuf, size_t nNumBytes,
  107. size_t *pNumRead) = 0;
  108. /// <summary>
  109. /// This function closes the stream, and may also deallocate the stream object.
  110. /// </summary>
  111. /// <returns>Returns a status (such as eOk) indicating the outcome of the close operation.</returns>
  112. virtual int close() { return eNotSupported; }
  113. /// <summary>
  114. /// Auxiliary method for implementation-specific functionality.
  115. /// </summary>
  116. /// <param name="nArg">Input value, implementation dependent</param>
  117. /// <returns>An implementation dependent value.</returns>
  118. virtual __int64 control(__int64 nArg) {
  119. UNREFERENCED_PARAMETER(nArg);
  120. return 0;
  121. }
  122. protected:
  123. /// <summary>
  124. /// Destructor
  125. /// </summary>
  126. virtual ~IAcReadStream() {} // no explicit deletes
  127. };
  128. /// <summary>
  129. /// Interface for a read/write stream.
  130. /// </summary>
  131. class __declspec(novtable) IAcWriteStream : public IAcReadStream
  132. {
  133. public:
  134. /// <summary>
  135. /// This function copies nNumBytes bytes of data from the location pointed to by pSrcBuf to the
  136. /// stream. The value pointed to by pNumWritten is set to the number of bytes actually copied
  137. /// to the stream.
  138. /// </summary>
  139. /// NOTE: When implementing a class derived from IAcWriteStream, the write() method must be
  140. /// overridden, but all other IAcWriteStream methods can be the default implementations.
  141. /// <param name="pSrcBuf">Input pointer to location of data to be written to the stream</param>
  142. /// <param name="nNumBytes">Input number of bytes to write to the stream</param>
  143. /// <param name="pNumWritten">Output number of bytes written to the stream</param>
  144. /// <returns>Returns a status (such as eOk) indicating the outcome of the write operation.</returns>
  145. virtual int write(const void* pSrcBuf, size_t nNumBytes,
  146. size_t *pNumWritten) = 0;
  147. /// <summary>
  148. /// This function flushes any buffers used by the stream.
  149. /// </summary>
  150. /// <returns>Returns a status (such as eOk) indicating the outcome of the operation.</returns>
  151. virtual int flushBuffers() { return eNotSupported; }
  152. /// <summary>
  153. /// This function sets the current stream position as the end of file.
  154. /// </summary>
  155. /// <returns>Returns a status (such as eOk) indicating the outcome of the operation.</returns>
  156. virtual int setEndOfFile() { return eNotSupported; }
  157. protected:
  158. /// <summary>
  159. /// Destructor
  160. /// </summary>
  161. virtual ~IAcWriteStream() {} // no explicit deletes
  162. };