libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_type.hpp
1#ifndef GIMBAL_TYPE_HPP
2#define GIMBAL_TYPE_HPP
3
4#include "gimbal_type.h"
5#include "../types/gimbal_typedefs.hpp"
6#include "../core/gimbal_api_generators.hpp"
7#include "../types/gimbal_result.hpp"
8#include "../objects/gimbal_context.hpp"
9#include "../meta/gimbal_primitives.h"
10#include "../meta/gimbal_enum.h"
11#include "../meta/gimbal_flags.h"
12
13#define GBL_TYPE_DECLARE_CPP(cppName, cName)
14 class cppName final: public Type {
15 public:
16 cppName(void): Type(cName) {}
17 }
18
19namespace gimbal {
20
21class Class;
22
24public:
25 TypeFlags(unsigned value):
26 TypeFlags(static_cast<GblTypeFlags>(value)) {}
27
28 TypeFlags(GblTypeFlags flags=static_cast<GblTypeFlags>(0)):
29 PrimitiveBase(flags) {}
30
31};
32
33class TypeInfo: public GblTypeInfo {
34public:
35
36};
37
38class Type: public PrimitiveBase<GblType> {
39public:
40
41 Type(GblType type=GBL_INVALID_TYPE);
42 Type(float) = delete;
43 Type(double) = delete;
44 Type(unsigned) = delete;
45
46 const char* getName(void) const;
47 Type getParentType(void) const;
48 Type getFundamentalType(void) const;
49 const TypeInfo* getInfo(void) const;
50 UInt getDepth(void) const;
51
52 bool isValid(void) const;
53 bool isClassed(void) const;
54 bool isInstantiable(void) const;
55 bool isDerivable(void) const;
56 bool isDeepDerivable(void) const;
57 bool isAbstract(void) const;
58 bool isFinal(void) const;
59 bool isInterfaced(void) const;
60 bool isFundamental(void) const;
61
62 bool isA(Type base) const;
63 bool isFundamentallyA(Type base) const;
64 RefCount getClassRefCount(void) const;
65#ifdef GBL_TYPE_DEBUG
66 RefCount getInstanceRefCount(void) const;
67#endif
68
69 void* instanceCreate (void) const;
70 void instanceConstruct (void* pInstance) const;
71 void instanceDestruct (void* pInstance) const;
72 void instanceDestroy (void* pInstance) const;
73
74 void* classReference (void) const;
75 void classUnreference (void* pClass) const;
76
77// static API
78 static Result init(Context* pCtx =nullptr,
79 Size typeBuiltinInitialCount =0,
80 Size typeTotalInitialCount =0);
81 static Type registerStatic(Type parentType,
82 const char* pName,
83 TypeInfo typeInfo,
84 TypeFlags flags);
85 static void unregister(Type type);
86
87 static Size count(void);
88 static Type fromName(const char* pName);
89
90 static void* instanceCreate (Type type);
91 static void instanceConstruct (Type type, void* pInstance);
92 static void instanceDestruct (Type type, void* pInstance);
93 static void instanceDestroy (Type type, void* pInstance);
94
95 static void* classReference (Type type);
96 static void* classPeek (Type type);
97 static void classUnreference (Type type, void* pClass);
98};
99
100
101
102template<typename P,
103 typename C,
104 typename I>
105class StaticType: public Type {
106public:
107 using ParentType = P;
108 using ClassType = C;
109 using InstanceType = I;
110
111protected:
112 StaticType(Type type): Type(std::move(type)) {}
113#if 0
114 ClassRef<ClassType> getClassRef(void) const {
115 return Type::classRef();
116 }
117#endif
118
119 InstanceType* createInstance(void) const;
120 void destroyInstance(InstanceType* pInstance) const;
121
122 Type registerStatic(const char* pName, TypeFlags flags) {
123 const TypeInfo info = {
124 {
125 .classSize = sizeof(C),
126 .instanceSize = sizeof(I)
127 }
128 };
129 return Type::registerStatic(P(), pName, info, flags);
130 }
131
132};
133
135GBL_TYPE_DECLARE_CPP(InterfaceType, GBL_INTERFACE_TYPE);
136GBL_TYPE_DECLARE_CPP(IVariantType, GBL_IVARIANT_TYPE);
137GBL_TYPE_DECLARE_CPP(NilType, GBL_NIL_TYPE);
138GBL_TYPE_DECLARE_CPP(BoolType, GBL_BOOL_TYPE);
139GBL_TYPE_DECLARE_CPP(CharType, GBL_CHAR_TYPE);
140GBL_TYPE_DECLARE_CPP(Uint8Type, GBL_UINT8_TYPE);
141GBL_TYPE_DECLARE_CPP(Uint16Type, GBL_UINT16_TYPE);
142GBL_TYPE_DECLARE_CPP(Int16Type, GBL_INT16_TYPE);
143GBL_TYPE_DECLARE_CPP(Uint32Type, GBL_UINT32_TYPE);
144GBL_TYPE_DECLARE_CPP(Int32Type, GBL_INT32_TYPE);
145GBL_TYPE_DECLARE_CPP(Uint64Type, GBL_UINT64_TYPE);
146GBL_TYPE_DECLARE_CPP(Int64Type, GBL_INT64_TYPE);
147GBL_TYPE_DECLARE_CPP(EnumType, GBL_ENUM_TYPE);
148GBL_TYPE_DECLARE_CPP(FlagsType, GBL_FLAGS_TYPE);
149GBL_TYPE_DECLARE_CPP(FloatType, GBL_FLOAT_TYPE);
150GBL_TYPE_DECLARE_CPP(DoubleType, GBL_DOUBLE_TYPE);
151GBL_TYPE_DECLARE_CPP(PointerType, GBL_POINTER_TYPE);
152GBL_TYPE_DECLARE_CPP(StringType, GBL_STRING_TYPE);
153
154
155// ==== INLINEZ =====
156inline Type::Type(GblType type): PrimitiveBase(type) {}
157inline const char* Type::getName(void) const { return GblType_name(*this); }
158inline Type Type::getParentType(void) const { return GblType_parent(*this); }
159inline UInt Type::getDepth(void) const { return GblType_depth(*this); }
160inline Type Type::getFundamentalType(void) const { return GblType_root(*this); }
161inline const TypeInfo* Type::getInfo(void) const { return static_cast<const TypeInfo*>(GblType_info(*this)); }
162inline bool Type::isA(Type base) const { return GblType_check(*this, base); }
163inline RefCount Type::getClassRefCount(void) const { return GblType_classRefCount(*this); }
164inline bool Type::isValid(void) const { return *this != GBL_INVALID_TYPE; }
165
166inline bool Type::isClassed(void) const { return GBL_TYPE_CLASSED_CHECK(*this); }
167inline bool Type::isInstantiable(void) const { return GBL_TYPE_INSTANTIABLE_CHECK(*this); }
168inline bool Type::isDerivable(void) const { return GBL_TYPE_DERIVABLE_CHECK(*this); }
169inline bool Type::isDeepDerivable(void) const { return GBL_TYPE_DEEP_DERIVABLE_CHECK(*this); }
170inline bool Type::isAbstract(void) const { return GBL_TYPE_ABSTRACT_CHECK(*this); }
171inline bool Type::isFinal(void) const { return GBL_TYPE_FINAL_CHECK(*this); }
172inline bool Type::isInterfaced(void) const { return GBL_TYPE_INTERFACED_CHECK(*this); }
173inline bool Type::isRoot(void) const { return GBL_TYPE_ROOT_CHECK(*this); }
174
175inline void* Type::instanceCreate (void) const { return Type::instanceCreate(*this); }
176inline void Type::instanceConstruct (void* pInstance) const { return Type::instanceConstruct(*this, pInstance); }
177inline void Type::instanceDestruct (void* pInstance) const { Type::instanceDestruct(*this, pInstance); }
178inline void Type::instanceDestroy (void* pInstance) const { Type::instanceDestroy(*this, pInstance); }
179
180inline void* Type::classReference (void) const { return Type::classReference(*this); }
181inline void Type::classUnreference (void* pClass) const { return Type::classUnreference(*this, pClass); }
182
183inline Result Type::init(Context* pCtx, Size initialBuiltinCount, Size initialTotalCount) {
184 return GblType_init(pCtx, initialBuiltinCount, initialTotalCount);
185}
186
187inline Type Type::registerStatic(Type parentType,
188 const char* pName,
189 TypeInfo typeInfo,
190 TypeFlags flags)
191{
192 return GblType_registerStatic(parentType,
193 pName,
194 &typeInfo,
195 flags);
196}
197
198inline void Type::unregister(Type type) {
199 Exception::checkThrow(GblType_unregister(type));
200}
201
202inline Type Type::fromName(const char* pName) {
203 return GblType_fromName(pName);
204}
205inline Size Type::count(void) {
206 return GblType_registeredCount();
207}
208
209inline void* Type::instanceCreate (Type type) { return GblInstance_create(type); }
210inline void Type::instanceConstruct (Type type, void* pInstance) { GblInstance_construct(reinterpret_cast<GblInstance*>(pInstance), type); }
211inline void Type::instanceDestruct (Type type, void* pInstance) { GblInstance_destruct(reinterpret_cast<GblInstance*>(pInstance)); }
212inline void Type::instanceDestroy (Type type, void* pInstance) { GblInstance_destroy(reinterpret_cast<GblInstance*>(pInstance)); }
213
214inline void* Type::classReference (Type type) { return GblClass_refDefault(type); }
215inline void Type::classUnreference (Type type, void* pClass) { GblClass_unrefDefault(reinterpret_cast<GblClass*>(pClass)); }
216
217}
218
219#endif // GIMBAL_TYPE_HPP
#define GBL_TYPE_ROOT_CHECK(type)
#define GBL_TYPE_DEEP_DERIVABLE_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_ROOT_FLAG_DEEP_DERIVABLE flag.
#define GBL_TYPE_DERIVABLE_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_ROOT_FLAG_DERIVABLE flag.
#define GBL_TYPE_INSTANTIABLE_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_ROOT_FLAG_INSTANTIABLE flag.
#define GBL_TYPE_CLASSED_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_ROOT_FLAG_CLASSED flag.
#define GBL_TYPE_FINAL_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_FINAL flag ///<.
#define GBL_TYPE_INTERFACED_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_ROOT_FLAG_INTERFACED flag.
#define GBL_TYPE_ABSTRACT_CHECK(type)
Convenience macro checking a GblType's GBL_TYPE_ABSTRACT flag.
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
Definition gimbal_type.h:31
#define GBL_TYPE_DECLARE_CPP(cppName, cName)
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51