[*] improved soo with ctors

This commit is contained in:
Reece Wilson 2023-03-21 02:33:37 +00:00
parent c20c7072e3
commit 5e0678e628
2 changed files with 83 additions and 46 deletions

View File

@ -83,7 +83,7 @@
#endif #endif
#if !defined(AU_SHARED_API) #if !defined(AU_SHARED_API)
#define AU_SHARED_API(name, type, ...) AU_SHARED_API_EX(, name, type, #__VA_ARGS__) #define AU_SHARED_API(name, type, ...) AU_SHARED_API_EX(, name, type, ##__VA_ARGS__)
#endif #endif
#if !defined(AU_NOINLINE) #if !defined(AU_NOINLINE)

View File

@ -18,58 +18,95 @@
#define _AUROXTL_INTERRFACE_SOO_THIS(FullType) (reinterpret_cast<FullType *>(this)) #define _AUROXTL_INTERRFACE_SOO_THIS(FullType) (reinterpret_cast<FullType *>(this))
#define AUROXTL_INTERFACE_SOO_HDR_(type, maxSize) \ // ??!?!
protected: \ #if !defined(_ZAUFE_FE_1_FIRST)
char padding[maxSize] {}; \ #define _ZAUFE_FE_1_FIRST(a, b)
inline type(std::nullptr_t) \ #endif
{} \
public: \ #define _AUROXTL_INTERRFACE_SOO_EMITTER_0(a) AU_EMIT_FIRST a AU_EMIT_SECOND a
static const AuUInt kSSOPaddedSize = maxSize; \ #define _AUROXTL_INTERRFACE_SOO_EMITTER_1(a) , AU_EMIT_FIRST a AU_EMIT_SECOND a
static const AuUInt kSSORealSize; \ #define _AUROXTL_INTERRFACE_SOO_EMITTER_2(a) AU_EMIT_SECOND a
type(); \ #define _AUROXTL_INTERRFACE_SOO_EMITTER_3(a) , AU_EMIT_SECOND a
#define AUROXTL_INTERFACE_SOO_HDR_(type, maxSize, ...) \
protected: \
char padding[maxSize] {}; \
inline type(std::nullptr_t) \
{} \
public: \
static const AuUInt kSSOPaddedSize = maxSize; \
static const AuUInt kSSORealSize; \
type(AU_FOR_EACH_FIRST(_AUROXTL_INTERRFACE_SOO_EMITTER_0, _AUROXTL_INTERRFACE_SOO_EMITTER_1, ## __VA_ARGS__));\
~type(); ~type();
#define AUROXTL_INTERFACE_SOO_HDR(Type, extends, targetSize) \ #define AUROXTL_INTERFACE_SOO_HDR(Type, extends, targetSize, ...) \
struct Type ## SOO \ struct Type ## SOO \
{ \ { \
AUROXTL_INTERFACE_SOO_HDR_(Type ## SOO, targetSize) \ AUROXTL_INTERFACE_SOO_HDR_(Type ## SOO, targetSize, ## __VA_ARGS__) \
inline extends *operator ->() \ inline extends *operator ->() \
{ \ { \
return (extends *)this->padding; \ return (extends *)this->padding; \
} \ } \
inline operator extends&() \ inline operator extends&() \
{ \ { \
return *(extends *)this->padding; \ return *(extends *)this->padding; \
} \ } \
inline operator extends*() \ inline operator extends*() \
{ \ { \
return (extends *)this->padding; \ return (extends *)this->padding; \
} \ } \
}; \ inline extends * AsPointer() \
{ \
return (extends *)this->padding; \
} \
\
inline const extends *operator ->() const \
{ \
return (const extends *)this->padding; \
} \
inline operator const extends&() const \
{ \
return *(const extends *)this->padding; \
} \
inline operator const extends*() const \
{ \
return (const extends *)this->padding; \
} \
inline const extends * AsPointer() const \
{ \
return (const extends *)this->padding; \
} \
}; \
using Type ## SOO_t = Type ## SOO; using Type ## SOO_t = Type ## SOO;
#define AUROXTL_INTERFACE_SOO_SRC(Type, FullType) \ #define AUROXTL_INTERFACE_SOO_SRC(Type, FullType, ...) \
Type ## SOO::Type ## SOO() \ Type ## SOO::Type ## SOO(AU_FOR_EACH_FIRST(_AUROXTL_INTERRFACE_SOO_EMITTER_0, _AUROXTL_INTERRFACE_SOO_EMITTER_1, ## __VA_ARGS__)) \
{ \ { \
if (kSSORealSize > kSSOPaddedSize) \ if (kSSORealSize > kSSOPaddedSize) \
{ \ { \
AuMemoryPanic("SOO out of overhead: " \ AuMemoryPanic("SOO out of overhead: " \
_AUROXTL_INTERFACE_SOO_TYPE2NAME(Type)); \ _AUROXTL_INTERFACE_SOO_TYPE2NAME(Type)); \
} \ } \
\ \
{ \ { \
new (_AUROXTL_INTERRFACE_SOO_THIS(FullType)) FullType(); \ new (_AUROXTL_INTERRFACE_SOO_THIS(FullType)) FullType(AU_FOR_EACH_FIRST(_AUROXTL_INTERRFACE_SOO_EMITTER_2, _AUROXTL_INTERRFACE_SOO_EMITTER_3, ## __VA_ARGS__)); \
} \ } \
} \ } \
\ \
Type ## SOO::~ Type ## SOO() \ Type ## SOO::~ Type ## SOO() \
{ \ { \
_AUROXTL_INTERRFACE_SOO_THIS(FullType)->~FullType(); \ _AUROXTL_INTERRFACE_SOO_THIS(FullType)->~FullType(); \
} \ } \
const AuUInt Type ## SOO::kSSORealSize = sizeof(FullType); const AuUInt Type ## SOO::kSSORealSize = sizeof(FullType);
#if !defined(AU_SHARED_API_SOO) #if !defined(AU_SHARED_API_SOO)
#define AU_SHARED_API_SOO(name, size, type, ...) \ #define AU_SHARED_API_SOO(name, size, type, ...) \
AU_SHARED_API_EX(, name, type, #__VA_ARGS__) \ AU_SHARED_API_EX(, name, type, ##__VA_ARGS__) \
AUROXTL_INTERFACE_SOO_HDR(name, type, size) AUROXTL_INTERFACE_SOO_HDR(name, type, size)
#endif #endif
#if !defined(AU_SHARED_API_SOO_2)
#define AU_SHARED_API_SOO_2(name, size, type, ctr, ...) \
AU_SHARED_API_EX(, name, type, ##__VA_ARGS__) \
AUROXTL_INTERFACE_SOO_HDR(name, type, size, AU_WHAT ctr)
#endif