diff --git a/include/common.hpp b/include/common.hpp index 54a7b526..ac789613 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -18,9 +18,6 @@ #include -namespace rack { - - /** Attribute for deprecated functions and symbols. E.g. @@ -120,6 +117,47 @@ to get its size in bytes. #endif +/** Helpful user-defined literals for specifying exact integer and float types. +Usage examples: + 123_i8 + -1234_u16 + 0x1000_i32 + 0b10000000_u64 + 12.3_f32 + 1e4_f64 +*/ +inline int8_t operator"" _i8(unsigned long long x) {return x;} +inline int16_t operator"" _i16(unsigned long long x) {return x;} +inline int32_t operator"" _i32(unsigned long long x) {return x;} +inline int64_t operator"" _i64(unsigned long long x) {return x;} +inline uint8_t operator"" _u8(unsigned long long x) {return x;} +inline uint16_t operator"" _u16(unsigned long long x) {return x;} +inline uint32_t operator"" _u32(unsigned long long x) {return x;} +inline uint64_t operator"" _u64(unsigned long long x) {return x;} +inline float operator"" _f32(long double x) {return x;} +inline double operator"" _f64(long double x) {return x;} + + +#if defined ARCH_WIN +// wchar_t on Windows should be 2 bytes +static_assert(sizeof(wchar_t) == 2); + +// Windows C standard functions are ASCII-8 instead of UTF-8, so redirect these functions to wrappers which convert to UTF-8 +#define fopen fopen_u8 + +extern "C" { +FILE* fopen_u8(const char* filename, const char* mode); +} + +namespace std { + using ::fopen_u8; +} +#endif + + +namespace rack { + + /** C#-style property constructor Example: @@ -213,20 +251,3 @@ extern const std::string API_VERSION; } // namespace rack - - -#if defined ARCH_WIN -// wchar_t on Windows should be 2 bytes -static_assert(sizeof(wchar_t) == 2); - -// Windows C standard functions are ASCII-8 instead of UTF-8, so redirect these functions to wrappers which convert to UTF-8 -#define fopen fopen_u8 - -extern "C" { -FILE* fopen_u8(const char* filename, const char* mode); -} - -namespace std { - using ::fopen_u8; -} -#endif diff --git a/src/common.cpp b/src/common.cpp index 3e47d6bb..b05671ad 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -2,6 +2,16 @@ #include +#if defined ARCH_WIN +#include + +FILE* fopen_u8(const char* filename, const char* mode) { + return _wfopen(rack::string::U8toU16(filename).c_str(), rack::string::U8toU16(mode).c_str()); +} + +#endif + + namespace rack { @@ -30,14 +40,3 @@ Exception::Exception(const char* format, ...) { } // namespace rack - - -#if defined ARCH_WIN -#include - -FILE* fopen_u8(const char* filename, const char* mode) { - return _wfopen(rack::string::U8toU16(filename).c_str(), rack::string::U8toU16(mode).c_str()); -} - - -#endif