CMemoryStream.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * CMemoryStream.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "CInputStream.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. /**
  14. * A class which provides method definitions for reading from memory.
  15. * @deprecated use CMemoryBuffer
  16. */
  17. class DLL_LINKAGE CMemoryStream : public CInputStream
  18. {
  19. public:
  20. /**
  21. * C-tor. The data buffer won't be free'd. (no ownership)
  22. *
  23. * @param data a pointer to the data array.
  24. * @param size The size in bytes of the array.
  25. */
  26. CMemoryStream(const ui8 * data, si64 size);
  27. /**
  28. * Reads n bytes from the stream into the data buffer.
  29. *
  30. * @param data A pointer to the destination data array.
  31. * @param size The number of bytes to read.
  32. * @return the number of bytes read actually.
  33. */
  34. si64 read(ui8 * data, si64 size) override;
  35. /**
  36. * Seeks the internal read pointer to the specified position.
  37. *
  38. * @param position The read position from the beginning.
  39. * @return the position actually moved to, -1 on error.
  40. */
  41. si64 seek(si64 position) override;
  42. /**
  43. * Gets the current read position in the stream.
  44. *
  45. * @return the read position.
  46. */
  47. si64 tell() override;
  48. /**
  49. * Skips delta numbers of bytes.
  50. *
  51. * @param delta The count of bytes to skip.
  52. * @return the count of bytes skipped actually.
  53. */
  54. si64 skip(si64 delta) override;
  55. /**
  56. * Gets the length in bytes of the stream.
  57. *
  58. * @return the length in bytes of the stream.
  59. */
  60. si64 getSize() override;
  61. private:
  62. /** A pointer to the data array. */
  63. const ui8 * data;
  64. /** The size in bytes of the array. */
  65. si64 size;
  66. /** Current reading position of the stream. */
  67. si64 position;
  68. };
  69. VCMI_LIB_NAMESPACE_END