1 //----------------------------------------------------------------------------- 2 // Project : SDK Core 3 // 4 // Category : SDK Core Interfaces 5 // Filename : pluginterfaces/base/ftypes.h 6 // Created by : Steinberg, 01/2004 7 // Description : Basic data types 8 // 9 //----------------------------------------------------------------------------- 10 // This file is part of a Steinberg SDK. It is subject to the license terms 11 // in the LICENSE file found in the top-level directory of this distribution 12 // and at www.steinberg.net/sdklicenses. 13 // No part of the SDK, including this file, may be copied, modified, propagated, 14 // or distributed except according to the terms contained in the LICENSE file. 15 //----------------------------------------------------------------------------- 16 17 #pragma once 18 19 #include "fplatform.h" 20 21 //#define UNICODE_OFF // disable / enable unicode 22 23 #ifdef UNICODE_OFF 24 #ifdef UNICODE 25 #undef UNICODE 26 #endif 27 #else 28 #define UNICODE 1 29 #endif 30 31 #ifdef UNICODE 32 #define _UNICODE 1 33 #endif 34 35 namespace Steinberg 36 { 37 //----------------------------------------------------------------- 38 // Integral Types 39 typedef char int8; 40 typedef unsigned char uint8; 41 typedef unsigned char uchar; 42 43 typedef short int16; 44 typedef unsigned short uint16; 45 46 #if SMTG_OS_WINDOWS && !defined(__GNUC__) 47 typedef long int32; 48 typedef unsigned long uint32; 49 #else 50 typedef int int32; 51 typedef unsigned int uint32; 52 #endif 53 54 static const int32 kMaxLong = 0x7fffffff; 55 static const int32 kMinLong = (-0x7fffffff - 1); 56 static const int32 kMaxInt32 = kMaxLong; 57 static const int32 kMinInt32 = kMinLong; 58 static const uint32 kMaxInt32u = 0xffffffff; 59 60 #if SMTG_OS_WINDOWS && !defined(__GNUC__) 61 typedef __int64 int64; 62 typedef unsigned __int64 uint64; 63 static const int64 kMaxInt64 = 9223372036854775807i64; 64 static const int64 kMinInt64 = (-9223372036854775807i64 - 1); 65 #else 66 typedef long long int64; 67 typedef unsigned long long uint64; 68 static const int64 kMaxInt64 = 0x7fffffffffffffffLL; 69 static const int64 kMinInt64 = (-0x7fffffffffffffffLL-1); 70 #endif 71 static const uint64 kMaxInt64u = uint64 (0xffffffff) | (uint64 (0xffffffff) << 32); 72 73 //----------------------------------------------------------------- 74 // other Semantic Types 75 typedef int64 TSize; // byte (or other) sizes 76 typedef int32 tresult; // result code 77 //----------------------------------------------------------------- 78 static const float kMaxFloat = 3.40282346638528860E38; 79 static const double kMaxDouble = 1.7976931348623158E308; 80 81 #if SMTG_PLATFORM_64 82 typedef uint64 TPtrInt; 83 #else 84 typedef uint32 TPtrInt; 85 #endif 86 87 //------------------------------------------------------------------ 88 // Boolean 89 typedef uint8 TBool; 90 91 //------------------------------------------------------------------ 92 // Char / Strings 93 typedef char char8; 94 #ifdef _NATIVE_WCHAR_T_DEFINED 95 typedef __wchar_t char16; 96 #elif SMTG_CPP11 97 typedef char16_t char16; 98 #else 99 typedef int16 char16; 100 #endif 101 102 #ifdef UNICODE 103 typedef char16 tchar; 104 #else 105 typedef char8 tchar; 106 #endif 107 108 typedef const char8* CStringA; 109 typedef const char16* CStringW; 110 typedef const tchar* CString; strEmpty(const tchar * str)111 inline bool strEmpty (const tchar* str) { return (!str || *str == 0); } str8Empty(const char8 * str)112 inline bool str8Empty (const char8* str) { return (!str || *str == 0); } str16Empty(const char16 * str)113 inline bool str16Empty (const char16* str) { return (!str || *str == 0); } 114 115 typedef const char8* FIDString; // identifier as string (used for attributes, messages) 116 117 const FIDString kPlatformStringWin = "WIN"; 118 const FIDString kPlatformStringMac = "MAC"; 119 const FIDString kPlatformStringIOS = "IOS"; 120 const FIDString kPlatformStringLinux = "Linux"; 121 #if SMTG_OS_WINDOWS 122 const FIDString kPlatformString = kPlatformStringWin; 123 #elif SMTG_OS_IOS 124 const FIDString kPlatformString = kPlatformStringIOS; 125 #elif SMTG_OS_MACOS 126 const FIDString kPlatformString = kPlatformStringMac; 127 #elif SMTG_OS_LINUX 128 const FIDString kPlatformString = kPlatformStringLinux; 129 #endif 130 131 //------------------------------------------------------------------------ 132 /** Coordinates */ 133 typedef int32 UCoord; 134 static const UCoord kMaxCoord = ((UCoord)0x7FFFFFFF); 135 static const UCoord kMinCoord = ((UCoord)-0x7FFFFFFF); 136 } // namespace Steinberg 137 138 139 //---------------------------------------------------------------------------- 140 /** Byte-order Conversion Macros */ 141 //---------------------------------------------------------------------------- 142 #define SWAP_32(l) { \ 143 unsigned char* p = (unsigned char*)& (l); \ 144 unsigned char t; \ 145 t = p[0]; p[0] = p[3]; p[3] = t; t = p[1]; p[1] = p[2]; p[2] = t; } 146 147 #define SWAP_16(w) { \ 148 unsigned char* p = (unsigned char*)& (w); \ 149 unsigned char t; \ 150 t = p[0]; p[0] = p[1]; p[1] = t; } 151 152 #define SWAP_64(i) { \ 153 unsigned char* p = (unsigned char*)& (i); \ 154 unsigned char t; \ 155 t = p[0]; p[0] = p[7]; p[7] = t; t = p[1]; p[1] = p[6]; p[6] = t; \ 156 t = p[2]; p[2] = p[5]; p[5] = t; t = p[3]; p[3] = p[4]; p[4] = t;} 157 158 namespace Steinberg 159 { FSwap(int8 &)160 static inline void FSwap (int8&) {} FSwap(uint8 &)161 static inline void FSwap (uint8&) {} FSwap(int16 & i16)162 static inline void FSwap (int16& i16) { SWAP_16 (i16) } FSwap(uint16 & i16)163 static inline void FSwap (uint16& i16) { SWAP_16 (i16) } FSwap(int32 & i32)164 static inline void FSwap (int32& i32) { SWAP_32 (i32) } FSwap(uint32 & i32)165 static inline void FSwap (uint32& i32) { SWAP_32 (i32) } FSwap(int64 & i64)166 static inline void FSwap (int64& i64) { SWAP_64 (i64) } FSwap(uint64 & i64)167 static inline void FSwap (uint64& i64) { SWAP_64 (i64) } 168 } 169 170 // always inline macros (only when RELEASE is 1) 171 //---------------------------------------------------------------------------- 172 #if RELEASE 173 #if SMTG_OS_MACOS || SMTG_OS_LINUX 174 #define SMTG_ALWAYS_INLINE __inline__ __attribute__((__always_inline__)) 175 #define SMTG_NEVER_INLINE __attribute__((noinline)) 176 #elif SMTG_OS_WINDOWS 177 #define SMTG_ALWAYS_INLINE __forceinline 178 #define SMTG_NEVER_INLINE __declspec(noinline) 179 #endif 180 #endif 181 182 #ifndef SMTG_ALWAYS_INLINE 183 #define SMTG_ALWAYS_INLINE inline 184 #endif 185 #ifndef SMTG_NEVER_INLINE 186 #define SMTG_NEVER_INLINE 187 #endif 188 189 #ifndef SMTG_CPP11_STDLIBSUPPORT 190 // Enable this for old compilers 191 // #define nullptr NULL 192 #endif 193