CMemoryBuffer.h 1.8 KB

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