bsnes/nall/vfs/vfs.hpp
Tim Allen 0a57cac70c Update to v101r02 release.
byuu says:

Changelog:

  - Emulator: use `(uintmax)-1 >> 1` for the units of time
  - MD: implemented 13 new 68K instructions (basically all of the
    remaining easy ones); 21 remain
  - nall: replaced `(u)intmax_t` (64-bit) with *actual* `(u)intmax` type
    (128-bit where available)
      - this extends to everything: atoi, string, etc. You can even
        print 128-bit variables if you like

22,552 opcodes still don't exist in the 68K map. Looking like quite a
few entries will be blank once I finish.
2016-08-09 21:07:18 +10:00

76 lines
1.7 KiB
C++

#pragma once
#include <nall/range.hpp>
#include <nall/shared-pointer.hpp>
namespace nall { namespace vfs {
struct file {
enum class mode : uint { read, write, modify, create };
enum class index : uint { absolute, relative };
virtual ~file() = default;
virtual auto size() const -> uintmax = 0;
virtual auto offset() const -> uintmax = 0;
virtual auto seek(intmax offset, index = index::absolute) -> void = 0;
virtual auto read() -> uint8_t = 0;
virtual auto write(uint8_t data) -> void = 0;
virtual auto flush() -> void {}
auto end() const -> bool {
return offset() >= size();
}
auto read(void* vdata, uintmax bytes) -> void {
auto data = (uint8_t*)vdata;
while(bytes--) *data++ = read();
}
auto readl(uint bytes) -> uintmax {
uintmax data = 0;
for(auto n : range(bytes)) data |= (uintmax)read() << n * 8;
return data;
}
auto readm(uint bytes) -> uintmax {
uintmax data = 0;
for(auto n : range(bytes)) data = data << 8 | read();
return data;
}
auto reads() -> string {
string s;
s.resize(size());
read(s.get<uint8_t>(), s.size());
return s;
}
auto write(const void* vdata, uintmax bytes) -> void {
auto data = (const uint8_t*)vdata;
while(bytes--) write(*data++);
}
auto writel(uintmax data, uint bytes) -> void {
for(auto n : range(bytes)) write(data), data >>= 8;
}
auto writem(uintmax data, uint bytes) -> void {
for(auto n : rrange(bytes)) write(data >> n * 8);
}
auto writes(const string& s) -> void {
write(s.data<uint8_t>(), s.size());
}
};
}}
namespace nall { namespace vfs { namespace shared {
using file = shared_pointer<vfs::file>;
}}}
#include <nall/vfs/fs/file.hpp>
#include <nall/vfs/memory/file.hpp>