CMemoryStream.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /**
  13. * A class which provides method definitions for reading from memory.
  14. */
  15. class DLL_LINKAGE CMemoryStream : public CInputStream
  16. {
  17. public:
  18. /**
  19. * C-tor. The data buffer won't be free'd. (no ownership)
  20. *
  21. * @param data a pointer to the data array.
  22. * @param size The size in bytes of the array.
  23. */
  24. CMemoryStream(const ui8 * data, si64 size);
  25. /**
  26. * Reads n bytes from the stream into the data buffer.
  27. *
  28. * @param data A pointer to the destination data array.
  29. * @param size The number of bytes to read.
  30. * @return the number of bytes read actually.
  31. */
  32. si64 read(ui8 * data, si64 size);
  33. /**
  34. * Seeks the internal read pointer to the specified position.
  35. *
  36. * @param position The read position from the beginning.
  37. * @return the position actually moved to, -1 on error.
  38. */
  39. si64 seek(si64 position);
  40. /**
  41. * Gets the current read position in the stream.
  42. *
  43. * @return the read position.
  44. */
  45. si64 tell();
  46. /**
  47. * Skips delta numbers of bytes.
  48. *
  49. * @param delta The count of bytes to skip.
  50. * @return the count of bytes skipped actually.
  51. */
  52. si64 skip(si64 delta);
  53. /**
  54. * Gets the length in bytes of the stream.
  55. *
  56. * @return the length in bytes of the stream.
  57. */
  58. si64 getSize();
  59. private:
  60. /** A pointer to the data array. */
  61. const ui8 * data;
  62. /** The size in bytes of the array. */
  63. si64 size;
  64. /** Current reading position of the stream. */
  65. si64 position;
  66. };