bsnes/nall/stream/file.hpp
Tim Allen f2a416aea9 Update to v095r11 release.
byuu says:

Changelog:
- SFC: "uint8 read(uint addr)" -> "uint8 read(uint addr, uint8 data)"
- hiro: mHorizontalLayout::setGeometry() return value
- hiro/GTK: ListView,TreeView::setFocused() does not grab focus of first
  item

Notes:
- nall/windows/utf8.hpp needs using uint = unsigned; at the top to
  compile
- sfc/balanced, sfc/performance won't compile yet

Seems Cx4 games broke a while back. Not from this WIP, either. I'll go
back and find out what's wrong now.
2015-12-14 20:41:06 +11:00

43 lines
1.1 KiB
C++

#ifndef NALL_STREAM_FILE_HPP
#define NALL_STREAM_FILE_HPP
#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(unsigned offset) const -> void { pfile.seek(offset); }
auto read() const -> uint8 { return pfile.read(); }
auto write(uint8_t data) const -> void { pfile.write(data); }
private:
mutable file pfile;
bool pwritable;
};
}
#endif