Loading...
Searching...
No Matches
rtti.hpp
Go to the documentation of this file.
1
3#pragma once
4
5#include <iostream>
6
7#include "meta/common.hpp"
8#include "meta/type/adam.hpp"
9
10namespace by {
11
17 struct _nout metaIf {
18 typedef short yes;
19 typedef char no;
20 };
21
27 template <typename T> struct tifHasDefaultCtor: public metaIf {
28 template <typename X, typename = decltype(X())> static yes test(X*);
29
30 template <typename X> static no test(...);
31
32 static constexpr nbool is = sizeof(decltype(test<T>(nullptr))) == sizeof(yes);
33 };
34
40 template <typename T> struct tifTemplate: public metaIf {
41 template <template <typename> class Template, typename X> static yes _foo(Template<X>*);
42 static no _foo(...);
43
44 static inline constexpr nbool is = sizeof(_foo((T*) 0)) == sizeof(yes);
45 };
46
52 template <typename T, typename super> // is T is sub of super
53 struct tifSub {
54 static inline constexpr nbool is = std::is_base_of<super, T>::value;
55 };
56
57 template <typename T, typename super> struct tifSub<T&, super> {
58 static inline constexpr nbool is = std::is_base_of<super, T>::value;
59 };
60
61 template <typename T, typename super> struct tifSub<T, super&> {
62 static inline constexpr nbool is = std::is_base_of<super, T>::value;
63 };
64
65 template <typename T, typename super> struct tifSub<T&, super&> {
66 static inline constexpr nbool is = std::is_base_of<super, T>::value;
67 };
68
74 template <typename T> struct taEmptyCan {
75 typedef void is;
76 };
77
83 template <typename T, typename = void> struct tifHasSuperTypedef: public metaIf {
84 static inline constexpr nbool is = false;
85 };
86
87 template <typename T> struct tifHasSuperTypedef<T, typename taEmptyCan<typename T::super>::is>: public metaIf {
88 static inline constexpr nbool is = true;
89 };
90
99
100 template <typename T> struct tadaptiveSuper<T, true> {
101 typedef typename T::super super;
102 };
103
110 static void* make() { return nullptr; }
111 };
112
113 template <typename T> struct tinstanceMaker<T, true> {
114 static void* make() { return (void*) new T(); }
115 };
116
132 template <typename T> struct tnameGetter {
133 static const nchar* getRawName() { return typeid(T).name(); }
134
135 static std::string getName() {
136 std::string ret = platformAPI::filterDemangle(getRawName());
137
138 return ret;
139 }
140 };
141
142 // famous void_t def:
143 // predefined at c++17 (if we use c++17, we can remove this)
144 template <typename T> using void_t = void;
145
151 template <typename T, typename = void> struct tifHasMetaTypeDef: public metaIf {
152 static inline constexpr nbool is = false;
153 };
154
155 template <typename T> struct tifHasMetaTypeDef<T, typename taEmptyCan<typename T::metaType>::is>: public metaIf {
156 static inline constexpr nbool is = true;
157 };
158
167
168 template <typename T> struct tmetaTypeDef<T, true> {
169 using is = typename T::metaType;
170 };
171
172 template <typename T, typename... Es> using areBaseOfT = std::conjunction<std::is_base_of<T, Es>...>;
173} // namespace by
Root base class for the type hierarchy.
Definition adam.hpp:34
Core class for runtime type information in byeol language.
Definition type.hpp:100
Base interface for SFINAE-based type checking.
Definition rtti.hpp:17
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34
Helper struct for SFINAE detection patterns.
Definition rtti.hpp:74
Adaptive super type selector.
Definition rtti.hpp:96
Type trait to check if type has default constructor.
Definition rtti.hpp:27
Type trait to check if type has metaType definition.
Definition rtti.hpp:151
Type trait to check if type has super typedef.
Definition rtti.hpp:83
Type trait to check if T is subclass of super.
Definition rtti.hpp:53
Type trait to check if type is a template specialization.
Definition rtti.hpp:40
Instance factory for type creation.
Definition rtti.hpp:109
Meta type definition selector.
Definition rtti.hpp:164
Template name getter for type introspection.
Definition rtti.hpp:132