StreamFile.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include "../../Include/RmlUi/Core/Stream.h"
  3. #include "../../Include/RmlUi/Core/Types.h"
  4. namespace Rml {
  5. class StreamFile final : public Stream {
  6. public:
  7. StreamFile();
  8. virtual ~StreamFile();
  9. /// Attempts to open the stream pointing at a given location.
  10. bool Open(const String& path);
  11. /// Closes the stream.
  12. void Close() override;
  13. /// Returns the size of this stream (in bytes).
  14. size_t Length() const override;
  15. /// Returns the position of the stream pointer (in bytes).
  16. size_t Tell() const override;
  17. /// Sets the stream position (in bytes).
  18. bool Seek(long offset, int origin) const override;
  19. /// Read from the stream.
  20. size_t Read(void* buffer, size_t bytes) const override;
  21. using Stream::Read;
  22. /// Write to the stream at the current position.
  23. size_t Write(const void* buffer, size_t bytes) override;
  24. using Stream::Write;
  25. /// Truncate the stream to the specified length.
  26. size_t Truncate(size_t bytes) override;
  27. /// Returns true if the stream is ready for reading, false otherwise.
  28. bool IsReadReady() override;
  29. /// Returns false.
  30. bool IsWriteReady() override;
  31. private:
  32. // Determines the length of the stream.
  33. void GetLength();
  34. FileHandle file_handle;
  35. size_t length;
  36. };
  37. } // namespace Rml