wut  v1.7.0
Wii U Toolchain
FileStream.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <coreinit/filesystem.h>
4 #include <nn/result.h>
5 #include <nn/sl/IStream.h>
7 #include <wut.h>
8 
9 #ifdef __cplusplus
10 
11 namespace nn::sl {
12  namespace details {
13  typedef struct WUT_PACKED FileStreamInternal {
14  void *vtable;
19  WUT_CHECK_SIZE(FileStreamInternal, 0x10);
20  WUT_CHECK_OFFSET(FileStreamInternal, 0x00, vtable);
21  WUT_CHECK_OFFSET(FileStreamInternal, 0x04, fsClient);
22  WUT_CHECK_OFFSET(FileStreamInternal, 0x08, fsCmdBlock);
23  WUT_CHECK_OFFSET(FileStreamInternal, 0x0C, fileHandle);
24 
28  } // namespace details
29 
31  public:
34  }
35 
36  ~FileStream() override {
37  __dt__Q3_2nn2sl10FileStreamFv(&mInstance, 2);
38  }
39 
40  nn::Result Read(uint32_t *bytesRead, void *buffer, uint32_t readSize) override {
41  auto *base = reinterpret_cast<details::IStreamInternal *>(&mInstance);
42  return base->vtable->ReadFn(base, bytesRead, buffer, readSize);
43  }
44  nn::Result Write(uint32_t *bytesWritten, void *buffer, uint32_t readSize) override {
45  auto *base = reinterpret_cast<details::IStreamInternal *>(&mInstance);
46  return base->vtable->WriteFn(base, bytesWritten, buffer, readSize);
47  }
48  nn::Result GetSize(uint32_t *fileSize) override {
49  auto *base = reinterpret_cast<details::IStreamInternal *>(&mInstance);
50  return base->vtable->GetSizeFn(base, fileSize);
51  }
52  nn::Result Seek(int32_t offset, nn::sl::SeekOrigin seekOrigin) override {
53  auto *base = reinterpret_cast<details::IStreamInternal *>(&mInstance);
54  return base->vtable->SeekFn(base, offset, seekOrigin);
55  }
56 
60  nn::Result Initialize(FSClient *client, FSCmdBlock *cmdBlock, char const *path, char const *mode) {
61  return Initialize__Q3_2nn2sl10FileStreamFP8FSClientP10FSCmdBlockPCcT3(&mInstance, client, cmdBlock, path, mode);
62  }
63 
65  return reinterpret_cast<details::IStreamInternal *>(&mInstance);
66  }
67 
68  private:
69  details::FileStreamInternal mInstance = {};
70  };
71 
72 }; // namespace nn::sl
73 
74 #endif
Result value type used by nn libraries.
Definition: result.h:68
nn::Result Initialize(FSClient *client, FSCmdBlock *cmdBlock, char const *path, char const *mode)
The given client and cmd must be valid during the whole liftime of the filestream.
Definition: FileStream.h:60
nn::Result GetSize(uint32_t *fileSize) override
Definition: FileStream.h:48
nn::Result Read(uint32_t *bytesRead, void *buffer, uint32_t readSize) override
Definition: FileStream.h:40
~FileStream() override
Definition: FileStream.h:36
nn::Result Write(uint32_t *bytesWritten, void *buffer, uint32_t readSize) override
Definition: FileStream.h:44
details::IStreamInternal * GetInternal() override
Definition: FileStream.h:64
nn::Result Seek(int32_t offset, nn::sl::SeekOrigin seekOrigin) override
Definition: FileStream.h:52
uint32_t FSFileHandle
Definition: filesystem.h:32
FileStreamInternal * __ct__Q3_2nn2sl10FileStreamFv(FileStreamInternal *)
struct nn::sl::details::FileStreamInternal FileStreamInternal
IStreamInternalVTable * vtable
void __dt__Q3_2nn2sl10FileStreamFv(FileStreamInternal *, int)
nn::Result Initialize__Q3_2nn2sl10FileStreamFP8FSClientP10FSCmdBlockPCcT3(FileStreamInternal *, FSClient *, FSCmdBlock *, char const *, char const *)
SeekOrigin
Definition: sl_cpp.h:266