wut  v1.7.0
Wii U Toolchain
IStream.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <nn/result.h>
5 #include <nn/sl/sl_cpp.h>
6 #include <wut.h>
7 
8 #ifdef __cplusplus
9 
10 namespace nn::sl {
11  class IStream : public details::IStreamBase {
12 
13  public:
14  IStream() {
15  InitInternalVtable();
16  }
17 
18  IStream(IStream &src) {
19  InitInternalVtable();
20  }
21 
22  IStream &operator=(const IStream &other) {
23  InitInternalVtable();
24  return *this;
25  }
26 
27  IStream &operator=(IStream &&src) noexcept {
28  InitInternalVtable();
29  return *this;
30  }
31 
32  ~IStream() override = default;
33 
34  private:
35  static nn::Result ReadWrapper(details::IStreamInternal *instance, uint32_t *bytesRead, void *buffer, uint32_t readSize) {
36  return instance->vtable->instance->Read(bytesRead, buffer, readSize);
37  }
38 
39  static nn::Result WriteWrapper(details::IStreamInternal *instance, uint32_t *bytesWritten, void *buffer, uint32_t readSize) {
40  return instance->vtable->instance->Write(bytesWritten, buffer, readSize);
41  }
42 
43  static nn::Result GetSizeWrapper(details::IStreamInternal *instance, uint32_t *fileSize) {
44  return instance->vtable->instance->GetSize(fileSize);
45  }
46 
47  static nn::Result SeekWrapper(details::IStreamInternal *instance, int32_t offset, nn::sl::SeekOrigin seekOrigin) {
48  return instance->vtable->instance->Seek(offset, seekOrigin);
49  }
50 
51  details::IStreamInternal *GetInternal() override {
52  return &mInstance;
53  }
54 
55  void InitInternalVtable() {
56  mVTable = {.instance = this,
57  .ReadFn = &ReadWrapper,
58  .WriteFn = &WriteWrapper,
59  .GetSizeFn = &GetSizeWrapper,
60  .SeekFn = &SeekWrapper};
61  mInstance.vtable = &mVTable;
62  }
63 
64  details::IStreamInternal mInstance{};
65  details::IStreamInternalVTable mVTable{};
66  };
67 } // namespace nn::sl
68 
69 #endif
Result value type used by nn libraries.
Definition: result.h:68
IStream & operator=(const IStream &other)
Definition: IStream.h:22
IStream(IStream &src)
Definition: IStream.h:18
IStream & operator=(IStream &&src) noexcept
Definition: IStream.h:27
~IStream() override=default
virtual nn::Result Read(uint32_t *bytesRead, void *buffer, uint32_t readSize)=0
virtual nn::Result Write(uint32_t *bytesWritten, void *buffer, uint32_t writeSize)=0
IStreamInternalVTable * vtable
struct nn::sl::details::IStreamInternal IStreamInternal
SeekOrigin
Definition: sl_cpp.h:266