DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
7.8KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DISTRHO_DEFINES_H_INCLUDED
  17. #define DISTRHO_DEFINES_H_INCLUDED
  18. /* Compatibility with non-clang compilers */
  19. #ifndef __has_feature
  20. # define __has_feature(x) 0
  21. #endif
  22. #ifndef __has_extension
  23. # define __has_extension __has_feature
  24. #endif
  25. /* Check OS */
  26. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
  27. # define DISTRHO_PLUGIN_EXPORT extern "C" __declspec (dllexport)
  28. # define DISTRHO_OS_WINDOWS 1
  29. # define DISTRHO_DLL_EXTENSION "dll"
  30. #else
  31. # define DISTRHO_PLUGIN_EXPORT extern "C" __attribute__ ((visibility("default")))
  32. # if defined(__APPLE__)
  33. # define DISTRHO_OS_MAC 1
  34. # define DISTRHO_DLL_EXTENSION "dylib"
  35. # elif defined(__HAIKU__)
  36. # define DISTRHO_OS_HAIKU 1
  37. # elif defined(__linux__) || defined(__linux)
  38. # define DISTRHO_OS_LINUX 1
  39. # endif
  40. #endif
  41. #ifndef DISTRHO_DLL_EXTENSION
  42. # define DISTRHO_DLL_EXTENSION "so"
  43. #endif
  44. /* Check for C++11 support */
  45. #if defined(HAVE_CPP11_SUPPORT)
  46. # if HAVE_CPP11_SUPPORT
  47. # define DISTRHO_PROPER_CPP11_SUPPORT
  48. # endif
  49. #elif __cplusplus >= 201103L || (defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405) || __has_extension(cxx_noexcept)
  50. # define DISTRHO_PROPER_CPP11_SUPPORT
  51. # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407 && ! defined(__clang__)) || (defined(__clang__) && ! __has_extension(cxx_override_control))
  52. # define override // gcc4.7+ only
  53. # define final // gcc4.7+ only
  54. # endif
  55. #endif
  56. #ifndef DISTRHO_PROPER_CPP11_SUPPORT
  57. # define noexcept throw()
  58. # define override
  59. # define final
  60. # define nullptr NULL
  61. #endif
  62. /* Define DISTRHO_DEPRECATED */
  63. #if defined(__GNUC__)
  64. # define DISTRHO_DEPRECATED __attribute__((deprecated))
  65. #elif defined(_MSC_VER)
  66. # define DISTRHO_DEPRECATED __declspec(deprecated)
  67. #else
  68. # define DISTRHO_DEPRECATED
  69. #endif
  70. /* Define DISTRHO_SAFE_ASSERT* */
  71. #define DISTRHO_SAFE_ASSERT(cond) if (! (cond)) d_safe_assert(#cond, __FILE__, __LINE__);
  72. #define DISTRHO_SAFE_ASSERT_BREAK(cond) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); break; }
  73. #define DISTRHO_SAFE_ASSERT_CONTINUE(cond) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); continue; }
  74. #define DISTRHO_SAFE_ASSERT_RETURN(cond, ret) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  75. #define DISTRHO_SAFE_ASSERT_INT_BREAK(cond, value) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value); break; }
  76. #define DISTRHO_SAFE_ASSERT_INT_CONTINUE(cond, value) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); continue; }
  77. #define DISTRHO_SAFE_ASSERT_INT_RETURN(cond, value, ret) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); return ret; }
  78. #define DISTRHO_SAFE_ASSERT_INT2_BREAK(cond, v1, v2) if (! (cond)) { d_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); break; }
  79. #define DISTRHO_SAFE_ASSERT_INT2_CONTINUE(cond, v1, v2) if (! (cond)) { d_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); continue; }
  80. #define DISTRHO_SAFE_ASSERT_INT2_RETURN(cond, v1, v2, ret) if (! (cond)) { d_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); return ret; }
  81. #define DISTRHO_SAFE_ASSERT_UINT_BREAK(cond, value) if (! (cond)) { d_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value); break; }
  82. #define DISTRHO_SAFE_ASSERT_UINT_CONTINUE(cond, value) if (! (cond)) { d_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); continue; }
  83. #define DISTRHO_SAFE_ASSERT_UINT_RETURN(cond, value, ret) if (! (cond)) { d_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); return ret; }
  84. #define DISTRHO_SAFE_ASSERT_UINT2_BREAK(cond, v1, v2) if (! (cond)) { d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); break; }
  85. #define DISTRHO_SAFE_ASSERT_UINT2_CONTINUE(cond, v1, v2) if (! (cond)) { d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); continue; }
  86. #define DISTRHO_SAFE_ASSERT_UINT2_RETURN(cond, v1, v2, ret) if (! (cond)) { d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); return ret; }
  87. /* Define DISTRHO_SAFE_EXCEPTION */
  88. #define DISTRHO_SAFE_EXCEPTION(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); }
  89. #define DISTRHO_SAFE_EXCEPTION_BREAK(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); break; }
  90. #define DISTRHO_SAFE_EXCEPTION_CONTINUE(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); continue; }
  91. #define DISTRHO_SAFE_EXCEPTION_RETURN(msg, ret) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); return ret; }
  92. /* Define DISTRHO_DECLARE_NON_COPY_CLASS */
  93. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  94. # define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \
  95. private: \
  96. ClassName(ClassName&) = delete; \
  97. ClassName(const ClassName&) = delete; \
  98. ClassName& operator=(ClassName&) = delete ; \
  99. ClassName& operator=(const ClassName&) = delete;
  100. #else
  101. # define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \
  102. private: \
  103. ClassName(ClassName&); \
  104. ClassName(const ClassName&); \
  105. ClassName& operator=(ClassName&); \
  106. ClassName& operator=(const ClassName&);
  107. #endif
  108. /* Define DISTRHO_DECLARE_NON_COPY_STRUCT */
  109. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  110. # define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) \
  111. StructName(StructName&) = delete; \
  112. StructName(const StructName&) = delete; \
  113. StructName& operator=(StructName&) = delete; \
  114. StructName& operator=(const StructName&) = delete;
  115. #else
  116. # define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) \
  117. private: \
  118. StructName(StructName&); \
  119. StructName(const StructName&); \
  120. StructName& operator=(StructName&); \
  121. StructName& operator=(const StructName&);
  122. #endif
  123. /* Define DISTRHO_PREVENT_HEAP_ALLOCATION */
  124. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  125. # define DISTRHO_PREVENT_HEAP_ALLOCATION \
  126. private: \
  127. static void* operator new(size_t) = delete; \
  128. static void operator delete(void*) = delete;
  129. #else
  130. # define DISTRHO_PREVENT_HEAP_ALLOCATION \
  131. private: \
  132. static void* operator new(size_t); \
  133. static void operator delete(void*);
  134. #endif
  135. /* Define namespace */
  136. #ifndef DISTRHO_NAMESPACE
  137. # define DISTRHO_NAMESPACE DISTRHO
  138. #endif
  139. #define START_NAMESPACE_DISTRHO namespace DISTRHO_NAMESPACE {
  140. #define END_NAMESPACE_DISTRHO }
  141. #define USE_NAMESPACE_DISTRHO using namespace DISTRHO_NAMESPACE;
  142. /* Useful typedefs */
  143. typedef unsigned char uchar;
  144. typedef unsigned short int ushort;
  145. typedef unsigned int uint;
  146. typedef unsigned long int ulong;
  147. #endif // DISTRHO_DEFINES_H_INCLUDED