CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
NLCommon.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_NL_SAFE_CAST
17
18#define CE_NL_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_NL_RENDER_API_OBJECT_FORWARD(N) \
27 class NL##N; \
28 using NL##N##Ptr = RC<NL##N>;
30#undef CE_NL_RENDER_API_OBJECT_FORWARD
31
32 template<typename ChildTypeName, typename ParentType = void> class NLObject {
33 public:
39#if defined(CE_NL_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_NL_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_NL_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_NL_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_NL_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 NLObject<ChildTypeName, void> {};
116
117 template<typename ChildTypeName, typename ParentType = void> class NLDeviceObject : public NLObject<ChildTypeName, ParentType> {
118 protected:
121
122 protected:
125 explicit NLDeviceObject(NLDevicePtr device) : deviceNL(*device) {}
126 };
127
128#if defined(__OBJC__)
129 [[nodiscard]] NSString* NLString(const String& string);
130 [[nodiscard]] NSString* NLString(const StringView& string);
131
133 [[nodiscard]] NLLViewport NLViewport(const Viewport& viewport);
134 [[nodiscard]] NLLScissorRect NLScissorRect(const Scissor& scissor);
135#endif
136
137} // namespace CeresEngine
#define CE_NL_RENDER_API_OBJECT_FORWARD(N)
Definition NLCommon.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
Null RenderAPI device object.
Definition NLDevice.hpp:32
Definition NLCommon.hpp:117
NLDevice & deviceNL
The owning NLDevice instance.
Definition NLCommon.hpp:120
NLDeviceObject(NLDevicePtr device)
Creates a new NLDeviceObject from the given device.
Definition NLCommon.hpp:125
Definition NLCommon.hpp:32
static const ChildTypeName * safeCast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition NLCommon.hpp:112
static ChildTypeName * cast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition NLCommon.hpp:82
static const ChildTypeName & cast(const ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition NLCommon.hpp:70
static const ChildTypeName * cast(const ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition NLCommon.hpp:94
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 NLCommon.hpp:38
static ChildTypeName & cast(ParentType &object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition NLCommon.hpp:58
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 NLCommon.hpp:50
static ChildTypeName * safeCast(ParentType *object)
Casts a object of type ParentType to a object of type ChildTypeName.
Definition NLCommon.hpp:106
Definition Application.hpp:19
BasicStringView< char > StringView
Narrow string view used for handling narrow encoded text in UTF-8.
Definition String.hpp:190
BasicString< char > String
Narrow string used for handling narrow encoded text in UTF-8.
Definition String.hpp:163
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Flags< GPUMemoryProperty > GPUMemoryProperties
Flag specifying properties for a memory type.
Definition Forward.hpp:103