CMemoryBuffer.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * CMemoryBuffer.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 "CInputOutputStream.h"
  12. VCMI_LIB_NAMESPACE_BEGIN
  13. /**
  14. * A class which provides IO memory buffer.
  15. */
  16. class DLL_LINKAGE CMemoryBuffer : public CInputOutputStream
  17. {
  18. public:
  19. using TBuffer = std::vector<ui8>;
  20. /**
  21. * C-tor.
  22. *
  23. */
  24. CMemoryBuffer();
  25. /**
  26. * Write 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 write.
  30. * @return the number of bytes written actually.
  31. */
  32. si64 write(const ui8 * data, si64 size) override;
  33. /**
  34. * Reads n bytes from the stream into the data buffer.
  35. *
  36. * @param data A pointer to the destination data array.
  37. * @param size The number of bytes to read.
  38. * @return the number of bytes read actually.
  39. */
  40. si64 read(ui8 * data, si64 size) override;
  41. /**
  42. * Seeks the internal read pointer to the specified position.
  43. *
  44. * @param position The read position from the beginning.
  45. * @return the position actually moved to, -1 on error.
  46. */
  47. si64 seek(si64 position) override;
  48. /**
  49. * Gets the current read position in the stream.
  50. *
  51. * @return the read position.
  52. */
  53. si64 tell() override;
  54. /**
  55. * Skips delta numbers of bytes.
  56. *
  57. * @param delta The count of bytes to skip.
  58. * @return the count of bytes skipped actually.
  59. */
  60. si64 skip(si64 delta) override;
  61. /**
  62. * Gets the length in bytes of the stream.
  63. *
  64. * @return the length in bytes of the stream.
  65. */
  66. si64 getSize() override;
  67. const TBuffer & getBuffer(){return buffer;}
  68. private:
  69. /** Actual data. */
  70. TBuffer buffer;
  71. /** Current reading position of the stream. */
  72. si64 position;
  73. };
  74. VCMI_LIB_NAMESPACE_END