CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
SmartPtr.hpp File Reference
#include "CeresEngine/DataTypes.hpp"
#include "CeresEngine/Macros.hpp"
#include "CeresEngine/Foundation/Hash.hpp"
#include "CeresEngine/Foundation/Container/Atomic.hpp"
#include <atomic>
#include <memory>
#include <type_traits>
#include <cstring>

Go to the source code of this file.

Classes

struct  CeresEngine::AdoptPtrT
 A tag type that is used to adopt a pointer, rather than retain it upon construction.
 
class  CeresEngine::CountedPtr< T >
 A retain-release type of smart pointer. More...
 
class  CeresEngine::RefCounter< true >
 A class that implements a simple interface for reference counting. More...
 
class  CeresEngine::RefCounter< false >
 A class that implements a simple interface for reference counting. More...
 
class  CeresEngine::RefCounted< T, Counter, Deleter >
 A simple reference counter base class. More...
 
class  CeresEngine::CopyOnWritePtr< T >
 A copy-on-write pointer type that shares a single instance of an object when copied but allows. More...
 
struct  CeresEngine::CopyOnWritePtr< T >::Data
 
class  CeresEngine::ValuePtr< T, SmallSize >
 A pointer type that has value semantics. More...
 
struct  CeresEngine::ValuePtr< T, SmallSize >::VTable
 
struct  CeresEngine::ValuePtr< T, SmallSize >::ConstructTag< TT >
 A tag used for tagged dispatching the object constructing constructor. More...
 

Namespaces

namespace  CeresEngine
 

Concepts

concept  CeresEngine::IntrusiveReferenceCountable
 A concept type that checks if a given type T has a intrusive retain
 
concept  CeresEngine::ReferenceCountable
 A concept type that checks if a given type T has a CountedPtrTrait specialization that allows it to be used with RC.
 

Macros

#define CE_RCPTR_TRAIT_DECL(ClassName)
 
#define CE_RCPTR_TRAIT_DEF(ClassName)
 
#define CE_VPTR_TMPL(T)   typename T, size_t T##SmallSize
 
#define CE_VPTR_TYPE(T)   ValuePtr<T, T##SmallSize>
 

Typedefs

template<typename T , typename Deleter = std::default_delete<T>>
using CeresEngine::UPtr = std::unique_ptr< T, Deleter >
 UPtr is a smart pointer that owns and manages another object through a pointer and disposes of that object when the unique_ptr goes out of scope.
 
template<typename T >
using CeresEngine::SPtr = std::shared_ptr< T >
 SPtr is a smart pointer that retains shared ownership of an object through a pointer.
 
template<typename T >
using CeresEngine::WPtr = std::weak_ptr< T >
 WPtr is a smart pointer that holds a non-owning ("weak") reference to an object that is managed by SPtr.
 
template<typename T >
using CeresEngine::RC = CountedPtr< T >
 RC is a smart pointer that retains shared ownership of an object through a pointer.
 
template<typename T >
using CeresEngine::CoW = CopyOnWritePtr< T >
 A copy-on-write pointer type that shares a single instance of an object when copied but allows.
 
template<typename T , size_t SmallSize = sizeof(int*) * 3>
using CeresEngine::VPtr = ValuePtr< T, SmallSize >
 A pointer type that has value semantics.
 

Functions

template<typename T , typename... Args>
constexpr TCeresEngine::ce_new (Args &&... args)
 
template<typename T , typename... Args>
constexpr UPtr< TCeresEngine::ce_unique_new (Args &&... args)
 
template<typename T , typename RawAllocator , typename... Args>
constexpr UPtr< T, AllocatorDeleter< T, RawAllocator > > CeresEngine::ce_unique_alloc (RawAllocator &allocator, Args &&... args)
 
template<typename T , typename... Args>
constexpr SPtr< TCeresEngine::ce_shared_new (Args &&... args)
 
template<typename T , typename Allocator , typename... Args>
constexpr SPtr< TCeresEngine::ce_shared_alloc (Allocator &allocator, Args &&... args)
 
template<typename Pointer >
 CeresEngine::CountedPtr (Pointer) -> CountedPtr< Pointer >
 
template<ReferenceCountable T>
RC< TCeresEngine::ce_counted_adopt (T *const ptr)
 
template<ReferenceCountable T, typename... Args>
RC< TCeresEngine::ce_counted_new (Args &&... args)
 
template<typename U1 , typename U2 >
bool CeresEngine::operator== (const CountedPtr< U1 > &a, const CountedPtr< U2 > &b) noexcept
 
template<typename U1 , typename U2 >
bool CeresEngine::operator!= (const CountedPtr< U1 > &a, const CountedPtr< U2 > &b) noexcept
 
template<typename U1 , typename U2 >
bool CeresEngine::operator== (const CountedPtr< U1 > &a, const U2 *b) noexcept
 
template<typename U1 , typename U2 >
bool CeresEngine::operator!= (const CountedPtr< U1 > &a, const U2 *b) noexcept
 
template<typename U1 , typename U2 >
bool CeresEngine::operator== (const U1 *a, const CountedPtr< U2 > &b) noexcept
 
template<typename U1 , typename U2 >
bool CeresEngine::operator!= (const U1 *a, const CountedPtr< U2 > &b) noexcept
 
template<typename U >
bool CeresEngine::operator== (const CountedPtr< U > &a, std::nullptr_t) noexcept
 
template<typename U >
bool CeresEngine::operator!= (const CountedPtr< U > &a, std::nullptr_t) noexcept
 
template<typename T , typename U = T, typename... Args>
CopyOnWritePtr< TCeresEngine::ce_cow_new (Args &&... args)
 Creates a new copy-on-write pointer by constructing a new object of type U.
 
template<typename T , size_t TSmallSize, typename U , size_t USmallSize>
bool CeresEngine::operator== (const ValuePtr< T, TSmallSize > &lhs, const ValuePtr< U, USmallSize > &rhs) noexcept
 Compares if two ValuePtr objects are equal.
 
template<typename T , size_t TSmallSize, typename U >
bool CeresEngine::operator== (const ValuePtr< T, TSmallSize > &lhs, const U &rhs) noexcept
 Compares if two ValuePtr objects are equal.
 
template<typename U , typename T , size_t TSmallSize>
bool CeresEngine::operator== (const U &lhs, const ValuePtr< T, TSmallSize > &rhs) noexcept
 Compares if two ValuePtr objects are equal.
 
template<typename T , size_t TSmallSize, typename U , size_t USmallSize>
bool CeresEngine::operator!= (const ValuePtr< T, TSmallSize > &lhs, const ValuePtr< U, USmallSize > &rhs) noexcept
 Compares if two ValuePtr objects are not equal.
 
template<typename T , size_t TSmallSize, typename U >
bool CeresEngine::operator!= (const ValuePtr< T, TSmallSize > &lhs, const U &rhs) noexcept
 Compares if two ValuePtr objects are not equal.
 
template<typename U , typename T , size_t TSmallSize>
bool CeresEngine::operator!= (const U &lhs, const ValuePtr< T, TSmallSize > &rhs) noexcept
 Compares if two ValuePtr objects are not equal.
 
template<typename T , size_t TSmallSize, typename U , size_t USmallSize>
bool CeresEngine::operator> (const ValuePtr< T, TSmallSize > &lhs, const ValuePtr< U, USmallSize > &rhs) noexcept
 Compares if a ValuePtr object is greater than another.
 
template<typename T , size_t TSmallSize, typename U >
bool CeresEngine::operator> (const ValuePtr< T, TSmallSize > &lhs, const U &rhs) noexcept
 Compares if a ValuePtr object is greater than another.
 
template<typename U , typename T , size_t TSmallSize>
bool CeresEngine::operator> (const U &lhs, const ValuePtr< T, TSmallSize > &rhs) noexcept
 Compares if a ValuePtr object is greater than another.
 
template<typename T , size_t TSmallSize, typename U , size_t USmallSize>
bool CeresEngine::operator>= (const ValuePtr< T, TSmallSize > &lhs, const ValuePtr< U, USmallSize > &rhs) noexcept
 Compares if a ValuePtr object is greater or equal than another.
 
template<typename T , size_t TSmallSize, typename U >
bool CeresEngine::operator>= (const ValuePtr< T, TSmallSize > &lhs, const U &rhs) noexcept
 Compares if a ValuePtr object is greater or equal than another.
 
template<typename U , typename T , size_t TSmallSize>
bool CeresEngine::operator>= (const U &lhs, const ValuePtr< T, TSmallSize > &rhs) noexcept
 Compares if a ValuePtr object is greater or equal than another.
 
template<typename T , size_t TSmallSize, typename U , size_t USmallSize>
bool CeresEngine::operator< (const ValuePtr< T, TSmallSize > &lhs, const ValuePtr< U, USmallSize > &rhs) noexcept
 Compares if a ValuePtr object is less than another.
 
template<typename T , size_t TSmallSize, typename U >
bool CeresEngine::operator< (const ValuePtr< T, TSmallSize > &lhs, const U &rhs) noexcept
 Compares if a ValuePtr object is less than another.
 
template<typename U , typename T , size_t TSmallSize>
bool CeresEngine::operator< (const U &lhs, const ValuePtr< T, TSmallSize > &rhs) noexcept
 Compares if a ValuePtr object is less than another.
 
template<typename T , size_t TSmallSize, typename U , size_t USmallSize>
bool CeresEngine::operator<= (const ValuePtr< T, TSmallSize > &lhs, const ValuePtr< U, USmallSize > &rhs) noexcept
 Compares if a ValuePtr object is less or equal than another.
 
template<typename T , size_t TSmallSize, typename U >
bool CeresEngine::operator<= (const ValuePtr< T, TSmallSize > &lhs, const U &rhs) noexcept
 Compares if a ValuePtr object is less or equal than another.
 
template<typename U , typename T , size_t TSmallSize>
bool CeresEngine::operator<= (const U &lhs, const ValuePtr< T, TSmallSize > &rhs) noexcept
 Compares if a ValuePtr object is less or equal than another.
 
template<typename T , size_t TSmallSize>
bool CeresEngine::operator== (const ValuePtr< T, TSmallSize > &lhs, std::nullptr_t) noexcept
 Checks if a ValuePtr is nullptr.
 
template<typename T , size_t TSmallSize>
bool CeresEngine::operator!= (const ValuePtr< T, TSmallSize > &lhs, std::nullptr_t) noexcept
 Checks if a ValuePtr is not nullptr.
 

Macro Definition Documentation

◆ CE_RCPTR_TRAIT_DECL

#define CE_RCPTR_TRAIT_DECL (   ClassName)
Value:
template<> struct CeresEngine::CountedPtrTrait<ClassName> { \
static void retain(ClassName* ptr) noexcept; \
static void release(ClassName* ptr) noexcept; \
};
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
A trait template class that can be specialized for custom types.
Definition SmartPtr.hpp:95

◆ CE_RCPTR_TRAIT_DEF

#define CE_RCPTR_TRAIT_DEF (   ClassName)
Value:
void ::CeresEngine::CountedPtrTrait<ClassName>::retain(ClassName* ptr) noexcept { ptr->retain(); } \
void ::CeresEngine::CountedPtrTrait<ClassName>::release(ClassName* ptr) noexcept { ptr->release(); }

◆ CE_VPTR_TMPL

#define CE_VPTR_TMPL (   T)    typename T, size_t T##SmallSize

◆ CE_VPTR_TYPE

#define CE_VPTR_TYPE (   T)    ValuePtr<T, T##SmallSize>