aboutsummaryrefslogtreecommitdiff
path: root/include/cru/common/io/UnixFileStream.hpp
blob: 8bd3829abb40fc4e5770ebb92dc5662f14e1405d (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
40
41
42
43
44
45
#pragma once

#include "../PreConfig.hpp"

#ifdef CRU_PLATFORM_UNIX

#include "../String.hpp"
#include "OpenFileFlag.hpp"
#include "Stream.hpp"

namespace cru::io {
class UnixFileStream : public Stream {
 public:
  UnixFileStream(String path, OpenFileFlag flags);

  CRU_DELETE_COPY(UnixFileStream)
  CRU_DELETE_MOVE(UnixFileStream)

  ~UnixFileStream() override;

 public:
  bool CanSeek() override;
  Index Tell() override;
  void Seek(Index offset, SeekOrigin origin = SeekOrigin::Current) override;

  bool CanRead() override;
  Index Read(std::byte* buffer, Index offset, Index size) override;

  bool CanWrite() override;
  Index Write(const std::byte* buffer, Index offset, Index size) override;

  void Close() override;

 private:
  void CheckClosed();

 private:
  String path_;
  OpenFileFlag flags;
  int file_descriptor_;
  bool closed_ = false;
};
}  // namespace cru::io

#endif