aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/polymorphism.h
diff options
context:
space:
mode:
Diffstat (limited to 'Alc/polymorphism.h')
-rw-r--r--Alc/polymorphism.h17
1 files changed, 11 insertions, 6 deletions
diff --git a/Alc/polymorphism.h b/Alc/polymorphism.h
index fa31fad2..83d5585f 100644
--- a/Alc/polymorphism.h
+++ b/Alc/polymorphism.h
@@ -2,9 +2,15 @@
#define POLYMORPHISM_H
/* Macros to declare inheriting types, and to (down-)cast and up-cast. */
+#ifdef __cplusplus
+#define STATIC_CAST(to, obj) static_cast<to*>(obj)
+#define STATIC_UPCAST(to, from, obj) static_cast<to*>(obj)
+#else
+
#define DERIVE_FROM_TYPE(t) t t##_parent
#define STATIC_CAST(to, obj) (&(obj)->to##_parent)
-#ifdef __GNUC__
+
+#if defined(__GNUC__)
#define STATIC_UPCAST(to, from, obj) __extension__({ \
static_assert(__builtin_types_compatible_p(from, __typeof(*(obj))), \
"Invalid upcast object from type"); \
@@ -13,6 +19,7 @@
#else
#define STATIC_UPCAST(to, from, obj) ((to*)((char*)(obj) - offsetof(to, from##_parent)))
#endif
+#endif /* __cplusplus */
/* Defines method forwards, which call the given parent's (T2's) implementation. */
#define DECLARE_FORWARD(T1, T2, rettype, func) \
@@ -54,7 +61,7 @@ static rettype T1##_##T2##_##func(T2 *obj, argtype1 a, argtype2 b, argtype3 c, a
/* Defines the default functions used to (de)allocate a polymorphic object. */
#define DECLARE_DEFAULT_ALLOCATORS(T) \
-static void* T##_New(size_t size) { return al_malloc(16, size); } \
+static void* T##_New(size_t size) { return al_calloc(16, size); } \
static void T##_Delete(void *ptr) { al_free(ptr); }
@@ -74,17 +81,15 @@ static void T##_Delete(void *ptr) { al_free(ptr); }
/* Allocate and construct an object, with arguments. */
#define NEW_OBJ(_res, T) do { \
- _res = T##_New(sizeof(T)); \
+ _res = (T*)T##_New(sizeof(T)); \
if(_res) \
{ \
- memset(_res, 0, sizeof(T)); \
T##_Construct(_res, EXTRACT_NEW_ARGS
/* Allocate and construct an object, with no arguments. */
#define NEW_OBJ0(_res, T) do { \
- _res = T##_New(sizeof(T)); \
+ _res = (T*)T##_New(sizeof(T)); \
if(_res) \
{ \
- memset(_res, 0, sizeof(T)); \
T##_Construct(_res EXTRACT_NEW_ARGS
/* Destructs and deallocate an object. */