CMemoryStream.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. /*
  3. * CMemoryStream.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  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. };