13#include "Refureku/Config.h"
14#include "Refureku/Misc/TypeTraitsMacros.h"
15#include "Refureku/TypeInfo/Archetypes/GetArchetype.h"
16#include "Refureku/TypeInfo/Archetypes/Struct.h"
17#include "Refureku/Misc/SharedPtr.h"
19#ifndef _RFK_UNPACK_IF_NOT_PARSING
24#define RFK_UNPACK_IF_NOT_PARSING(...)
26#define RFK_UNPACK_IF_NOT_PARSING(...) __VA_ARGS__
31namespace rfk::internal
33 RFK_GENERATE_IMPLEMENTS_TEMPLATE1_METHOD_TRAITS(_rfk_registerChildClass);
35 class CodeGenerationHelpers
38 CodeGenerationHelpers() =
delete;
39 ~CodeGenerationHelpers() =
delete;
47 template <
typename ParentClass,
typename ChildClass>
48 static constexpr void registerChildClass(
rfk::Struct& childClass)
noexcept;
56 template <
typename Derived,
typename Base>
57 RFK_NODISCARD
static constexpr std::ptrdiff_t computeClassPointerOffset() noexcept;
66 template <typename ClassType>
67 RFK_NODISCARD static std::
size_t getReflectedFieldsCount() noexcept;
76 template <typename ClassType>
77 RFK_NODISCARD static std::
size_t getReflectedStaticFieldsCount() noexcept;
87#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ <= 9
90 RFK_NODISCARD
static rfk::SharedPtr<T> defaultSharedInstantiator();
93 RFK_NODISCARD
static rfk::SharedPtr<T> defaultSharedInstantiator() noexcept(!std::is_default_constructible_v<T> || std::is_nothrow_constructible_v<T>);
104#if defined(__GNUC__) && !defined (__clang__) && __GNUC__ <= 9
106 template <
typename T>
107 RFK_NODISCARD
static rfk::UniquePtr<T> defaultUniqueInstantiator();
109 template <
typename T>
110 RFK_NODISCARD
static rfk::UniquePtr<T> defaultUniqueInstantiator() noexcept(!std::is_default_constructible_v<T> || std::is_nothrow_constructible_v<T>);
115 struct ForceGenerateSymbol
119 struct RawTypenameFormat
122 std::size_t leadingCharsCount = 0u;
125 std::size_t trailingCharsCount = 0u;
135 template <
typename T>
136 static constexpr auto const& getRawTypename() noexcept
138__RFK_DISABLE_WARNING_PUSH
139__RFK_DISABLE_WARNING_LANGUAGE_EXTENSION_TOKEN
144 return __PRETTY_FUNCTION__;
147__RFK_DISABLE_WARNING_POP
157 static constexpr bool getCompilerRawTypenameFormat(RawTypenameFormat* out_format)
noexcept
159 constexpr auto const& rawTypename = getRawTypename<char>();
161 for (std::size_t i = 0u;; i++)
164 if (rawTypename[i] ==
'c' && rawTypename[i+1] ==
'h' && rawTypename[i+2] ==
'a' && rawTypename[i+3] ==
'r')
166 if (out_format !=
nullptr)
168 out_format->leadingCharsCount = i;
169 out_format->trailingCharsCount =
sizeof(rawTypename) - i - 4 - 1;
180 inline static constexpr RawTypenameFormat typenameFormat = []
185 RawTypenameFormat format;
186 getCompilerRawTypenameFormat(&format);
198 template <
typename T>
199 constexpr auto getTypenameAsArray() noexcept
201 constexpr std::size_t typenameLength =
sizeof(getRawTypename<T>()) - typenameFormat.leadingCharsCount - typenameFormat.trailingCharsCount;
202 std::array<char, typenameLength> typename_{};
204 for (std::size_t i = 0; i < typenameLength - 1; i++)
206 typename_[i] = getRawTypename<T>()[i + typenameFormat.leadingCharsCount];
219 template <
typename T>
220 char const* getTypename() noexcept
222 static constexpr auto name = getTypenameAsArray<T>();
227 #include "Refureku/Misc/CodeGenerationHelpers.inl"