1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2016 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 
17 #ifndef DISTRHO_DEFINES_H_INCLUDED
18 #define DISTRHO_DEFINES_H_INCLUDED
19 
20 /* Compatibility with non-clang compilers */
21 #ifndef __has_feature
22 # define __has_feature(x) 0
23 #endif
24 #ifndef __has_extension
25 # define __has_extension __has_feature
26 #endif
27 
28 /* Check OS */
29 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
30 # define DISTRHO_PLUGIN_EXPORT extern "C" __declspec (dllexport)
31 # define DISTRHO_OS_WINDOWS 1
32 # define DISTRHO_DLL_EXTENSION "dll"
33 #else
34 # define DISTRHO_PLUGIN_EXPORT extern "C" __attribute__ ((visibility("default")))
35 # if defined(__APPLE__)
36 #  define DISTRHO_OS_MAC 1
37 #  define DISTRHO_DLL_EXTENSION "dylib"
38 # elif defined(__HAIKU__)
39 #  define DISTRHO_OS_HAIKU 1
40 # elif defined(__linux__) || defined(__linux)
41 #  define DISTRHO_OS_LINUX 1
42 # endif
43 #endif
44 
45 #ifndef DISTRHO_DLL_EXTENSION
46 # define DISTRHO_DLL_EXTENSION "so"
47 #endif
48 
49 /* Check for C++11 support */
50 #if defined(HAVE_CPP11_SUPPORT)
51 # if HAVE_CPP11_SUPPORT
52 #  define DISTRHO_PROPER_CPP11_SUPPORT
53 # endif
54 #elif __cplusplus >= 201103L || (defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405) || __has_extension(cxx_noexcept)
55 # define DISTRHO_PROPER_CPP11_SUPPORT
56 # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407 && ! defined(__clang__)) || (defined(__clang__) && ! __has_extension(cxx_override_control))
57 #  define override // gcc4.7+ only
58 #  define final    // gcc4.7+ only
59 # endif
60 #endif
61 
62 #ifndef DISTRHO_PROPER_CPP11_SUPPORT
63 # define noexcept throw()
64 # define override
65 # define final
66 # define nullptr NULL
67 #endif
68 
69 /* Define DISTRHO_DEPRECATED */
70 #if defined(__GNUC__)
71 # define DISTRHO_DEPRECATED __attribute__((deprecated))
72 #elif defined(_MSC_VER)
73 # define DISTRHO_DEPRECATED __declspec(deprecated)
74 #else
75 # define DISTRHO_DEPRECATED
76 #endif
77 
78 /* Define DISTRHO_SAFE_ASSERT* */
79 #define DISTRHO_SAFE_ASSERT(cond)               if (! (cond))   d_safe_assert(#cond, __FILE__, __LINE__);
80 #define DISTRHO_SAFE_ASSERT_BREAK(cond)         if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); break; }
81 #define DISTRHO_SAFE_ASSERT_CONTINUE(cond)      if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); continue; }
82 #define DISTRHO_SAFE_ASSERT_RETURN(cond, ret)   if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); return ret; }
83 
84 /* Define DISTRHO_SAFE_EXCEPTION */
85 #define DISTRHO_SAFE_EXCEPTION(msg)             catch(...) { d_safe_exception(msg, __FILE__, __LINE__); }
86 #define DISTRHO_SAFE_EXCEPTION_BREAK(msg)       catch(...) { d_safe_exception(msg, __FILE__, __LINE__); break; }
87 #define DISTRHO_SAFE_EXCEPTION_CONTINUE(msg)    catch(...) { d_safe_exception(msg, __FILE__, __LINE__); continue; }
88 #define DISTRHO_SAFE_EXCEPTION_RETURN(msg, ret) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); return ret; }
89 
90 /* Define DISTRHO_DECLARE_NON_COPY_CLASS */
91 #ifdef DISTRHO_PROPER_CPP11_SUPPORT
92 # define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \
93 private:                                           \
94     ClassName(ClassName&) = delete;                \
95     ClassName(const ClassName&) = delete;          \
96     ClassName& operator=(ClassName&) = delete  ;   \
97     ClassName& operator=(const ClassName&) = delete;
98 #else
99 # define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) \
100 private:                                           \
101     ClassName(ClassName&);                         \
102     ClassName(const ClassName&);                   \
103     ClassName& operator=(ClassName&);              \
104     ClassName& operator=(const ClassName&);
105 #endif
106 
107 /* Define DISTRHO_DECLARE_NON_COPY_STRUCT */
108 #ifdef DISTRHO_PROPER_CPP11_SUPPORT
109 # define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) \
110     StructName(StructName&) = delete;                \
111     StructName(const StructName&) = delete;          \
112     StructName& operator=(StructName&) = delete;     \
113     StructName& operator=(const StructName&) = delete;
114 #else
115 # define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName)
116 #endif
117 
118 /* Define DISTRHO_PREVENT_HEAP_ALLOCATION */
119 #ifdef DISTRHO_PROPER_CPP11_SUPPORT
120 # define DISTRHO_PREVENT_HEAP_ALLOCATION        \
121 private:                                        \
122     static void* operator new(size_t) = delete; \
123     static void operator delete(void*) = delete;
124 #else
125 # define DISTRHO_PREVENT_HEAP_ALLOCATION \
126 private:                                 \
127     static void* operator new(size_t);   \
128     static void operator delete(void*);
129 #endif
130 
131 /* Define namespace */
132 #ifndef DISTRHO_NAMESPACE
133 # define DISTRHO_NAMESPACE DISTRHO
134 #endif
135 #define START_NAMESPACE_DISTRHO namespace DISTRHO_NAMESPACE {
136 #define END_NAMESPACE_DISTRHO }
137 #define USE_NAMESPACE_DISTRHO using namespace DISTRHO_NAMESPACE;
138 
139 /* Useful typedefs */
140 typedef unsigned char uchar;
141 typedef unsigned short int ushort;
142 typedef unsigned int uint;
143 typedef unsigned long int ulong;
144 
145 #endif // DISTRHO_DEFINES_H_INCLUDED
146