diff options
author | Chris Robinson <[email protected]> | 2018-11-01 23:52:53 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-11-01 23:52:53 -0700 |
commit | 66df771d96d98acdf7c31d0ca5729b06502ae7d0 (patch) | |
tree | bec7b19faf2bd574c715a348cde6641e5e1ec007 /Alc/polymorphism.h | |
parent | 7307c2d5aa4a5cae73f05451ddbc1c4dcc9fad20 (diff) |
Make the polymorphism macros less hacky in C++
In particular, it relies on derived structs using C++-style inheritence. Any
implementation's source that's converted to C++ will consequently need to make
that change.
Diffstat (limited to 'Alc/polymorphism.h')
-rw-r--r-- | Alc/polymorphism.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Alc/polymorphism.h b/Alc/polymorphism.h index e837b2a5..bc0a5681 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) -#if defined(__GNUC__) && !defined(__cplusplus) + +#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) \ |