wut  1.0.0-beta8
Wii U Toolchain
result.h
Go to the documentation of this file.
1 #pragma once
2 #include <wut.h>
3 
11 typedef struct NNResult NNResult;
12 
19 struct NNResult
20 {
22  int32_t value;
23 };
24 
37 static inline int NNResult_IsSuccess(NNResult result)
38 {
39  return result.value >= 0;
40 }
41 
54 static inline int NNResult_IsFailure(NNResult result)
55 {
56  return result.value < 0;
57 }
58 
59 #ifdef __cplusplus
60 
61 namespace nn
62 {
63 
67 class Result
68 {
69 public:
70  enum Level
71  {
76  LEVEL_END = -7,
77  };
78 
80  {
86  };
87 
88  enum Module
89  {
112  };
113 
115  {
133  MODULE_NN_FS = 0x11,
134  MODULE_NN_DI = 0x12,
137  MODULE_NN_PI = 0x15,
138  MODULE_NN_PM = 0x16,
148  MODULE_NN_AM = 0x20,
153  MODULE_NN_MP = 0x25,
155  MODULE_NN_AC = 0x27,
171  MODULE_NN_MC = 0x37,
181  MODULE_NN_PS = 0x41,
183  MODULE_NN_IR = 0x43,
185  MODULE_NN_PL = 0x45,
189  MODULE_NN_NS = 0x49,
191  MODULE_NN_RO = 0x4B,
192  MODULE_NN_GD = 0x4C,
194  MODULE_NN_EC = 0x4E,
200  };
201 
203  {
216  };
217 
219  {
221  };
222 
223 public:
224  Result(Level level, Module module, unsigned description) :
225  mDescription(description),
226  mModule(module),
227  mLevel(level)
228  {
229  }
230 
231  Result(const NNResult &result) :
232  mValue(result.value)
233  {
234  }
235 
245  bool IsFailure() const
246  {
247  return !IsSuccess();
248  }
249 
259  bool IsSuccess() const
260  {
261  return mLevel >= 0;
262  }
263 
264  bool IsLegacy() const
265  {
266  return mLegacy.signature == SIGNATURE_IS_LEGACY;
267  }
268 
269  unsigned GetDescription() const
270  {
271  if (IsLegacy()) {
272  return mLegacy.description;
273  }
274 
275  return mDescription;
276  }
277 
278  int GetLevel() const
279  {
280  if (IsLegacy()) {
281  return mLegacy.level;
282  }
283 
284  return mLevel;
285  }
286 
287  unsigned GetModule() const
288  {
289  if (IsLegacy()) {
290  return mLegacy.module;
291  }
292 
293  return mModule;
294  }
295 
296  unsigned GetSummary() const
297  {
298  if (IsLegacy()) {
299  return mLegacy.summary;
300  }
301 
302  return 0;
303  }
304 
305  operator bool() const
306  {
307  return IsSuccess();
308  }
309 
310  operator NNResult() const
311  {
312  NNResult result;
313  result.value = mValue;
314  return result;
315  }
316 
317  bool operator==(const Result &other) const
318  {
319  return mValue == other.mValue;
320  }
321 
322  bool operator!=(const Result &other) const
323  {
324  return mValue != other.mValue;
325  }
326 
327 private:
328  union {
329  struct {
330  uint32_t description : 10;
331  uint32_t summary : 4;
332  int32_t level : 4;
333  uint32_t : 2;
334  uint32_t module : 7;
335  uint32_t signature : 2;
336  } mLegacy;
337 
338  struct {
339  uint32_t mDescription : 20;
340  uint32_t mModule : 9;
341  int32_t mLevel : 3;
342  };
343 
344  int32_t mValue;
345  };
346 };
347 
348 } // namespace nn
349 
350 #endif // ifdef __cplusplus
351 
Result structure for nn libraries.
Definition: result.h:19
bool IsSuccess() const
Determine if the Result instance represents a successful state.
Definition: result.h:259
Result value type used by nn libraries.
Definition: result.h:67
LegacySummary
Definition: result.h:202
static int NNResult_IsSuccess(NNResult result)
Determine if a NNResult represents a successful state.
Definition: result.h:37
int GetLevel() const
Definition: result.h:278
Definition: ac_cpp.h:14
bool operator!=(const Result &other) const
Definition: result.h:322
bool operator==(const Result &other) const
Definition: result.h:317
Result(const NNResult &result)
Definition: result.h:231
unsigned GetSummary() const
Definition: result.h:296
LegacySignature
Definition: result.h:218
bool IsFailure() const
Determine if the Result instance represents a failure.
Definition: result.h:245
int32_t value
Aggregate value of result bitfield.
Definition: result.h:22
bool IsLegacy() const
Definition: result.h:264
static int NNResult_IsFailure(NNResult result)
Determine if a NNResult represents a failure.
Definition: result.h:54
struct NNResult NNResult
Definition: result.h:11
Result(Level level, Module module, unsigned description)
Definition: result.h:224
unsigned GetModule() const
Definition: result.h:287
LegacyLevel
Definition: result.h:79
unsigned GetDescription() const
Definition: result.h:269
LegacyModule
Definition: result.h:114