mirror of
https://github.com/encounter/aurora.git
synced 2026-07-09 18:19:33 -07:00
9c3d4665ce
* Refactor CARD FileIO with on-demand handles * Guarantee stream is flushed before closing handle
33 lines
864 B
C++
33 lines
864 B
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
|
|
#include <SDL3/SDL_iostream.h>
|
|
|
|
namespace aurora::card {
|
|
|
|
class FileIO {
|
|
std::string m_path;
|
|
bool m_ready = false;
|
|
|
|
bool isReady() const { return m_ready && !m_path.empty(); };
|
|
|
|
public:
|
|
FileIO() = default;
|
|
explicit FileIO(std::string_view filename, bool truncate = false);
|
|
~FileIO() = default;
|
|
|
|
FileIO(FileIO&& other) noexcept;
|
|
FileIO& operator=(FileIO&& other) noexcept;
|
|
FileIO(const FileIO& other) = delete;
|
|
FileIO& operator=(const FileIO& other) = delete;
|
|
|
|
static SDL_IOStream* fileOpen(const std::string& path, const char* mode) {return path.empty() ? nullptr : SDL_IOFromFile(path.c_str(), mode);}
|
|
bool fileRead(void* buf, size_t length, off_t offset);
|
|
bool fileWrite(const void* buf, size_t length, off_t offset);
|
|
explicit operator bool() const;
|
|
};
|
|
|
|
} // namespace aurora::card
|