bsnes/nall/stream/file.hpp
Tim Allen 0d0af39b44 Update to v097r14 release.
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.
2016-02-16 20:11:58 +11:00

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;
};
}