Files
aurora/lib/card/FileIO.hpp
Irastris 9c3d4665ce Refactor CARD FileIO with on-demand handles (#77)
* Refactor CARD FileIO with on-demand handles

* Guarantee stream is flushed before closing handle
2026-03-31 20:24:20 -07:00

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