[beast: 6/57] SFI: cxxaux.hh: move basic type declarations and utility macros here



commit df081f899ddf025bfca89eb1497165c971bbd9f9
Author: Tim Janik <timj gnu org>
Date:   Tue Jul 4 14:41:09 2017 +0200

    SFI: cxxaux.hh: move basic type declarations and utility macros here
    
    Signed-off-by: Tim Janik <timj gnu org>

 sfi/Makefile.am |    3 +-
 sfi/bcore.hh    |   41 +--------------------------
 sfi/cxxaux.hh   |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 88 insertions(+), 41 deletions(-)
---
diff --git a/sfi/Makefile.am b/sfi/Makefile.am
index f13cc38..113e627 100644
--- a/sfi/Makefile.am
+++ b/sfi/Makefile.am
@@ -7,6 +7,7 @@ AM_CPPFLAGS += -I$(top_srcdir)
 
 sfi_public_headers = $(strip \
        bcore.hh        \
+       cxxaux.hh       \
        sfistore.hh     sficomwire.hh   sfifilecrawler.hh \
        glib-extra.hh                   sfiwrapper.hh    \
        sfivmarshal.hh  sfiglue.hh      sfigluecodec.hh sfiglueproxy.hh \
@@ -38,7 +39,7 @@ doc_sources.lst: Makefile
 # == libsfi-@MAJOR@.so ==
 noinst_LTLIBRARIES            = libsfi-@MAJOR@.la
 libsfi_@MAJOR@includedir      = $(bseincludedir)/sfi
-libsfi_@MAJOR@include_HEADERS = $(sfi_public_headers)
+libsfi_@MAJOR@include_HEADERS = $(sfi_public_headers) sysconfig.h
 libsfi_@MAJOR@_la_SOURCES     = $(sfi_all_sources)
 libsfi_@MAJOR@_la_CXXFLAGS    = $(AM_CXXFLAGS) $(LIBBSE_CFLAGS) -DBSE_CONVENIENCE
 libsfi_@MAJOR@_la_LIBADD      = $(LIBBSE_LIBS)
diff --git a/sfi/bcore.hh b/sfi/bcore.hh
index 6d9d67b..d34822e 100644
--- a/sfi/bcore.hh
+++ b/sfi/bcore.hh
@@ -2,56 +2,17 @@
 #ifndef __BSE_BCORE_HH__
 #define __BSE_BCORE_HH__
 
+#include <sfi/cxxaux.hh>
 #include <rapicorn-core.hh>
 #include <sfi/glib-extra.hh>
 
 namespace Bse {
 using namespace Rapicorn;
-using Rapicorn::uint8;
-using Rapicorn::uint16;
-using Rapicorn::uint32;
-using Rapicorn::uint64;
-using Rapicorn::int8;
-using Rapicorn::int16;
-using Rapicorn::int32;
-using Rapicorn::int64;
-using Rapicorn::unichar;
-using Rapicorn::String;
 using Rapicorn::string_format;
 using Rapicorn::printout;
 using Rapicorn::printerr;
 namespace Path = Rapicorn::Path;
 
-
-// == Utility Macros ==
-#define BSE_ISLIKELY(expr)      __builtin_expect (bool (expr), 1)       ///< Compiler hint to optimize for 
@a expr evaluating to true.
-#define BSE_UNLIKELY(expr)      __builtin_expect (bool (expr), 0)       ///< Compiler hint to optimize for 
@a expr evaluating to false.
-#define BSE_ABS(a)              ((a) < 0 ? -(a) : (a))          ///< Yield the absolute value of @a a.
-#define BSE_MIN(a,b)            ((a) <= (b) ? (a) : (b))        ///< Yield the smaller value of @a a and @a 
b.
-#define BSE_MAX(a,b)            ((a) >= (b) ? (a) : (b))        ///< Yield the greater value of @a a and @a 
b.
-#define BSE_CLAMP(v,mi,ma)      ((v) < (mi) ? (mi) : ((v) > (ma) ? (ma) : (v))) ///< Yield @a v clamped to [ 
@a mi .. @a ma ].
-#define BSE_ARRAY_SIZE(array)   (sizeof (array) / sizeof ((array)[0]))          ///< Yield the number of C 
@a array elements.
-#define BSE_ALIGN(size, base)   ((base) * (((size) + (base) - 1) / (base)))     ///< Round up @a size to 
multiples of @a base.
-#define BSE_CPP_STRINGIFY(s)    RAPICORN_CPP_STRINGIFY(s)    ///< Turn @a s into a C string literal.
-#define BSE__HERE__             RAPICORN__HERE__             ///< Shorthand for a string literal containing 
__FILE__ ":" __LINE__
-#define BSE_PURE               RAPICORN_PURE           ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_MALLOC             RAPICORN_MALLOC         ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_SENTINEL           RAPICORN_SENTINEL       ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_NORETURN           RAPICORN_NORETURN       ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_CONST              RAPICORN_CONST          ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_UNUSED             RAPICORN_UNUSED         ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_USED               RAPICORN_USED           ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_NO_INSTRUMENT      RAPICORN_NO_INSTRUMENT  ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_DEPRECATED         RAPICORN_DEPRECATED     ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_ALWAYS_INLINE      RAPICORN_ALWAYS_INLINE  ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_NOINLINE           RAPICORN_NOINLINE       ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_CONSTRUCTOR                RAPICORN_CONSTRUCTOR    ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attribute</a>.
-#define BSE_MAY_ALIAS          RAPICORN_MAY_ALIAS      ///< A <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html";>GCC Attribute</a>.
-#define BSE_CLASS_NON_COPYABLE(ClassName) RAPICORN_CLASS_NON_COPYABLE (ClassName) ///< Delete copy ctor and 
assignment operator.
-#define BSE_DECLARE_VLA(Type, var, count) RAPICORN_DECLARE_VLA (Type, var, count) ///< Declare a variable 
length array (clang++ uses std::vector<>).
-/// Return silently if @a cond does not evaluate to true with return value @a ...
-#define BSE_RETURN_UNLESS(cond, ...)      do { if (BSE_UNLIKELY (!bool (cond))) return __VA_ARGS__; } while 
(0)
-
 // == Path Name Macros ==
 #ifdef  _WIN32 // includes _WIN64
 #undef  BSE_UNIX_PATHS                                                  ///< Undefined on _WIN32 and _WIN64, 
defined on Unix.
diff --git a/sfi/cxxaux.hh b/sfi/cxxaux.hh
new file mode 100644
index 0000000..4bced57
--- /dev/null
+++ b/sfi/cxxaux.hh
@@ -0,0 +1,85 @@
+// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
+#ifndef __BSE_CXXAUX_HH__
+#define __BSE_CXXAUX_HH__
+
+#include <sfi/sysconfig.h>
+#include <sys/types.h>                  // uint, ssize
+#include <cstdint>                      // uint64_t
+#include <vector>
+#include <map>
+
+namespace Bse {
+
+// == uint ==
+#if     BSE_SIZEOF_SYS_TYPESH_UINT == 0
+typedef unsigned int            uint;   ///< Provide 'uint' if sys/types.h fails to do so.
+#else
+static_assert (BSE_SIZEOF_SYS_TYPESH_UINT == 4, "");
+#endif
+static_assert (sizeof (uint) == 4, "");
+
+// == type aliases ==
+typedef uint8_t         uint8;          ///< An 8-bit unsigned integer.
+typedef uint16_t        uint16;         ///< A 16-bit unsigned integer.
+typedef uint32_t        uint32;         ///< A 32-bit unsigned integer.
+typedef uint64_t        uint64;         ///< A 64-bit unsigned integer, use PRI*64 in format strings.
+typedef int8_t          int8;           ///< An 8-bit signed integer.
+typedef int16_t         int16;          ///< A 16-bit signed integer.
+typedef int32_t         int32;          ///< A 32-bit signed integer.
+typedef int64_t         int64;          ///< A 64-bit unsigned integer, use PRI*64 in format strings.
+typedef uint32_t        unichar;        ///< A 32-bit unsigned integer used for Unicode characters.
+static_assert (sizeof (uint8) == 1 && sizeof (uint16) == 2 && sizeof (uint32) == 4 && sizeof (uint64) == 8, 
"");
+static_assert (sizeof (int8)  == 1 && sizeof (int16)  == 2 && sizeof (int32)  == 4 && sizeof (int64)  == 8, 
"");
+static_assert (sizeof (int) == 4 && sizeof (uint) == 4 && sizeof (unichar) == 4, "");
+using   std::map;
+using   std::vector;
+typedef std::string String;             ///< Convenience alias for std::string.
+typedef vector<String> StringVector;    ///< Convenience alias for a std::vector<std::string>.
+
+// == Utility Macros ==
+#define BSE_CPP_STRINGIFY(s)    BSE_CPP_STRINGIFY_ (s)                  ///< Convert macro argument into a C 
const char*.
+#define BSE_CPP_STRINGIFY_(s)   #s                                      // Indirection helper, required to 
expand macros like __LINE__
+#define BSE_ISLIKELY(expr)      __builtin_expect (bool (expr), 1)       ///< Compiler hint to optimize for 
@a expr evaluating to true.
+#define BSE_UNLIKELY(expr)      __builtin_expect (bool (expr), 0)       ///< Compiler hint to optimize for 
@a expr evaluating to false.
+#define BSE_ABS(a)              ((a) < 0 ? -(a) : (a))                  ///< Yield the absolute value of @a 
a.
+#define BSE_MIN(a,b)            ((a) <= (b) ? (a) : (b))                ///< Yield the smaller value of @a a 
and @a b.
+#define BSE_MAX(a,b)            ((a) >= (b) ? (a) : (b))                ///< Yield the greater value of @a a 
and @a b.
+#define BSE_CLAMP(v,mi,ma)      ((v) < (mi) ? (mi) : ((v) > (ma) ? (ma) : (v))) ///< Yield @a v clamped to [ 
@a mi .. @a ma ].
+#define BSE_ARRAY_SIZE(array)   (sizeof (array) / sizeof ((array)[0]))          ///< Yield the number of C 
@a array elements.
+#define BSE_ALIGN(size, base)   ((base) * (((size) + (base) - 1) / (base)))     ///< Round up @a size to 
multiples of @a base.
+/// @addtogroup GCC Attributes
+/// Bse macros that are shorthands for <a 
href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html";>GCC Attributes</a>.
+/// @{
+#define BSE_ALWAYS_INLINE       __attribute__ ((always_inline))
+#define BSE_CONST               __attribute__ ((__const__))
+#define BSE_CONSTRUCTOR                __attribute__ ((constructor,used))      // gcc-3.3 also needs "used" 
to emit code
+#define BSE_DEPRECATED          __attribute__ ((__deprecated__))
+#define BSE_MALLOC              __attribute__ ((__malloc__))
+#define BSE_MAY_ALIAS           __attribute__ ((may_alias))
+#define BSE_NOINLINE           __attribute__ ((noinline))
+#define BSE_NORETURN            __attribute__ ((__noreturn__))
+#define BSE_NO_INSTRUMENT       __attribute__ ((__no_instrument_function__))
+#define BSE_PRINTF(fx, ax)      __attribute__ ((__format__ (__printf__, fx, ax)))
+#define BSE_PURE                __attribute__ ((__pure__))
+#define BSE_SCANF(fx, ax)       __attribute__ ((__format__ (__scanf__, fx, ax)))
+#define BSE_SENTINEL            __attribute__ ((__sentinel__))
+#define BSE_UNUSED              __attribute__ ((__unused__))
+#define BSE_USED                __attribute__ ((__used__))
+/// @}
+
+/// Return silently if @a cond does not evaluate to true, with return value @a ...
+#define BSE_RETURN_UNLESS(cond, ...)      do { if (BSE_UNLIKELY (!bool (cond))) return __VA_ARGS__; } while 
(0)
+
+/// Delete copy ctor and assignment operator.
+#define BSE_CLASS_NON_COPYABLE(ClassName)  \
+  /*copy-ctor*/ ClassName  (const ClassName&) = delete; \
+  ClassName&    operator=  (const ClassName&) = delete
+#ifdef __clang__ // clang++-3.8.0: work around 'variable length array of non-POD element type'
+#define BSE_DECLARE_VLA(Type, var, count)          std::vector<Type> var (count)
+#else // sane c++
+#define BSE_DECLARE_VLA(Type, var, count)          Type var[count] ///< Declare a variable length array 
(clang++ uses std::vector<>).
+#endif
+
+} // Bse
+
+#endif // __BSE_CXXAUX_HH__


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]