mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
byuu says: This is a few days old, but oh well. This WIP changes nall,hiro,ruby,icarus back to (u)int(8,16,32,64)_t. I'm slowly pushing for (u)int(8,16,32,64) to use my custom Integer<Size>/Natural<Size> classes instead. But it's going to be one hell of a struggle to get that into higan.
39 lines
1 KiB
C++
39 lines
1 KiB
C++
#pragma once
|
|
|
|
#include <nall/file.hpp>
|
|
|
|
namespace nall {
|
|
|
|
struct filestream : stream {
|
|
using stream::read;
|
|
using stream::write;
|
|
|
|
filestream(const string& filename) {
|
|
pfile.open(filename, file::mode::readwrite);
|
|
pwritable = pfile.open();
|
|
if(!pwritable) pfile.open(filename, file::mode::read);
|
|
}
|
|
|
|
filestream(const string& filename, file::mode mode) {
|
|
pfile.open(filename, mode);
|
|
pwritable = mode == file::mode::write || mode == file::mode::readwrite;
|
|
}
|
|
|
|
auto seekable() const -> bool { return true; }
|
|
auto readable() const -> bool { return true; }
|
|
auto writable() const -> bool { return pwritable; }
|
|
auto randomaccess() const -> bool { return false; }
|
|
|
|
auto size() const -> uint { return pfile.size(); }
|
|
auto offset() const -> uint { return pfile.offset(); }
|
|
auto seek(uint offset) const -> void { pfile.seek(offset); }
|
|
|
|
auto read() const -> uint8_t { return pfile.read(); }
|
|
auto write(uint8_t data) const -> void { pfile.write(data); }
|
|
|
|
private:
|
|
mutable file pfile;
|
|
bool pwritable;
|
|
};
|
|
|
|
}
|