Minecraft Community Edition 0.1.0
Loading...
Searching...
No Matches
FileOutputStream.hpp
1#pragma once
2#include "..\..\Common\Platform.hpp"
3#include "OutputStream.hpp"
4#ifdef MCE_PLATFORM_WINDOWS
5#undef INVALID_FILE_SIZE
6#endif
7
8#include <string>
9#include <cstdio>
10
11namespace mce {
18 class FileOutputStream final : public OutputStream {
19 public:
23 FileOutputStream() = default;
24
30 bool open(const std::string& file);
31
36 bool isOpen() const;
37
41 void close();
42
49 size_t write(const void* buffer, size_t size) override;
50
56 size_t seek(size_t position) override;
57
62 size_t tell() override;
63
68 size_t getSize() override;
69
76 static inline constexpr size_t INVALID_FILE_SIZE = ~(0);
77
81 static inline constexpr size_t INVALID_FILE_POSITION = ~(0);
82
83 private:
84#ifdef MCE_PLATFORM_WINDOWS
91 void* hFile = nullptr;
92#elif defined(MCE_PLATFORM_LINUX) || defined(MCE_PLATFORM_MACOS)
96 std::FILE* file = nullptr;
97#endif
98 };
99}
FileOutputStream()=default
Default constructor.
static constexpr size_t INVALID_FILE_SIZE
Constant indicating an invalid file size/position.
Definition FileOutputStream.hpp:76
size_t getSize() override
Get the total size of the underlying file in bytes.
void close()
Close the file and release any resources.
static constexpr size_t INVALID_FILE_POSITION
Constant indicating an invalid file position.
Definition FileOutputStream.hpp:81
size_t seek(size_t position) override
Change the current write position in the file.
size_t tell() override
Get the current write position in the file.
size_t write(const void *buffer, size_t size) override
Write bytes to the file.
bool open(const std::string &file)
Opens a file for writing (creates/truncates by default).
bool isOpen() const
Query whether the underlying file handle is open.
Definition OutputStream.hpp:6