From 0360d094d2c57dc2a1edf0f62b5b4e04b8926b50 Mon Sep 17 00:00:00 2001 From: Light Date: Mon, 26 Jul 2021 10:00:29 +0430 Subject: [PATCH] Ref. Scope - Added Ref and Scope types to replace the std::shared_ptr and std::unique_ptr, currently it is being used as an alias --- Engine/src/Engine/Base.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Engine/src/Engine/Base.h b/Engine/src/Engine/Base.h index a671a63..cc22097 100644 --- a/Engine/src/Engine/Base.h +++ b/Engine/src/Engine/Base.h @@ -31,6 +31,7 @@ #endif + // operations #define BIT(x) 1 << x @@ -43,6 +44,42 @@ #define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } } #endif +namespace Light { + + // Ref (std::shared_ptr) + template + using Ref = std::shared_ptr; + + template + constexpr std::shared_ptr CreateRef(Args... args) + { + return std::make_shared(std::forward(args)...); + } + + template + constexpr std::shared_ptr MakeRef(T* rawPointer) + { + return std::shared_ptr(T); + } + + // Scope (std::unique_ptr) + template + using Scope = std::unique_ptr; + + template + constexpr std::unique_ptr CreateScope(Args... args) + { + return std::make_unique(std::forward(args)...); + } + + template + constexpr std::unique_ptr MakeScope(T* rawPointer) + { + return std::unique_ptr(rawPointer); + } + +} + ///*** [ PORTABLES ] ***/// //** PORTABLE_DEBUG_BREAK **// // copied from: https://github.com/nemequ/portable-snippets/tree/master/debug-trap