Loading...
Searching...
No Matches
FileOutputStream.hpp
#pragma once
#include "..\..\Platform.hpp"
#include "OutputStream.hpp"
#ifdef MCE_PLATFORM_WINDOWS
#undef INVALID_FILE_SIZE
#endif
#include <string>
#include <cstdio>
namespace mce::io::stream {
class FileOutputStream final : public OutputStream {
public:
FileOutputStream() = default;
bool open(const std::string& file);
bool isOpen() const;
void close();
size_t write(const void* buffer, size_t size) override;
size_t seek(size_t position) override;
size_t tell() override;
size_t getSize() override;
static inline constexpr size_t INVALID_FILE_SIZE = ~(0);
static inline constexpr size_t INVALID_FILE_POSITION = ~(0);
private:
#ifdef MCE_PLATFORM_WINDOWS
void* hFile = nullptr;
#elif defined(MCE_PLATFORM_LINUX) || defined(MCE_PLATFORM_MACOS)
std::FILE* file = nullptr;
#endif
};
}
mce::io::FileOutputStream::FileOutputStream
FileOutputStream()=default
Default constructor.
mce::io::stream::FileOutputStream::INVALID_FILE_SIZE
static constexpr size_t INVALID_FILE_SIZE
Constant indicating an invalid file size/position.
Definition FileOutputStream.hpp:76
mce::io::stream::FileOutputStream::write
size_t write(const void *buffer, size_t size) override
Write bytes to the file.
mce::io::stream::FileOutputStream::seek
size_t seek(size_t position) override
Change the current write position in the file.
mce::io::stream::FileOutputStream::INVALID_FILE_POSITION
static constexpr size_t INVALID_FILE_POSITION
Constant indicating an invalid file position.
Definition FileOutputStream.hpp:81
mce::io::stream::FileOutputStream::getSize
size_t getSize() override
Get the total size of the underlying file in bytes.
mce::io::stream::FileOutputStream::close
void close()
Close the file and release any resources.
mce::io::stream::FileOutputStream::isOpen
bool isOpen() const
Query whether the underlying file handle is open.
mce::io::stream::FileOutputStream::FileOutputStream
FileOutputStream()=default
Default constructor.
mce::io::stream::FileOutputStream::open
bool open(const std::string &file)
Opens a file for writing (creates/truncates by default).
mce::io::stream::FileOutputStream::tell
size_t tell() override
Get the current write position in the file.