OpenShot Library | libopenshot-audio  0.1.9
juce_PlatformDefs.h
1 
2 /** @weakgroup juce_core-system
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /* This file defines miscellaneous macros for debugging, assertions, etc.
32 */
33 
34 //==============================================================================
35 #ifdef JUCE_FORCE_DEBUG
36  #undef JUCE_DEBUG
37 
38  #if JUCE_FORCE_DEBUG
39  #define JUCE_DEBUG 1
40  #endif
41 #endif
42 
43 /** This macro defines the C calling convention used as the standard for JUCE calls. */
44 #if JUCE_MSVC
45  #define JUCE_CALLTYPE __stdcall
46  #define JUCE_CDECL __cdecl
47 #else
48  #define JUCE_CALLTYPE
49  #define JUCE_CDECL
50 #endif
51 
52 //==============================================================================
53 // Debugging and assertion macros
54 
55 #ifndef JUCE_LOG_CURRENT_ASSERTION
56  #if JUCE_LOG_ASSERTIONS || JUCE_DEBUG
57  #define JUCE_LOG_CURRENT_ASSERTION juce::logAssertion (__FILE__, __LINE__);
58  #else
59  #define JUCE_LOG_CURRENT_ASSERTION
60  #endif
61 #endif
62 
63 //==============================================================================
64 #if JUCE_IOS || JUCE_LINUX
65  /** This will try to break into the debugger if the app is currently being debugged.
66  If called by an app that's not being debugged, the behaviour isn't defined - it may
67  crash or not, depending on the platform.
68  @see jassert()
69  */
70  #define JUCE_BREAK_IN_DEBUGGER { ::kill (0, SIGTRAP); }
71 #elif JUCE_MSVC
72  #ifndef __INTEL_COMPILER
73  #pragma intrinsic (__debugbreak)
74  #endif
75  #define JUCE_BREAK_IN_DEBUGGER { __debugbreak(); }
76 #elif JUCE_GCC || JUCE_MAC
77  #if JUCE_NO_INLINE_ASM
78  #define JUCE_BREAK_IN_DEBUGGER { }
79  #else
80  #define JUCE_BREAK_IN_DEBUGGER { asm ("int $3"); }
81  #endif
82 #elif JUCE_ANDROID
83  #define JUCE_BREAK_IN_DEBUGGER { __builtin_trap(); }
84 #else
85  #define JUCE_BREAK_IN_DEBUGGER { __asm int 3 }
86 #endif
87 
88 #if JUCE_CLANG && defined (__has_feature) && ! defined (JUCE_ANALYZER_NORETURN)
89  #if __has_feature (attribute_analyzer_noreturn)
90  inline void __attribute__((analyzer_noreturn)) juce_assert_noreturn() {}
91  #define JUCE_ANALYZER_NORETURN juce::juce_assert_noreturn();
92  #endif
93 #endif
94 
95 #ifndef JUCE_ANALYZER_NORETURN
96  #define JUCE_ANALYZER_NORETURN
97 #endif
98 
99 //==============================================================================
100 #if JUCE_MSVC && ! DOXYGEN
101  #define JUCE_BLOCK_WITH_FORCED_SEMICOLON(x) \
102  __pragma(warning(push)) \
103  __pragma(warning(disable:4127)) \
104  do { x } while (false) \
105  __pragma(warning(pop))
106 #else
107  /** This is the good old C++ trick for creating a macro that forces the user to put
108  a semicolon after it when they use it.
109  */
110  #define JUCE_BLOCK_WITH_FORCED_SEMICOLON(x) do { x } while (false)
111 #endif
112 
113 //==============================================================================
114 #if (JUCE_DEBUG && ! JUCE_DISABLE_ASSERTIONS) || DOXYGEN
115  /** Writes a string to the standard error stream.
116  Note that as well as a single string, you can use this to write multiple items
117  as a stream, e.g.
118  @code
119  DBG ("foo = " << foo << "bar = " << bar);
120  @endcode
121  The macro is only enabled in a debug build, so be careful not to use it with expressions
122  that have important side-effects!
123  @see Logger::outputDebugString
124  */
125  #define DBG(textToWrite) JUCE_BLOCK_WITH_FORCED_SEMICOLON (juce::String tempDbgBuf; tempDbgBuf << textToWrite; juce::Logger::outputDebugString (tempDbgBuf);)
126 
127  //==============================================================================
128  /** This will always cause an assertion failure.
129  It is only compiled in a debug build, (unless JUCE_LOG_ASSERTIONS is enabled for your build).
130  @see jassert
131  */
132  #define jassertfalse JUCE_BLOCK_WITH_FORCED_SEMICOLON (JUCE_LOG_CURRENT_ASSERTION; if (juce::juce_isRunningUnderDebugger()) JUCE_BREAK_IN_DEBUGGER; JUCE_ANALYZER_NORETURN)
133 
134  //==============================================================================
135  /** Platform-independent assertion macro.
136 
137  This macro gets turned into a no-op when you're building with debugging turned off, so be
138  careful that the expression you pass to it doesn't perform any actions that are vital for the
139  correct behaviour of your program!
140  @see jassertfalse
141  */
142  #define jassert(expression) JUCE_BLOCK_WITH_FORCED_SEMICOLON (if (! (expression)) jassertfalse;)
143 
144 #else
145  //==============================================================================
146  // If debugging is disabled, these dummy debug and assertion macros are used..
147 
148  #define DBG(textToWrite)
149  #define jassertfalse JUCE_BLOCK_WITH_FORCED_SEMICOLON (JUCE_LOG_CURRENT_ASSERTION)
150 
151  #if JUCE_LOG_ASSERTIONS
152  #define jassert(expression) JUCE_BLOCK_WITH_FORCED_SEMICOLON (if (! (expression)) jassertfalse;)
153  #else
154  #define jassert(expression) JUCE_BLOCK_WITH_FORCED_SEMICOLON ( ; )
155  #endif
156 
157 #endif
158 
159 //==============================================================================
160 #if ! DOXYGEN
161  #define JUCE_JOIN_MACRO_HELPER(a, b) a ## b
162  #define JUCE_STRINGIFY_MACRO_HELPER(a) #a
163 #endif
164 
165 /** A good old-fashioned C macro concatenation helper.
166  This combines two items (which may themselves be macros) into a single string,
167  avoiding the pitfalls of the ## macro operator.
168 */
169 #define JUCE_JOIN_MACRO(item1, item2) JUCE_JOIN_MACRO_HELPER (item1, item2)
170 
171 /** A handy C macro for stringifying any symbol, rather than just a macro parameter. */
172 #define JUCE_STRINGIFY(item) JUCE_STRINGIFY_MACRO_HELPER (item)
173 
174 //==============================================================================
175 /** This is a shorthand macro for declaring stubs for a class's copy constructor and operator=.
176 
177  For example, instead of
178  @code
179  class MyClass
180  {
181  etc..
182 
183  private:
184  MyClass (const MyClass&);
185  MyClass& operator= (const MyClass&);
186  };@endcode
187 
188  ..you can just write:
189 
190  @code
191  class MyClass
192  {
193  etc..
194 
195  private:
196  JUCE_DECLARE_NON_COPYABLE (MyClass)
197  };@endcode
198 */
199 #define JUCE_DECLARE_NON_COPYABLE(className) \
200  className (const className&) = delete;\
201  className& operator= (const className&) = delete;
202 
203 /** This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and
204  JUCE_LEAK_DETECTOR macro for a class.
205 */
206 #define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className) \
207  JUCE_DECLARE_NON_COPYABLE(className) \
208  JUCE_LEAK_DETECTOR(className)
209 
210 /** This macro can be added to class definitions to disable the use of new/delete to
211  allocate the object on the heap, forcing it to only be used as a stack or member variable.
212 */
213 #define JUCE_PREVENT_HEAP_ALLOCATION \
214  private: \
215  static void* operator new (size_t) = delete; \
216  static void operator delete (void*) = delete;
217 
218 //==============================================================================
219 #if JUCE_MSVC && ! defined (DOXYGEN)
220  #define JUCE_WARNING_HELPER(file, line, mess) message(file "(" JUCE_STRINGIFY (line) ") : Warning: " #mess)
221  #define JUCE_COMPILER_WARNING(message) __pragma(JUCE_WARNING_HELPER (__FILE__, __LINE__, message))
222 #else
223  #ifndef DOXYGEN
224  #define JUCE_WARNING_HELPER(mess) message(#mess)
225  #endif
226 
227  /** This macro allows you to emit a custom compiler warning message.
228  Very handy for marking bits of code as "to-do" items, or for shaming
229  code written by your co-workers in a way that's hard to ignore.
230 
231  GCC and Clang provide the \#warning directive, but MSVC doesn't, so this macro
232  is a cross-compiler way to get the same functionality as \#warning.
233  */
234  #define JUCE_COMPILER_WARNING(message) _Pragma(JUCE_STRINGIFY (JUCE_WARNING_HELPER (message)))
235 #endif
236 
237 
238 //==============================================================================
239 #if JUCE_DEBUG || DOXYGEN
240  /** A platform-independent way of forcing an inline function.
241  Use the syntax: @code
242  forcedinline void myfunction (int x)
243  @endcode
244  */
245  #define forcedinline inline
246 #else
247  #if JUCE_MSVC
248  #define forcedinline __forceinline
249  #else
250  #define forcedinline inline __attribute__((always_inline))
251  #endif
252 #endif
253 
254 #if JUCE_MSVC || DOXYGEN
255  /** This can be placed before a stack or member variable declaration to tell the compiler
256  to align it to the specified number of bytes. */
257  #define JUCE_ALIGN(bytes) __declspec (align (bytes))
258 #else
259  #define JUCE_ALIGN(bytes) __attribute__ ((aligned (bytes)))
260 #endif
261 
262 //==============================================================================
263 // Cross-compiler deprecation macros..
264 #ifdef DOXYGEN
265  /** This macro can be used to wrap a function which has been deprecated. */
266  #define JUCE_DEPRECATED(functionDef)
267  #define JUCE_DEPRECATED_WITH_BODY(functionDef, body)
268 #elif JUCE_MSVC && ! JUCE_NO_DEPRECATION_WARNINGS
269  #define JUCE_DEPRECATED_ATTRIBUTE __declspec(deprecated)
270  #define JUCE_DEPRECATED(functionDef) JUCE_DEPRECATED_ATTRIBUTE functionDef
271  #define JUCE_DEPRECATED_WITH_BODY(functionDef, body) JUCE_DEPRECATED_ATTRIBUTE functionDef body
272 #elif (JUCE_GCC || JUCE_CLANG) && ! JUCE_NO_DEPRECATION_WARNINGS
273  #define JUCE_DEPRECATED_ATTRIBUTE __attribute__ ((deprecated))
274  #define JUCE_DEPRECATED(functionDef) functionDef JUCE_DEPRECATED_ATTRIBUTE
275  #define JUCE_DEPRECATED_WITH_BODY(functionDef, body) functionDef JUCE_DEPRECATED_ATTRIBUTE body
276 #else
277  #define JUCE_DEPRECATED_ATTRIBUTE
278  #define JUCE_DEPRECATED(functionDef) functionDef
279  #define JUCE_DEPRECATED_WITH_BODY(functionDef, body) functionDef body
280 #endif
281 
282 #if JUCE_ALLOW_STATIC_NULL_VARIABLES
283  #if ! (defined (DOXYGEN) || defined (JUCE_GCC) || (JUCE_MSVC && _MSC_VER <= 1900))
284  #define JUCE_DEPRECATED_STATIC(valueDef) JUCE_DEPRECATED_ATTRIBUTE valueDef
285 
286  #if JUCE_MSVC
287  #define JUCE_DECLARE_DEPRECATED_STATIC(valueDef) \
288  __pragma(warning(push)) \
289  __pragma(warning(disable:4996)) \
290  valueDef \
291  __pragma(warning(pop))
292  #else
293  #define JUCE_DECLARE_DEPRECATED_STATIC(valueDef) valueDef
294  #endif
295  #else
296  #define JUCE_DEPRECATED_STATIC(valueDef) valueDef
297  #define JUCE_DECLARE_DEPRECATED_STATIC(valueDef) valueDef
298  #endif
299 #else
300  #define JUCE_DEPRECATED_STATIC(valueDef)
301  #define JUCE_DECLARE_DEPRECATED_STATIC(valueDef)
302 #endif
303 
304 //==============================================================================
305 #if JUCE_ANDROID && ! DOXYGEN
306  #define JUCE_MODAL_LOOPS_PERMITTED 0
307 #elif ! defined (JUCE_MODAL_LOOPS_PERMITTED)
308  /** Some operating environments don't provide a modal loop mechanism, so this flag can be
309  used to disable any functions that try to run a modal loop. */
310  #define JUCE_MODAL_LOOPS_PERMITTED 1
311 #endif
312 
313 //==============================================================================
314 #if JUCE_GCC || JUCE_CLANG
315  #define JUCE_PACKED __attribute__((packed))
316 #elif ! DOXYGEN
317  #define JUCE_PACKED
318 #endif
319 
320 //==============================================================================
321 #if JUCE_GCC || DOXYGEN
322  /** This can be appended to a function declaration to tell gcc to disable associative
323  math optimisations which break some floating point algorithms. */
324  #define JUCE_NO_ASSOCIATIVE_MATH_OPTIMISATIONS __attribute__((__optimize__("no-associative-math")))
325 #else
326  #define JUCE_NO_ASSOCIATIVE_MATH_OPTIMISATIONS
327 #endif
328 
329 } // namespace juce
330 
331 /** @}*/