wut  1.0.0-alpha
Wii U Toolchain
result.h
Go to the documentation of this file.
1 #pragma once
2 #include <wut.h>
3 
13 typedef struct NNResult NNResult;
14 
15 struct NNResult
16 {
17  int32_t value;
18 };
19 
20 static inline int NNResult_IsSuccess(NNResult result)
21 {
22  return result.value >= 0;
23 }
24 
25 static inline int NNResult_IsFailure(NNResult result)
26 {
27  return result.value < 0;
28 }
29 
30 #ifdef __cplusplus
31 
32 namespace nn
33 {
34 
38 class Result
39 {
40 public:
41  enum Level
42  {
47  LEVEL_END = -7,
48  };
49 
51  {
57  };
58 
59  enum Module
60  {
83  };
84 
86  {
97  MODULE_NN_GX = 0xA,
104  MODULE_NN_FS = 0x11,
105  MODULE_NN_DI = 0x12,
108  MODULE_NN_PI = 0x15,
109  MODULE_NN_PM = 0x16,
119  MODULE_NN_AM = 0x20,
124  MODULE_NN_MP = 0x25,
126  MODULE_NN_AC = 0x27,
142  MODULE_NN_MC = 0x37,
152  MODULE_NN_PS = 0x41,
154  MODULE_NN_IR = 0x43,
156  MODULE_NN_PL = 0x45,
160  MODULE_NN_NS = 0x49,
162  MODULE_NN_RO = 0x4B,
163  MODULE_NN_GD = 0x4C,
165  MODULE_NN_EC = 0x4E,
171  };
172 
174  {
187  };
188 
190  {
192  };
193 
194 public:
195  Result(Level level, Module module, unsigned description) :
196  mDescription(description),
197  mModule(module),
198  mLevel(level)
199  {
200  }
201 
202  Result(const NNResult &result) :
203  mValue(result.value)
204  {
205  }
206 
207  bool IsFailure() const
208  {
209  return !IsSuccess();
210  }
211 
212  bool IsSuccess() const
213  {
214  return mLevel >= 0;
215  }
216 
217  bool IsLegacy() const
218  {
219  return mLegacy.signature == SIGNATURE_IS_LEGACY;
220  }
221 
222  unsigned GetDescription() const
223  {
224  if (IsLegacy()) {
225  return mLegacy.description;
226  }
227 
228  return mDescription;
229  }
230 
231  int GetLevel() const
232  {
233  if (IsLegacy()) {
234  return mLegacy.level;
235  }
236 
237  return mLevel;
238  }
239 
240  unsigned GetModule() const
241  {
242  if (IsLegacy()) {
243  return mLegacy.module;
244  }
245 
246  return mModule;
247  }
248 
249  unsigned GetSummary() const
250  {
251  if (IsLegacy()) {
252  return mLegacy.summary;
253  }
254 
255  return 0;
256  }
257 
258  operator bool() const
259  {
260  return IsSuccess();
261  }
262 
263  operator NNResult() const
264  {
265  NNResult result;
266  result.value = mValue;
267  return result;
268  }
269 
270  bool operator==(const Result &other) const
271  {
272  return mValue == other.mValue;
273  }
274 
275  bool operator!=(const Result &other) const
276  {
277  return mValue != other.mValue;
278  }
279 
280 private:
281  union {
282  struct {
283  uint32_t description : 10;
284  uint32_t summary : 4;
285  int32_t level : 4;
286  uint32_t : 2;
287  uint32_t module : 7;
288  uint32_t signature : 2;
289  } mLegacy;
290 
291  struct {
292  uint32_t mDescription : 20;
293  uint32_t mModule : 9;
294  int32_t mLevel : 3;
295  };
296 
297  int32_t mValue;
298  };
299 };
300 
301 } // namespace nn
302 
303 #endif // ifdef __cplusplus
304 
bool IsSuccess() const
Definition: result.h:212
Result value type used by nn libraries.
Definition: result.h:38
LegacySummary
Definition: result.h:173
static int NNResult_IsSuccess(NNResult result)
Definition: result.h:20
int GetLevel() const
Definition: result.h:231
Definition: ac_cpp.h:13
bool operator!=(const Result &other) const
Definition: result.h:275
bool operator==(const Result &other) const
Definition: result.h:270
Result(const NNResult &result)
Definition: result.h:202
unsigned GetSummary() const
Definition: result.h:249
LegacySignature
Definition: result.h:189
bool IsFailure() const
Definition: result.h:207
int32_t value
Definition: result.h:17
bool IsLegacy() const
Definition: result.h:217
static int NNResult_IsFailure(NNResult result)
Definition: result.h:25
struct NNResult NNResult
C equivalent of the C++ nn::Result.
Definition: result.h:13
Result(Level level, Module module, unsigned description)
Definition: result.h:195
unsigned GetModule() const
Definition: result.h:240
LegacyLevel
Definition: result.h:50
unsigned GetDescription() const
Definition: result.h:222
LegacyModule
Definition: result.h:85