summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/osdcomm.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/osdcomm.h')
-rw-r--r--src/osd/osdcomm.h61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/osd/osdcomm.h b/src/osd/osdcomm.h
index eb600e65360..516dd3e681a 100644
--- a/src/osd/osdcomm.h
+++ b/src/osd/osdcomm.h
@@ -8,15 +8,15 @@
fundamental integral types as well as compiler-specific tweaks.
***************************************************************************/
-
-#pragma once
-
#ifndef MAME_OSD_OSDCOMM_H
#define MAME_OSD_OSDCOMM_H
-#include <stdio.h>
-#include <string.h>
+#pragma once
+
#include <cstdint>
+#include <cstdio>
+#include <cstring>
+
#include <type_traits>
@@ -24,15 +24,14 @@
COMPILER-SPECIFIC NASTINESS
***************************************************************************/
-/* The Win32 port requires this constant for variable arg routines. */
+// The Win32 port requires this constant for variable arg routines.
#ifndef CLIB_DECL
#define CLIB_DECL
#endif
-/* Some optimizations/warnings cleanups for GCC */
+// Some optimizations/warnings cleanups for GCC
#if defined(__GNUC__)
-#define ATTR_UNUSED __attribute__((__unused__))
#define ATTR_PRINTF(x,y) __attribute__((format(printf, x, y)))
#define ATTR_CONST __attribute__((const))
#define ATTR_FORCE_INLINE __attribute__((always_inline))
@@ -42,7 +41,6 @@
#define EXPECTED(exp) __builtin_expect(!!(exp), 1)
#define RESTRICT __restrict__
#else
-#define ATTR_UNUSED
#define ATTR_PRINTF(x,y)
#define ATTR_CONST
#define ATTR_FORCE_INLINE __forceinline
@@ -73,28 +71,12 @@ using s64 = std::int64_t;
} // namespace OSD
+
/***************************************************************************
FUNDAMENTAL MACROS
***************************************************************************/
-/* Concatenate/extract 32-bit halves of 64-bit values */
-constexpr uint64_t concat_64(uint32_t hi, uint32_t lo) { return (uint64_t(hi) << 32) | uint32_t(lo); }
-constexpr uint32_t extract_64hi(uint64_t val) { return uint32_t(val >> 32); }
-constexpr uint32_t extract_64lo(uint64_t val) { return uint32_t(val); }
-
-// Highly useful template for compile-time knowledge of an array size
-template <typename T, size_t N> constexpr size_t ARRAY_LENGTH(T (&)[N]) { return N;}
-
-// For declaring an array of the same dimensions as another array (including multi-dimensional arrays)
-template <typename T, typename U> struct equivalent_array_or_type { typedef T type; };
-template <typename T, typename U, std::size_t N> struct equivalent_array_or_type<T, U[N]> { typedef typename equivalent_array_or_type<T, U>::type type[N]; };
-template <typename T, typename U> using equivalent_array_or_type_t = typename equivalent_array_or_type<T, U>::type;
-template <typename T, typename U> struct equivalent_array { };
-template <typename T, typename U, std::size_t N> struct equivalent_array<T, U[N]> { typedef equivalent_array_or_type_t<T, U> type[N]; };
-template <typename T, typename U> using equivalent_array_t = typename equivalent_array<T, U>::type;
-#define EQUIVALENT_ARRAY(a, T) equivalent_array_t<T, std::remove_reference_t<decltype(a)> >
-
-/* Macros for normalizing data into big or little endian formats */
+// Macros for normalizing data into big or little endian formats
constexpr uint16_t swapendian_int16(uint16_t val) { return (val << 8) | (val >> 8); }
constexpr uint32_t swapendian_int32_partial16(uint32_t val) { return ((val << 8) & 0xFF00FF00U) | ((val >> 8) & 0x00FF00FFU); }
@@ -118,7 +100,7 @@ constexpr uint64_t big_endianize_int64(uint64_t x) { return x; }
constexpr uint16_t little_endianize_int16(uint16_t x) { return swapendian_int16(x); }
constexpr uint32_t little_endianize_int32(uint32_t x) { return swapendian_int32(x); }
constexpr uint64_t little_endianize_int64(uint64_t x) { return swapendian_int64(x); }
-#endif /* LSB_FIRST */
+#endif // LSB_FIRST
#ifdef _MSC_VER
using ssize_t = std::make_signed_t<size_t>;
@@ -130,4 +112,25 @@ using ssize_t = std::make_signed_t<size_t>;
#endif
#endif
-#endif /* MAME_OSD_OSDCOMM_H */
+
+// macro for defining a copy constructor and assignment operator to prevent copying
+#define DISABLE_COPYING(TYPE) \
+ TYPE(const TYPE &) = delete; \
+ TYPE &operator=(const TYPE &) = delete
+
+// macro for declaring enumeration operators that increment/decrement like plain old C
+#define DECLARE_ENUM_INCDEC_OPERATORS(TYPE) \
+inline TYPE &operator++(TYPE &value) { return value = TYPE(std::underlying_type_t<TYPE>(value) + 1); } \
+inline TYPE &operator--(TYPE &value) { return value = TYPE(std::underlying_type_t<TYPE>(value) - 1); } \
+inline TYPE operator++(TYPE &value, int) { TYPE const old(value); ++value; return old; } \
+inline TYPE operator--(TYPE &value, int) { TYPE const old(value); --value; return old; }
+
+// macro for declaring bitwise operators for an enumerated type
+#define DECLARE_ENUM_BITWISE_OPERATORS(TYPE) \
+constexpr TYPE operator~(TYPE value) { return TYPE(~std::underlying_type_t<TYPE>(value)); } \
+constexpr TYPE operator&(TYPE a, TYPE b) { return TYPE(std::underlying_type_t<TYPE>(a) & std::underlying_type_t<TYPE>(b)); } \
+constexpr TYPE operator|(TYPE a, TYPE b) { return TYPE(std::underlying_type_t<TYPE>(a) | std::underlying_type_t<TYPE>(b)); } \
+inline TYPE &operator&=(TYPE &a, TYPE b) { return a = a & b; } \
+inline TYPE &operator|=(TYPE &a, TYPE b) { return a = a | b; }
+
+#endif // MAME_OSD_OSDCOMM_H