28 {
object.getClassInfo() } -> std::convertible_to<ClassInfo>;
29 {
constObject.getClassInfo() } -> std::convertible_to<ClassInfo>;
51 if constexpr(std::is_default_constructible_v<T>) {
55 if constexpr(std::is_copy_constructible_v<T>) {
65 template<
typename B>
void base();
79#define CE_META_CLASS_DEFINE_BASE(...) \
80 class ::CeresEngine::TUserTypeInfo<__VA_ARGS__> final : public TClass<__VA_ARGS__> { \
81 using ClassType = __VA_ARGS__; \
84 explicit TUserTypeInfo() { define(*this); } \
87 inline void define(TUserTypeInfo& define); \
90#define CE_META_REFLECTABLE_CLASS_BASE(...) \
91 [[nodiscard]] ::CeresEngine::ClassInfo __VA_ARGS__::getClassInfo() noexcept { \
92 return ::CeresEngine::ClassInfo{ \
93 ::CeresEngine::getTypeID<std::decay_t<decltype(*this)>>(), \
98 [[nodiscard]] ::CeresEngine::ClassInfo __VA_ARGS__::getClassInfo() const noexcept { \
99 return ::CeresEngine::ClassInfo{ \
100 ::CeresEngine::getTypeID<std::decay_t<decltype(*this)>>(), \
105#define CE_META_CLASS_DEFINE(...) \
106 template<> CE_META_CLASS_DEFINE_BASE(__VA_ARGS__); \
107 template<> const ::CeresEngine::TypeInfo& ::CeresEngine::GetTypeInfo<__VA_ARGS__>::get() { \
108 static const TUserTypeInfo<__VA_ARGS__> typeInfo; \
111 CE_META_TYPE_AUTO_REGISTRATION(__VA_ARGS__); \
112 void ::CeresEngine::TUserTypeInfo<__VA_ARGS__>::define(TUserTypeInfo& define)
114#define CE_META_REFLECTABLE_CLASS_DEFINE(...) \
115 template<> CE_META_CLASS_DEFINE_BASE(__VA_ARGS__); \
116 template<> const ::CeresEngine::TypeInfo& ::CeresEngine::GetTypeInfo<__VA_ARGS__>::get() { \
117 static const TUserTypeInfo<__VA_ARGS__> typeInfo; \
120 CE_META_TYPE_AUTO_REGISTRATION(__VA_ARGS__); \
121 CE_META_REFLECTABLE_CLASS_BASE(__VA_ARGS__) \
122 void ::CeresEngine::TUserTypeInfo<__VA_ARGS__>::define(TUserTypeInfo& define)
124#define CE_META_CLASS_TEMPLATE_DEFINE(TType, ...) \
125 template<__VA_ARGS__> CE_META_CLASS_DEFINE_BASE(TType); \
126 template<__VA_ARGS__> struct ::CeresEngine::GetTypeInfo<TType> { \
127 static const TypeInfo& get() noexcept { \
128 static const TUserTypeInfo<TType> typeInfo; \
133 template<__VA_ARGS__> void ::CeresEngine::TUserTypeInfo<TType>::define(TUserTypeInfo& define)
135#define CE_META_CLASS_TEMPLATE_SPECIALIZATION_EXTERN(...) extern template struct ::CeresEngine::GetTypeInfo<__VA_ARGS__>;
136#define CE_META_CLASS_TEMPLATE_SPECIALIZATION_DEFINE(...) \
137 template struct ::CeresEngine::GetTypeInfo<__VA_ARGS__>; \
138 CE_META_TYPE_AUTO_REGISTRATION(__VA_ARGS__);
149 using MethodInvokerTag = std::conditional_t<std::is_void_v<typename function_traits<F>::result_type>,
199 if constexpr(std::is_reference_v<Result>) {
223 using class_t = std::conditional_t<is_const_method::value, std::add_const_t<C>,
C>;
232 const Box& instance = arguments[0];
235 if constexpr(is_const_method::value) {
240 }
else if(type.isClassPtr()) {
265 using class_t = std::conditional_t<is_const_method::value, std::add_const_t<C>,
C>;
274 if constexpr(std::is_reference_v<Result>) {
275 return std::ref(std::forward<R>(
result));
277 return std::forward<R>(
result);
282 const Box& instance = arguments[0];
285 if constexpr(is_const_method::value) {
290 }
else if(type.isClassPtr()) {
320 static_assert(std::is_pointer_v<P> && !std::is_function_v<P>,
"Type should be pointer");
329 if constexpr(std::is_const_v<T>) {
349 static_assert(std::is_member_object_pointer_v<P>,
"Type should be member object pointer");
366 return std::ref(instance.
cref<
C>().*property);
368 return std::ref(instance.
ref<
C>().*property);
370 }
else if(type.isClassPtr()) {
371 return std::ref(instance.
to<
const C*>()->*property);
377 if constexpr(std::is_const_v<T>) {
386 if constexpr(std::is_assignable_v<T, T>) {
388 }
else if constexpr(std::is_copy_constructible_v<T>) {
389 (instance.
ref<
C>().*property).~T();
394 }
else if(type.isClassPtr()) {
395 if constexpr(std::is_assignable_v<T, T>) {
397 }
else if constexpr(std::is_copy_constructible_v<T>) {
398 (instance.
to<
C*>()->*property).~T();
408 if constexpr(std::is_const_v<T>) {
414 }
else if(type.isClassPtr()) {
461 return AccessorTraits::getStatic(
mPointer);
463 return AccessorTraits::getField(
mPointer, target);
468 void set(
const Box& target,
const Box& value)
const override {
470 AccessorTraits::setStatic(
mPointer, value);
472 AccessorTraits::setField(
mPointer, target, value);
477 void set(
const Box& target,
Box&& value)
const override {
479 AccessorTraits::setStatic(
mPointer, std::move(value));
481 AccessorTraits::setField(
mPointer, target, std::move(value));
492 static constexpr auto valid = (std::is_function_v<GetterType> && (std::is_void_v<SetterType> || std::is_function_v<SetterType>)) ||
493 (std::is_member_function_pointer_v<GetterType> && (std::is_void_v<SetterType> || std::is_member_function_pointer_v<SetterType>));
494 static_assert(
valid,
"Getter and setter methods should be simultaneously static method or pointer to member");
503 using T =
typename GetterTraits::result_type;
508 static_assert(!std::is_void_v<T>,
"Getter method should have non void result type");
509 static_assert(GetterTraits::arity == 0,
"Getter method shouldn't have any parameters");
510 static_assert(std::is_void_v<typename SetterTraits::result_type>,
"Setter method should have void result type");
511 static_assert(SetterTraits::arity == 1,
"Setter method should have one parameters");
512 static_assert(std::is_same_v<std::decay_t<T>, std::decay_t<SetterArgument>>,
"Getter method return type and setter method parameter type do not match");
552 void set(
const Box& target,
const Box& value)
const override {
561 void set(
const Box& target,
Box&& value)
const override {
592 const Vector<TypeID> parameters = invoker_t::getParametersTypeID();
607 static_assert((
sizeof...(Args) > 0) || std::is_default_constructible_v<C>,
"Type is not default constructible");
608 static_assert((
sizeof...(Args) == 0) || std::is_constructible_v<
C, Args...>,
"Type can not be constructed with given arguments");
636 if constexpr(std::is_same_v<std::decay_t<Argument>,
C>) {
637 if constexpr(std::is_rvalue_reference_v<Argument>) {
643 return ::CeresEngine::MetaSignature<Args...>::get(
name);
648 return ::CeresEngine::MetaSignature<Args...>::get(
name);
652 if constexpr(std::is_same_v<C, Box>) {
653 throw "not supported";
662 template<
typename DerivedType,
typename BaseType>
inline void const*
metacast_to_base(
void const* value) {
#define CE_ASSERT(...)
Definition Macros.hpp:323
A value type that can hold any alongside it's type information.
Definition Box.hpp:40
TypeID getTypeID() const noexcept
Gets the ID of the type held by the variant.
Definition Box.hpp:171
Box cref() const &
Gets a reference to the meta value.
T to() const &
Gets the value of the variant as a T.
Definition Box.hpp:332
Box ref() const &
Gets a reference to the meta value.
String name
Definition Class.hpp:157
ReflectionAttributeContainer attributes
Definition Class.hpp:54
const StringView name
Definition Class.hpp:53
StringView name
Definition Class.hpp:278
ReflectionAttributeContainer attributes
Definition Class.hpp:279
Represents a reflected property from metadata defined by the class.
Definition Class.hpp:176
ReflectionAttributeContainer attributes
Definition Class.hpp:179
StringView name
Definition Class.hpp:178
Definition MetaError.hpp:19
void set(const Type &type, Box &&value)
Sets the attribute for the given type.
Definition Class.define.hpp:48
void property(StringView name, P &&property, MetaAttributeList &&attributes={})
Definition Class.define.hpp:679
void method(StringView name, F func, MetaAttributeList &&attributes={})
Definition Class.define.hpp:695
void constructor()
Definition Class.define.hpp:673
void bases()
Definition Class.define.hpp:668
StringView getName() const noexcept final
Definition Class.define.hpp:62
TClass()
Definition Class.define.hpp:50
void base()
Definition Class.define.hpp:666
Definition TypeInfo.core.hpp:843
Represents a reflected C++ type. Can be used to get metadata from a C++ type.
Definition Type.hpp:32
TypeID getTypeID() const noexcept
Gets the type ID.
Definition Class.define.hpp:27
std::tuple_element_t< TIndex, Tuple< TTypeList > > Nth
"Nth" element of a type list.
Definition TypeListOps.hpp:29
typename PropertyTypeTrait< P >::type PropertyType
Definition Class.define.hpp:304
typename PropertyClassTrait< P >::type PropertyClass
Definition Class.define.hpp:309
std::conditional_t< std::is_member_pointer_v< P >, MemberPointerTag, StaticPointerTag > MetaPropertyAccessorTag
Definition Class.define.hpp:315
std::conditional_t< std::is_void_v< typename function_traits< F >::result_type >, std::conditional_t< std::is_void_v< typename function_traits< F >::class_type >, VoidStaticFunctionTag, VoidMemberFunctionTag >, std::conditional_t< std::is_void_v< typename function_traits< F >::class_type >, ReturnStaticFunctionTag, ReturnMemberFunctionTag > > MethodInvokerTag
Definition Class.define.hpp:151
typename index_sequence_for< Args... >::type index_sequence_for_t
Definition TypeTraits.hpp:155
Definition Application.hpp:19
SmallVector< Box, 4 > MetaValues
Definition Class.hpp:29
TypedID< internal::TypeTag, UInt64 > TypeID
Definition Forward.hpp:45
BasicStringView< char > StringView
Narrow string view used for handling narrow encoded text in UTF-8.
Definition String.hpp:190
void const * metacast_to_base(void const *value)
Definition Class.define.hpp:662
constexpr auto MoveConstructorSignature
Definition MetaContainer.hpp:24
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr StringView getTypeName()
Definition TypeName.hpp:72
CE_FLATTEN_INLINE TypeID getTypeID< void >()
Definition Type.hpp:247
constexpr auto DefaultConstructorSignature
Definition MetaContainer.hpp:22
std::array< T, N > Array
Array is a container that encapsulates fixed size arrays.
Definition Array.hpp:17
Vector< Box > MetaAttributeList
Definition Class.define.hpp:43
tcb ::span< T, Extent > Span
Span describes an object that can refer to a contiguous sequence of objects with the first element of...
Definition Span.hpp:708
constexpr auto CopyConstructorSignature
Definition MetaContainer.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
A structure that contains type information for a class.
Definition IReflectable.hpp:15
Compile-time list of types.
Definition TypeList.hpp:15
Definition TypeTraits.hpp:130
Definition Class.define.hpp:313
static Box invokeInternal(const F &func, const MetaValues &arguments, mpl::index_sequence< I... >)
Definition Class.define.hpp:281
typename function_traits< F >::args Args
Definition Class.define.hpp:249
typename function_traits< F >::result_type Result
Definition Class.define.hpp:250
static Vector< TypeID > getParametersTypeID(mpl::index_sequence< I... >)
Definition Class.define.hpp:269
static Vector< TypeID > getParametersTypeID()
Definition Class.define.hpp:254
std::conditional_t< is_const_method::value, std::add_const_t< C >, C > class_t
Definition Class.define.hpp:265
mpl::index_sequence_for_t< Args > argument_indexes_t
Definition Class.define.hpp:261
std::add_pointer_t< class_t > class_ptr_t
Definition Class.define.hpp:267
static bool isStatic()
Definition Class.define.hpp:252
typename function_traits< F >::is_const is_const_method
Definition Class.define.hpp:264
static Box reference_get(R &&result)
Definition Class.define.hpp:273
static String signature(StringView name)
Definition Class.define.hpp:255
std::add_lvalue_reference_t< class_t > class_ref_t
Definition Class.define.hpp:266
static Box invoke(const F &func, const MetaValues &arguments)
Definition Class.define.hpp:257
MPL::Nth< I, Args > argument_get_t
Definition Class.define.hpp:260
static TypeID getReturnTypeID()
Definition Class.define.hpp:253
typename function_traits< F >::class_type C
Definition Class.define.hpp:263
static String signature(StringView name)
Definition Class.define.hpp:186
typename function_traits< F >::result_type Result
Definition Class.define.hpp:181
MPL::Nth< I, Args > argument_get_t
Definition Class.define.hpp:191
mpl::index_sequence_for_t< Args > argument_indexes_t
Definition Class.define.hpp:192
static TypeID getReturnTypeID()
Definition Class.define.hpp:184
typename function_traits< F >::args Args
Definition Class.define.hpp:180
static Box invokeInternal(const F &func, const MetaValues &arguments, std::index_sequence< I... >)
Definition Class.define.hpp:198
static bool isStatic()
Definition Class.define.hpp:183
static Box invoke(const F &func, const MetaValues &arguments)
Definition Class.define.hpp:188
static Vector< TypeID > getParametersTypeID(mpl::index_sequence< I... >)
Definition Class.define.hpp:194
static Vector< TypeID > getParametersTypeID()
Definition Class.define.hpp:185
static Vector< TypeID > getParametersTypeID()
Definition Class.define.hpp:212
typename function_traits< F >::args Args
Definition Class.define.hpp:208
static TypeID getReturnTypeID()
Definition Class.define.hpp:211
static Box invokeInternal(const F &func, const MetaValues &arguments, mpl::index_sequence< I... >)
Definition Class.define.hpp:231
static String signature(StringView name)
Definition Class.define.hpp:213
std::add_pointer_t< class_t > class_ptr_t
Definition Class.define.hpp:225
std::conditional_t< is_const_method::value, std::add_const_t< C >, C > class_t
Definition Class.define.hpp:223
MPL::Nth< I, Args > argument_get_t
Definition Class.define.hpp:218
mpl::index_sequence_for_t< Args > argument_indexes_t
Definition Class.define.hpp:219
static bool isStatic()
Definition Class.define.hpp:210
static Vector< TypeID > getParametersTypeID(mpl::index_sequence< I... >)
Definition Class.define.hpp:227
std::add_lvalue_reference_t< class_t > class_ref_t
Definition Class.define.hpp:224
static Box invoke(const F &func, const MetaValues &arguments)
Definition Class.define.hpp:215
typename function_traits< F >::is_const is_const_method
Definition Class.define.hpp:222
typename function_traits< F >::class_type C
Definition Class.define.hpp:221
static Box invokeInternal(const F &func, const MetaValues &arguments, std::index_sequence< I... >)
Definition Class.define.hpp:169
static Box invoke(const F &func, const MetaValues &arguments)
Definition Class.define.hpp:163
static String signature(StringView name)
Definition Class.define.hpp:161
static Vector< TypeID > getParametersTypeID()
Definition Class.define.hpp:160
typename function_traits< F >::args Args
Definition Class.define.hpp:156
MPL::Nth< I, Args > argument_get_t
Definition Class.define.hpp:166
static bool isStatic()
Definition Class.define.hpp:158
static TypeID getReturnTypeID()
Definition Class.define.hpp:159
static Vector< TypeID > getParametersTypeID(mpl::index_sequence< I... >)
Definition Class.define.hpp:174
std::make_index_sequence< function_traits< F >::arity > argument_indexes_t
Definition Class.define.hpp:167
Definition Class.define.hpp:153
Definition Class.define.hpp:305
Definition Class.define.hpp:298
Definition Class.define.hpp:146
Definition Class.define.hpp:144
Definition Class.define.hpp:311
Definition Class.define.hpp:145
Definition Class.define.hpp:143
Definition TypeTraits.hpp:141
Definition TypeTraits.hpp:146