1 #ifndef GIMBAL_META_HPP
2 #define GIMBAL_META_HPP
5 #include "../types/gimbal_typedefs.hpp"
10 template<
typename T=
void>
13 GblMetaTypeVTable({}) {}
17 #define CHECK_ADD_OVERRIDE(cFunc, cppFunc) \
19 if constexpr(requires { this->pFn##cFunc = &Derived::cppFunc; }) { \
20 this->pFn##cFunc = &Derived::cppFunc; \
24 template<
typename Derived>
25 struct MetaTypeVTableStatic:
public MetaTypeVTable,
public Derived {
26 using ThisType = void;
27 using DerivedType = Derived;
28 MetaTypeVTableVTableStatic(
void) {
29 CHECK_ADD_OVERRIDE(Construct, construct);
30 CHECK_ADD_OVERRIDE(Destruct, destruct);
31 CHECK_ADD_OVERRIDE(Convert, convert);
32 CHECK_ADD_OVERRIDE(Compare, compare);
33 CHECK_ADD_OVERRIDE(Serialize, serialize);
34 CHECK_ADD_OVERRIDE(Deserialize, deserialize);
42 template<
typename CRTP>
50 typename = std::enable_if_t<std::is_function_v<F>>>
52 const V* pVTable = getVTable<V>();
53 return pVTable->*pMethod;
58 typename = std::enable_if_t<std::is_function_v<F>>>
60 return vMethod(pMethod) !=
nullptr;
65 typename = std::enable_if_t<std::is_function_v<F>>>
66 decltype(
auto)
vCall(F V::*pMethod, auto&&... args)
const {
69 return pFunc(std::forward<decltype(args)...>);
72 template<
typename V=const
void*>
74 if(
sizeof(V) > getDispatcher_()->vTableSizeOf)
return nullptr;
75 return getDispatcher_()->pVTable();
78 operator const GblDispatcher*()
const {
return getDispatcher_();}
81 const GblDispatcher* getDispatcher_(
void)
const {
return static_cast<const CRTP
>(
this)->getDispatcher(); }
88 pDispatcher_(pSource) {}
92 const GblDispatcher* pDispatcher_ =
nullptr;
100 operator GblDispatcher*() {
return static_cast<GblDispatcher*
>(
this); }
101 const GblDispatcher*
getDispatcher_(
void)
const {
return static_cast<const GblDispatcher*
>(
this); }
114 template<
typename CRTP>
122 return getMetaInstance_();
127 return static_cast<CRTP
>(
this)->getMetaInstance_();
134 pInstance_(pSource) {}
159 template<
typename T=
void>
164 template<
typename V=MetaTypeVTable<T>>
165 requires std::is_base_of_v<GblMetaTypeVTable, V>
169 GBL_VARIANT_TYPE_NIL,
170 GBL_META_TYPE_ID_INVALID,
171 GBL_META_TYPE_FLAG_NONE,
211 Exception::checkThrow(gblMetaTypeCompare(
this, *pCtx,
reinterpret_cast<const void*
>(pData), &rhs, &result));
214 bool compare(
Context* pCtx,
const T* pData,
const Variant& rhs, Variant::OpCmpType cmpType)
const {
216 return GBL_COMPARISON_VERIFY_OP_CMP_TYPE(result, cmpType);
219 Exception::checkThrow(gblMetaTypeSerialize(
this, *pCtx,
reinterpret_cast<const void*
>(pData), pBuffer, pSize));
223 Exception::checkThrow(gblMetaTypeDeserialize(
this, *pCtx,
reinterpret_cast<void*
>(pData), pBuffer, pSize));
232 #endif // GIMBAL_META_HPP