disk.hpp 997 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include <nall/file.hpp>
  3. namespace nall::vfs {
  4. struct disk : file {
  5. static auto open(string location_, mode mode_) -> shared_pointer<disk> {
  6. auto instance = shared_pointer<disk>{new disk};
  7. if(!instance->_open(location_, mode_)) return {};
  8. return instance;
  9. }
  10. auto size() const -> uintmax override {
  11. return _fp.size();
  12. }
  13. auto offset() const -> uintmax override {
  14. return _fp.offset();
  15. }
  16. auto seek(intmax offset_, index index_) -> void override {
  17. _fp.seek(offset_, (uint)index_);
  18. }
  19. auto read() -> uint8_t override {
  20. return _fp.read();
  21. }
  22. auto write(uint8_t data_) -> void override {
  23. _fp.write(data_);
  24. }
  25. auto flush() -> void override {
  26. _fp.flush();
  27. }
  28. private:
  29. disk() = default;
  30. disk(const disk&) = delete;
  31. auto operator=(const disk&) -> disk& = delete;
  32. auto _open(string location_, mode mode_) -> bool {
  33. if(!_fp.open(location_, (uint)mode_)) return false;
  34. return true;
  35. }
  36. file_buffer _fp;
  37. };
  38. }