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.

227 lines
7.2KB

  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. #else
  34. #define JUCE_CALLTYPE
  35. #endif
  36. //==============================================================================
  37. // Debugging and assertion macros
  38. // (For info about JUCE_LOG_ASSERTIONS, have a look in juce_Config.h)
  39. #if JUCE_LOG_ASSERTIONS
  40. #define juce_LogCurrentAssertion juce_LogAssertion (__FILE__, __LINE__);
  41. #elif JUCE_DEBUG
  42. #define juce_LogCurrentAssertion std::cerr << "JUCE Assertion failure in " << __FILE__ << ", line " << __LINE__ << std::endl;
  43. #else
  44. #define juce_LogCurrentAssertion
  45. #endif
  46. #if JUCE_DEBUG
  47. //==============================================================================
  48. // If debugging is enabled..
  49. /** Writes a string to the standard error stream.
  50. This is only compiled in a debug build.
  51. @see Logger::outputDebugString
  52. */
  53. #define DBG(dbgtext) Logger::outputDebugString (dbgtext);
  54. //==============================================================================
  55. // Assertions..
  56. #if JUCE_WINDOWS || DOXYGEN
  57. #if JUCE_USE_INTRINSICS
  58. #pragma intrinsic (__debugbreak)
  59. /** This will try to break the debugger if one is currently hosting this app.
  60. @see jassert()
  61. */
  62. #define juce_breakDebugger __debugbreak();
  63. #elif JUCE_GCC
  64. /** This will try to break the debugger if one is currently hosting this app.
  65. @see jassert()
  66. */
  67. #define juce_breakDebugger asm("int $3");
  68. #else
  69. /** This will try to break the debugger if one is currently hosting this app.
  70. @see jassert()
  71. */
  72. #define juce_breakDebugger { __asm int 3 }
  73. #endif
  74. #elif JUCE_MAC
  75. #define juce_breakDebugger Debugger();
  76. #elif JUCE_IPHONE
  77. #define juce_breakDebugger kill (0, SIGTRAP);
  78. #elif JUCE_LINUX
  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. template <bool b> struct JuceStaticAssert;
  111. template <> struct JuceStaticAssert <true> { static void dummy() {} };
  112. #endif
  113. /** A compile-time assertion macro.
  114. If the expression parameter is false, the macro will cause a compile error.
  115. */
  116. #define static_jassert(expression) JuceStaticAssert<expression>::dummy();
  117. //==============================================================================
  118. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  119. #define JUCE_TRY try
  120. #define JUCE_CATCH_ALL catch (...) {}
  121. #define JUCE_CATCH_ALL_ASSERT catch (...) { jassertfalse; }
  122. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  123. #define JUCE_CATCH_EXCEPTION JUCE_CATCH_ALL
  124. #else
  125. /** Used in try-catch blocks, this macro will send exceptions to the JUCEApplication
  126. object so they can be logged by the application if it wants to.
  127. */
  128. #define JUCE_CATCH_EXCEPTION \
  129. catch (const std::exception& e) \
  130. { \
  131. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__); \
  132. } \
  133. catch (...) \
  134. { \
  135. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__); \
  136. }
  137. #endif
  138. #else
  139. #define JUCE_TRY
  140. #define JUCE_CATCH_EXCEPTION
  141. #define JUCE_CATCH_ALL
  142. #define JUCE_CATCH_ALL_ASSERT
  143. #endif
  144. //==============================================================================
  145. // Macros for inlining.
  146. #if JUCE_MSVC
  147. /** A platform-independent way of forcing an inline function.
  148. Use the syntax: @code
  149. forcedinline void myfunction (int x)
  150. @endcode
  151. */
  152. #ifndef JUCE_DEBUG
  153. #define forcedinline __forceinline
  154. #else
  155. #define forcedinline inline
  156. #endif
  157. #define JUCE_ALIGN(bytes) __declspec (align (bytes))
  158. #else
  159. /** A platform-independent way of forcing an inline function.
  160. Use the syntax: @code
  161. forcedinline void myfunction (int x)
  162. @endcode
  163. */
  164. #ifndef JUCE_DEBUG
  165. #define forcedinline inline __attribute__((always_inline))
  166. #else
  167. #define forcedinline inline
  168. #endif
  169. #define JUCE_ALIGN(bytes) __attribute__ ((aligned (bytes)))
  170. #endif
  171. #endif // __JUCE_PLATFORMDEFS_JUCEHEADER__