diff --git a/Include/auROXTL/Objects/Objects.hpp b/Include/auROXTL/Objects/Objects.hpp index 7040c2f..e3e630b 100644 --- a/Include/auROXTL/Objects/Objects.hpp +++ b/Include/auROXTL/Objects/Objects.hpp @@ -8,4 +8,5 @@ #pragma once #include "ClassHelpers.hpp" -#include "ModuleApi.hpp" \ No newline at end of file +#include "ModuleApi.hpp" +#include "SOO.hpp" \ No newline at end of file diff --git a/Include/auROXTL/Objects/SOO.hpp b/Include/auROXTL/Objects/SOO.hpp new file mode 100644 index 0000000..1138433 --- /dev/null +++ b/Include/auROXTL/Objects/SOO.hpp @@ -0,0 +1,75 @@ +/*** + Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved. + + File: SOO.hpp + Date: 2023-1-18 + Author: Reece + + Note: ~~removed~~ + Recovered and fixed up: 2023-3-21 +***/ +#pragma once + +#if defined(_AUROXTL_INTERFACE_SOO_FORCE_NO_STRING) +#define _AUROXTL_INTERFACE_SOO_TYPE2NAME(Type) "" +#else +#define _AUROXTL_INTERFACE_SOO_TYPE2NAME(Type) #Type +#endif + +#define _AUROXTL_INTERRFACE_SOO_THIS(FullType) (reinterpret_cast(this)) + +#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(); \ + ~type(); + +#define AUROXTL_INTERFACE_SOO_HDR(Type, extends, targetSize) \ +struct Type ## SOO \ +{ \ + AUROXTL_INTERFACE_SOO_HDR_(Type ## SOO, targetSize) \ + inline extends *operator ->() \ + { \ + return (extends *)this->padding; \ + } \ + inline operator extends&() \ + { \ + return *(extends *)this->padding; \ + } \ + inline operator extends*() \ + { \ + return (extends *)this->padding; \ + } \ +}; \ +using Type ## SOO_t = Type ## SOO; + +#define AUROXTL_INTERFACE_SOO_SRC(Type, FullType) \ +Type ## SOO::Type ## SOO() \ +{ \ + if (kSSORealSize > kSSOPaddedSize) \ + { \ + AuMemoryPanic("SOO out of overhead: " \ + _AUROXTL_INTERFACE_SOO_TYPE2NAME(Type)); \ + } \ + \ + { \ + new (_AUROXTL_INTERRFACE_SOO_THIS(FullType)) FullType(); \ + } \ +} \ + \ +Type ## SOO::~ Type ## SOO() \ +{ \ + _AUROXTL_INTERRFACE_SOO_THIS(FullType)->~FullType(); \ +} \ +const AuUInt Type ## SOO::kSSORealSize = sizeof(FullType); + +#if !defined(AU_SHARED_API_SOO) +#define AU_SHARED_API_SOO(name, size, type, ...) \ + AU_SHARED_API_EX(, name, type, #__VA_ARGS__) \ + AUROXTL_INTERFACE_SOO_HDR(name, type, size) +#endif