The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

298 lines
9.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_PLATFORMDEFS_JUCEHEADER__
  19. #define __JUCE_PLATFORMDEFS_JUCEHEADER__
  20. //==============================================================================
  21. /* This file defines miscellaneous macros for debugging, assertions, etc.
  22. */
  23. //==============================================================================
  24. #ifdef JUCE_FORCE_DEBUG
  25. #undef JUCE_DEBUG
  26. #if JUCE_FORCE_DEBUG
  27. #define JUCE_DEBUG 1
  28. #endif
  29. #endif
  30. /** This macro defines the C calling convention used as the standard for Juce calls. */
  31. #if JUCE_MSVC
  32. #define JUCE_CALLTYPE __stdcall
  33. #define JUCE_CDECL __cdecl
  34. #else
  35. #define JUCE_CALLTYPE
  36. #define JUCE_CDECL
  37. #endif
  38. //==============================================================================
  39. // Debugging and assertion macros
  40. // (For info about JUCE_LOG_ASSERTIONS, have a look in juce_Config.h)
  41. #if JUCE_LOG_ASSERTIONS
  42. #define juce_LogCurrentAssertion juce_LogAssertion (__FILE__, __LINE__);
  43. #elif JUCE_DEBUG
  44. #define juce_LogCurrentAssertion std::cerr << "JUCE Assertion failure in " << __FILE__ << ", line " << __LINE__ << std::endl;
  45. #else
  46. #define juce_LogCurrentAssertion
  47. #endif
  48. #if JUCE_DEBUG
  49. //==============================================================================
  50. // If debugging is enabled..
  51. /** Writes a string to the standard error stream.
  52. This is only compiled in a debug build.
  53. @see Logger::outputDebugString
  54. */
  55. #define DBG(dbgtext) { JUCE_NAMESPACE::String tempDbgBuf; tempDbgBuf << dbgtext; JUCE_NAMESPACE::Logger::outputDebugString (tempDbgBuf); }
  56. //==============================================================================
  57. // Assertions..
  58. #if JUCE_WINDOWS || DOXYGEN
  59. #if JUCE_USE_INTRINSICS
  60. #pragma intrinsic (__debugbreak)
  61. /** This will try to break the debugger if one is currently hosting this app.
  62. @see jassert()
  63. */
  64. #define juce_breakDebugger __debugbreak();
  65. #elif JUCE_GCC
  66. /** This will try to break the debugger if one is currently hosting this app.
  67. @see jassert()
  68. */
  69. #define juce_breakDebugger asm("int $3");
  70. #else
  71. /** This will try to break the debugger if one is currently hosting this app.
  72. @see jassert()
  73. */
  74. #define juce_breakDebugger { __asm int 3 }
  75. #endif
  76. #elif JUCE_MAC
  77. #define juce_breakDebugger Debugger();
  78. #elif JUCE_IOS || JUCE_LINUX || JUCE_ANDROID
  79. #define juce_breakDebugger kill (0, SIGTRAP);
  80. #endif
  81. //==============================================================================
  82. /** This will always cause an assertion failure.
  83. It is only compiled in a debug build, (unless JUCE_LOG_ASSERTIONS is enabled
  84. in juce_Config.h).
  85. @see jassert()
  86. */
  87. #define jassertfalse { juce_LogCurrentAssertion; if (JUCE_NAMESPACE::juce_isRunningUnderDebugger()) juce_breakDebugger; }
  88. //==============================================================================
  89. /** Platform-independent assertion macro.
  90. This gets optimised out when not being built with debugging turned on.
  91. Be careful not to call any functions within its arguments that are vital to
  92. the behaviour of the program, because these won't get called in the release
  93. build.
  94. @see jassertfalse
  95. */
  96. #define jassert(expression) { if (! (expression)) jassertfalse; }
  97. #else
  98. //==============================================================================
  99. // If debugging is disabled, these dummy debug and assertion macros are used..
  100. #define DBG(dbgtext)
  101. #define jassertfalse { juce_LogCurrentAssertion }
  102. #if JUCE_LOG_ASSERTIONS
  103. #define jassert(expression) { if (! (expression)) jassertfalse; }
  104. #else
  105. #define jassert(a) { }
  106. #endif
  107. #endif
  108. //==============================================================================
  109. #ifndef DOXYGEN
  110. BEGIN_JUCE_NAMESPACE
  111. template <bool b> struct JuceStaticAssert;
  112. template <> struct JuceStaticAssert <true> { static void dummy() {} };
  113. END_JUCE_NAMESPACE
  114. #endif
  115. /** A compile-time assertion macro.
  116. If the expression parameter is false, the macro will cause a compile error.
  117. */
  118. #define static_jassert(expression) JUCE_NAMESPACE::JuceStaticAssert<expression>::dummy();
  119. /** This is a shorthand macro for declaring stubs for a class's copy constructor and
  120. operator=.
  121. For example, instead of
  122. @code
  123. class MyClass
  124. {
  125. etc..
  126. private:
  127. MyClass (const MyClass&);
  128. MyClass& operator= (const MyClass&);
  129. };@endcode
  130. ..you can just write:
  131. @code
  132. class MyClass
  133. {
  134. etc..
  135. private:
  136. JUCE_DECLARE_NON_COPYABLE (MyClass);
  137. };@endcode
  138. */
  139. #define JUCE_DECLARE_NON_COPYABLE(className) \
  140. className (const className&);\
  141. className& operator= (const className&)
  142. /** This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and
  143. JUCE_LEAK_DETECTOR macro for a class.
  144. */
  145. #define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className) \
  146. JUCE_DECLARE_NON_COPYABLE(className);\
  147. JUCE_LEAK_DETECTOR(className)
  148. //==============================================================================
  149. #if ! DOXYGEN
  150. #define JUCE_JOIN_MACRO_HELPER(a, b) a ## b
  151. #endif
  152. /** Good old C macro concatenation helper.
  153. This combines two items (which may themselves be macros) into a single string,
  154. avoiding the pitfalls of the ## macro operator.
  155. */
  156. #define JUCE_JOIN_MACRO(a, b) JUCE_JOIN_MACRO_HELPER (a, b)
  157. //==============================================================================
  158. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  159. #define JUCE_TRY try
  160. #define JUCE_CATCH_ALL catch (...) {}
  161. #define JUCE_CATCH_ALL_ASSERT catch (...) { jassertfalse; }
  162. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  163. #define JUCE_CATCH_EXCEPTION JUCE_CATCH_ALL
  164. #else
  165. /** Used in try-catch blocks, this macro will send exceptions to the JUCEApplication
  166. object so they can be logged by the application if it wants to.
  167. */
  168. #define JUCE_CATCH_EXCEPTION \
  169. catch (const std::exception& e) \
  170. { \
  171. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__); \
  172. } \
  173. catch (...) \
  174. { \
  175. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__); \
  176. }
  177. #endif
  178. #else
  179. #define JUCE_TRY
  180. #define JUCE_CATCH_EXCEPTION
  181. #define JUCE_CATCH_ALL
  182. #define JUCE_CATCH_ALL_ASSERT
  183. #endif
  184. //==============================================================================
  185. // Macros for inlining.
  186. #if JUCE_MSVC
  187. /** A platform-independent way of forcing an inline function.
  188. Use the syntax: @code
  189. forcedinline void myfunction (int x)
  190. @endcode
  191. */
  192. #ifndef JUCE_DEBUG
  193. #define forcedinline __forceinline
  194. #else
  195. #define forcedinline inline
  196. #endif
  197. #define JUCE_ALIGN(bytes) __declspec (align (bytes))
  198. #else
  199. /** A platform-independent way of forcing an inline function.
  200. Use the syntax: @code
  201. forcedinline void myfunction (int x)
  202. @endcode
  203. */
  204. #ifndef JUCE_DEBUG
  205. #define forcedinline inline __attribute__((always_inline))
  206. #else
  207. #define forcedinline inline
  208. #endif
  209. #define JUCE_ALIGN(bytes) __attribute__ ((aligned (bytes)))
  210. #endif
  211. //==============================================================================
  212. // Cross-compiler deprecation macros..
  213. #if JUCE_MSVC && ! JUCE_NO_DEPRECATION_WARNINGS
  214. #define JUCE_DEPRECATED(functionDef) __declspec(deprecated) functionDef
  215. #elif JUCE_GCC && ! JUCE_NO_DEPRECATION_WARNINGS
  216. #define JUCE_DEPRECATED(functionDef) functionDef __attribute__ ((deprecated))
  217. #else
  218. #define JUCE_DEPRECATED(functionDef) functionDef
  219. #endif
  220. //==============================================================================
  221. #if JUCE_ANDROID && ! DOXYGEN
  222. #define JUCE_MODAL_LOOPS_PERMITTED 0
  223. #else
  224. /** Some operating environments don't provide a modal loop mechanism, so this flag can be
  225. used to disable any functions that try to run a modal loop.
  226. */
  227. #define JUCE_MODAL_LOOPS_PERMITTED 1
  228. #endif
  229. #endif // __JUCE_PLATFORMDEFS_JUCEHEADER__