| 1 | /** |
| 2 | * @file util.h |
| 3 | * @brief Helper functions for OS functionality. |
| 4 | */ |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <cstdarg> |
| 9 | #include <nn/types.h> |
| 10 | |
| 11 | namespace nn { |
| 12 | namespace util { |
| 13 | |
| 14 | enum CharacterEncodingResult { Success, BadLength, InvalidFormat }; |
| 15 | |
| 16 | CharacterEncodingResult PickOutCharacterFromUtf8String(char*, char const** str); |
| 17 | CharacterEncodingResult ConvertCharacterUtf8ToUtf32(u32* dest, char const* src); |
| 18 | CharacterEncodingResult ConvertStringUtf16NativeToUtf8(char*, s32, u16 const*, s32); |
| 19 | CharacterEncodingResult ConvertStringUtf8ToUtf16Native(u16*, s32, char const*, s32); |
| 20 | |
| 21 | s32 SNPrintf(char* s, ulong n, const char* format, ...); |
| 22 | s32 VSNPrintf(char* s, ulong n, const char* format, va_list arg); |
| 23 | |
| 24 | void ReferSymbol(const void*); |
| 25 | } // namespace util |
| 26 | } // namespace nn |
| 27 | |
| 28 | #define NN_MAKE_VER(major, minor, patch) (((major) << 16) | ((minor) << 8) | (patch)) |
| 29 | |
| 30 | #ifdef NN_SDK_MAJOR |
| 31 | #define NN_SDK_VER NN_MAKE_VER(NN_SDK_MAJOR, NN_SDK_MINOR, NN_SDK_PATCH) |
| 32 | #else |
| 33 | #define NN_SDK_VER 0 |
| 34 | #define NN_SDK_MAJOR 0 |
| 35 | #define NN_SDK_MINOR 0 |
| 36 | #define NN_SDK_PATCH 0 |
| 37 | #endif |
| 38 | |
| 39 | #ifdef NN_WARE_MAJOR |
| 40 | #define NN_WARE_VER NN_MAKE_VER(NN_WARE_MAJOR, NN_WARE_MINOR, NN_WARE_PATCH) |
| 41 | #else |
| 42 | #define NN_WARE_VER 0 |
| 43 | #define NN_WARE_MAJOR 0 |
| 44 | #define NN_WARE_MINOR 0 |
| 45 | #define NN_WARE_PATCH 0 |
| 46 | #endif |
| 47 | |
| 48 | #ifndef NN_SDK_TYPE |
| 49 | #define NN_SDK_TYPE "Release" |
| 50 | #endif |
| 51 | |
| 52 | #define NN_STR(s) #s |
| 53 | #define NN_XSTR(s) NN_STR(s) |
| 54 | |
| 55 | #define NN_SDK_BUILD_STR \ |
| 56 | "-" NN_XSTR(NN_SDK_MAJOR) "_" NN_XSTR(NN_SDK_MINOR) "_" NN_XSTR(NN_SDK_PATCH) "-" NN_SDK_TYPE |
| 57 | |
| 58 | #define NN_MIDDLEWARE(var, company, name) \ |
| 59 | static const char var[] __attribute__((section(".api_info"))) = "SDK MW+" company "+" name |
| 60 | |
| 61 | // todo: move/rename with more info |
| 62 | #define NN_NO_COPY(CLASS) \ |
| 63 | CLASS(const CLASS&) = delete; \ |
| 64 | CLASS& operator=(const CLASS&) = delete |
| 65 | |
| 66 | #define NN_NO_MOVE(CLASS) \ |
| 67 | CLASS(CLASS&&) = delete; \ |
| 68 | CLASS& operator=(CLASS&&) = delete |
| 69 | |
| 70 | namespace nn::detail { |
| 71 | |
| 72 | [[noreturn]] void UnexpectedDefaultImpl(const char*, const char*, int); |
| 73 | |
| 74 | } // namespace nn::detail |
| 75 | |
| 76 | // todo: ifdef to support debug functionality? |
| 77 | #define NN_UNEXPECTED_DEFAULT nn::detail::UnexpectedDefaultImpl("", "", 0) |
| 78 | |