Beast - Music Synthesizer and Composer  0.11.1+10.g2da35
bcore.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __BSE_BCORE_HH__
3 #define __BSE_BCORE_HH__
4 
5 #include <rapicorn-core.hh>
6 #include <sfi/glib-extra.hh>
7 
8 namespace Bse {
9 using namespace Rapicorn;
10 using Rapicorn::uint8;
11 using Rapicorn::uint16;
12 using Rapicorn::uint32;
13 using Rapicorn::uint64;
14 using Rapicorn::int8;
15 using Rapicorn::int16;
16 using Rapicorn::int32;
17 using Rapicorn::int64;
18 using Rapicorn::unichar;
19 using Rapicorn::String;
21 using Rapicorn::printout;
22 using Rapicorn::printerr;
23 namespace Path = Rapicorn::Path;
24 
25 
26 // == Utility Macros ==
27 #define BSE_ISLIKELY(expr) __builtin_expect (bool (expr), 1)
28 #define BSE_UNLIKELY(expr) __builtin_expect (bool (expr), 0)
29 #define BSE_ABS(a) ((a) < 0 ? -(a) : (a))
30 #define BSE_MIN(a,b) ((a) <= (b) ? (a) : (b))
31 #define BSE_MAX(a,b) ((a) >= (b) ? (a) : (b))
32 #define BSE_CLAMP(v,mi,ma) ((v) < (mi) ? (mi) : ((v) > (ma) ? (ma) : (v)))
33 #define BSE_ARRAY_SIZE(array) (sizeof (array) / sizeof ((array)[0]))
34 #define BSE_ALIGN(size, base) ((base) * (((size) + (base) - 1) / (base)))
35 #define BSE_CPP_STRINGIFY(s) RAPICORN_CPP_STRINGIFY(s)
36 #define BSE__HERE__ RAPICORN__HERE__
37 #define BSE_PURE RAPICORN_PURE
38 #define BSE_MALLOC RAPICORN_MALLOC
39 #define BSE_SENTINEL RAPICORN_SENTINEL
40 #define BSE_NORETURN RAPICORN_NORETURN
41 #define BSE_CONST RAPICORN_CONST
42 #define BSE_UNUSED RAPICORN_UNUSED
43 #define BSE_USED RAPICORN_USED
44 #define BSE_NO_INSTRUMENT RAPICORN_NO_INSTRUMENT
45 #define BSE_DEPRECATED RAPICORN_DEPRECATED
46 #define BSE_ALWAYS_INLINE RAPICORN_ALWAYS_INLINE
47 #define BSE_NOINLINE RAPICORN_NOINLINE
48 #define BSE_CONSTRUCTOR RAPICORN_CONSTRUCTOR
49 #define BSE_MAY_ALIAS RAPICORN_MAY_ALIAS
50 #define BSE_CLASS_NON_COPYABLE(ClassName) RAPICORN_CLASS_NON_COPYABLE (ClassName)
51 #define BSE_DECLARE_VLA(Type, var, count) RAPICORN_DECLARE_VLA (Type, var, count)
52 #define BSE_RETURN_UNLESS(cond, ...) do { if (BSE_UNLIKELY (!bool (cond))) return __VA_ARGS__; } while (0)
54 
55 // == Path Name Macros ==
56 #ifdef _WIN32 // includes _WIN64
57 #undef BSE_UNIX_PATHS
58 #define BSE_DOS_PATHS 1
59 #else // !_WIN32
60 #define BSE_UNIX_PATHS 1
61 #undef BSE_DOS_PATHS
62 #endif // !_WIN32
63 #define BSE_DIR_SEPARATOR RAPICORN_DIR_SEPARATOR
64 #define BSE_DIR_SEPARATOR_S RAPICORN_DIR_SEPARATOR_S
65 #define BSE_SEARCHPATH_SEPARATOR RAPICORN_SEARCHPATH_SEPARATOR
66 #define BSE_SEARCHPATH_SEPARATOR_S RAPICORN_SEARCHPATH_SEPARATOR_S
67 #define BSE_IS_ABSPATH(p) RAPICORN_IS_ABSPATH (p)
68 
69 // == Diagnostics ==
70 template<class ...Args> void fatal (const char *format, const Args &...args) RAPICORN_NORETURN;
71 template<class ...Args> void warning (const char *format, const Args &...args);
72 template<class ...Args> void warn (const char *format, const Args &...args);
73 template<class ...Args> void info (const char *format, const Args &...args);
74 template<class ...Args> inline void dump (const char *conditional, const char *format, const Args &...args) RAPICORN_ALWAYS_INLINE;
75 template<class ...Args> inline void debug (const char *conditional, const char *format, const Args &...args) RAPICORN_ALWAYS_INLINE;
76 inline bool debug_enabled (const char *conditional) RAPICORN_ALWAYS_INLINE BSE_PURE;
77 
78 // == Internal Implementation Details ==
79 namespace Internal {
80 extern bool debug_any_enabled; //< Indicates if $BSE_DEBUG enables some debug settings.
81 bool debug_key_enabled (const char *conditional) BSE_PURE;
82 void diagnostic (char kind, const std::string &message);
83 void force_abort () RAPICORN_NORETURN;
84 } // Internal
85 
87 template<class ...Args> inline void RAPICORN_ALWAYS_INLINE
88 dump (const char *conditional, const char *format, const Args &...args)
89 {
90  if (BSE_UNLIKELY (Internal::debug_any_enabled) && Internal::debug_key_enabled (conditional))
91  Internal::diagnostic (' ', string_format (format, args...));
92 }
93 
95 template<class ...Args> inline void RAPICORN_ALWAYS_INLINE
96 debug (const char *conditional, const char *format, const Args &...args)
97 {
98  if (BSE_UNLIKELY (Internal::debug_any_enabled) && Internal::debug_key_enabled (conditional))
99  Internal::diagnostic ('D', string_format (format, args...));
100 }
101 
103 inline bool RAPICORN_ALWAYS_INLINE BSE_PURE
104 debug_enabled (const char *conditional)
105 {
106  if (BSE_UNLIKELY (Internal::debug_any_enabled))
107  return Internal::debug_key_enabled (conditional);
108  return false;
109 }
110 
112 template<class ...Args> void RAPICORN_NORETURN
113 fatal (const char *format, const Args &...args)
114 {
115  Internal::diagnostic ('F', string_format (format, args...));
116  Internal::force_abort();
117 }
118 
120 template<class ...Args> void RAPICORN_NORETURN
121 warn (const char *format, const Args &...args)
122 {
123  Internal::diagnostic ('W', string_format (format, args...));
124 }
125 
127 template<class ...Args> void RAPICORN_NORETURN
128 warning (const char *format, const Args &...args)
129 {
130  Internal::diagnostic ('W', string_format (format, args...));
131 }
132 
134 template<class ...Args> void RAPICORN_NORETURN
135 info (const char *format, const Args &...args)
136 {
137  Internal::diagnostic ('I', string_format (format, args...));
138 }
139 
140 // == Assertions ==
142 #define BSE_ASSERT_RETURN(cond, ...) AIDA_ASSERT_RETURN (cond, __VA_ARGS__)
143 #define BSE_ASSERT_RETURN_UNREACHED(...) AIDA_ASSERT_RETURN_UNREACHED (__VA_ARGS__)
145 #ifdef BSE_CONVENIENCE
146 #define assert_return(cond, ...) BSE_ASSERT_RETURN (cond, __VA_ARGS__)
148 #define assert_return_unreached(...) BSE_ASSERT_RETURN_UNREACHED (__VA_ARGS__)
150 #define ISLIKELY(cond) BSE_ISLIKELY (cond)
152 #define UNLIKELY(cond) BSE_UNLIKELY (cond)
154 #define return_unless(cond, ...) BSE_RETURN_UNLESS (cond, __VA_ARGS__)
156 #endif // BSE_CONVENIENCE
157 using Rapicorn::Aida::assertion_failed_hook;
158 using Rapicorn::breakpoint;
159 
160 } // Bse
161 
162 #endif // __BSE_BCORE_HH__
uint16_t uint16
void printerr(const char *format, const Args &...args)
#define BSE_UNLIKELY(expr)
Compiler hint to optimize for expr evaluating to false.
Definition: bcore.hh:28
int32_t int32
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:91
void debug(const char *conditional, const char *format, const Args &...args) RAPICORN_ALWAYS_INLINE
Issue a printf-like debugging message if conditional is enabled by $BSE_DEBUG.
Definition: bcore.hh:96
void warning(const char *format, const Args &...args)
Issue a printf-like warning message.
Definition: bcore.hh:128
void dump(const char *conditional, const char *format, const Args &...args) RAPICORN_ALWAYS_INLINE
Issue a printf-like message if conditional is enabled by $BSE_DEBUG.
Definition: bcore.hh:88
STL class.
uint32_t unichar
std::string String
void info(const char *format, const Args &...args)
Issue an informative printf-like message.
Definition: bcore.hh:135
bool debug_enabled(const char *conditional) RAPICORN_ALWAYS_INLINE BSE_PURE
Check if conditional is enabled by $BSE_DEBUG.
Definition: bcore.hh:104
Definition: topbuildid.cc:2
int64_t int64
void fatal(const char *format, const Args &...args)
Issue a printf-like message and abort the program, this function will not return. ...
Definition: bcore.hh:113
#define BSE_PURE
A GCC Attribute.
Definition: bcore.hh:37
uint8_t uint8
int8_t int8
uint64_t uint64
void printout(const char *format, const Args &...args)
int16_t int16
String string_format(const char *format, const Args &...args)
void warn(const char *format, const Args &...args)
Issue a printf-like warning message.
Definition: bcore.hh:121
uint32_t uint32