CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MKCommon.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
11
13
15
16#define CE_MK_SAFE_CAST
17
18#define CE_MK_POOLED(T) \
19 using Allocator = VKObjectAllocator; \
20 [[nodiscard]] static Allocator& getAllocator() noexcept; \
21 [[nodiscard]] static void* operator new(size_t size) noexcept; \
22 static void operator delete(void* p, std::size_t size) noexcept;
23
24namespace CeresEngine {
25
26#define CE_MK_RENDER_API_OBJECT_FORWARD(N) \
27 class MK##N; \
28 using MK##N##Ptr = RC<MK##N>;
30#undef CE_MK_RENDER_API_OBJECT_FORWARD
31
32 template<typename ChildTypeName, typename ParentType = void> class MKObject {
33 public:
39#if defined(CE_MK_SAFE_CAST)
40 return RC<ChildTypeName>(static_cast<ChildTypeName*>(ptr.get()));
41#else
42 return safeCast<ChildTypeName>(ptr);
43#endif
44 }
45
51 return RC<ChildTypeName>(dynamic_cast<ChildTypeName*>(ptr.get()));
52 }
53
58 [[nodiscard]] static ChildTypeName& cast(ParentType& object) {
59#if defined(CE_MK_SAFE_CAST)
60 return static_cast<ChildTypeName&>(object);
61#else
62 return dynamic_cast<ChildTypeName&>(object);
63#endif
64 }
65
70 [[nodiscard]] static const ChildTypeName& cast(const ParentType& object) {
71#if defined(CE_MK_SAFE_CAST)
72 return static_cast<const ChildTypeName&>(object);
73#else
74 return dynamic_cast<const ChildTypeName&>(object);
75#endif
76 }
77
82 [[nodiscard]] static ChildTypeName* cast(ParentType* object) {
83#if defined(CE_MK_SAFE_CAST)
84 return static_cast<ChildTypeName*>(object);
85#else
86 return safeCast<ChildTypeName*>(object);
87#endif
88 }
89
94 [[nodiscard]] static const ChildTypeName* cast(const ParentType* object) {
95#if defined(CE_MK_SAFE_CAST)
96 return static_cast<const ChildTypeName*>(object);
97#else
98 return safeCast<const ChildTypeName*>(object);
99#endif
100 }
101
106 [[nodiscard]] static ChildTypeName* safeCast(ParentType* object) { return dynamic_cast<ChildTypeName*>(object); }
107
112 [[nodiscard]] static const ChildTypeName* safeCast(const ParentType* object) { return dynamic_cast<const ChildTypeName*>(object); }
113 };
114
115 template<typename ChildTypeName> class MKObject<ChildTypeName, void> {};
116
117 template<typename ChildTypeName, typename ParentType = void> class MKDeviceObject : public MKObject<ChildTypeName, ParentType> {
118 protected:
121
122 protected:
125 explicit MKDeviceObject(MKDevicePtr device) : deviceMK(*device) {}
126 };
127
129
130#if defined(__OBJC__)
131 [[nodiscard]] NSString* MKString(const String& string);
132 [[nodiscard]] NSString* MKString(const StringView& string);
133
135 [[nodiscard]] MKLViewport MKViewport(const Viewport& viewport);
136 [[nodiscard]] MKLScissorRect MKScissorRect(const Scissor& scissor);
137#endif
138
139} // namespace CeresEngine
#define CE_MK_RENDER_API_OBJECT_FORWARD(N)
Definition MKCommon.hpp:26
#define CE_RENDER_API_OBJECT_EACH(F)
A macro that invokes the function-macro F for every RenderAPI object type.
Definition Forward.hpp:18
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Pointer get() const noexcept
Definition SmartPtr.hpp:244
Mock RenderAPI device object.
Definition MKDevice.hpp:32
Definition MKCommon.hpp:117
MKDevice & deviceMK
The owning MKDevice instance.
Definition MKCommon.hpp:120
MKDeviceObject(MKDevicePtr device)
Creates a new MKDeviceObject from the given device.
Definition MKCommon.hpp:125
Definition MKCommon.hpp:32
static const ChildTypeName & cast(const ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition MKCommon.hpp:70
static RC< ChildTypeName > cast(const RC< ParentType > &ptr)
Casts a RC containing a ParentType pointer to a pointer to a pointer to a ChildTypeName.
Definition MKCommon.hpp:38
static ChildTypeName * cast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition MKCommon.hpp:82
static ChildTypeName & cast(ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition MKCommon.hpp:58
static ChildTypeName * safeCast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition MKCommon.hpp:106
static const ChildTypeName * safeCast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition MKCommon.hpp:112
static RC< ChildTypeName > safeCast(const RC< ParentType > &ptr)
Safely casts a RC containing a ParentType pointer to a pointer to a pointer to a ChildTypeName.
Definition MKCommon.hpp:50
static const ChildTypeName * cast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition MKCommon.hpp:94
Definition Application.hpp:19
void MKNotImplemented()
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition GPUGraphicsPipeline.hpp:281
Definition GPUGraphicsPipeline.hpp:214