blob: 0b58bdc98b6146a33098297f518afe61e8864bd7 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 | #pragma once
#include "Stream.h"
#include <cstdio>
namespace cru::io {
class CRU_BASE_API CFileStream : public Stream {
 public:
  CFileStream(const char* path, const char* mode);
  explicit CFileStream(std::FILE* file, bool readable = true,
                       bool writable = true, bool auto_close = true);
  CRU_DELETE_COPY(CFileStream)
  CRU_DELETE_MOVE(CFileStream)
  ~CFileStream() override;
 public:
  CRU_STREAM_IMPLEMENT_CLOSE_BY_DO_CLOSE
  std::FILE* GetHandle() const;
 protected:
  Index DoSeek(Index offset, SeekOrigin origin) override;
  Index DoTell() override;
  void DoRewind() override;
  Index DoRead(std::byte* buffer, Index offset, Index size) override;
  Index DoWrite(const std::byte* buffer, Index offset, Index size) override;
  void DoFlush() override;
 private:
  void DoClose();
 private:
  std::FILE* file_;
  bool auto_close_;
};
}  // namespace cru::io
 |