Plasma Engine  2.0
Loading...
Searching...
No Matches
UniquePtr.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Memory/Allocator.h>
5
8template <typename T>
10{
11 PL_DISALLOW_COPY_AND_ASSIGN(plUniquePtr);
12
13public:
14 PL_DECLARE_MEM_RELOCATABLE_TYPE();
15
18
20 template <typename U>
22
25 template <typename U>
26 plUniquePtr(U* pInstance, plAllocator* pAllocator);
27
30 template <typename U>
32
34 plUniquePtr(std::nullptr_t);
35
38
40 template <typename U>
42
45 template <typename U>
47
49 plUniquePtr<T>& operator=(std::nullptr_t);
50
52 T* Release();
53
56 T* Release(plAllocator*& out_pAllocator);
57
59 T* Borrow() const;
60
62 void Clear();
63
65 T& operator*() const;
66
68 T* operator->() const;
69
71 explicit operator bool() const;
72
74 bool operator==(const plUniquePtr<T>& rhs) const;
75 bool operator!=(const plUniquePtr<T>& rhs) const;
76 bool operator<(const plUniquePtr<T>& rhs) const;
77 bool operator<=(const plUniquePtr<T>& rhs) const;
78 bool operator>(const plUniquePtr<T>& rhs) const;
79 bool operator>=(const plUniquePtr<T>& rhs) const;
80
82 bool operator==(std::nullptr_t) const;
83 bool operator!=(std::nullptr_t) const;
84 bool operator<(std::nullptr_t) const;
85 bool operator<=(std::nullptr_t) const;
86 bool operator>(std::nullptr_t) const;
87 bool operator>=(std::nullptr_t) const;
88
89private:
90 template <typename U>
91 friend class plUniquePtr;
92
93 T* m_pInstance = nullptr;
94 plAllocator* m_pAllocator = nullptr;
95};
96
97#include <Foundation/Types/Implementation/UniquePtr_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
void Clear()
Destroys the managed object and resets the unique ptr.
Definition UniquePtr_inl.h:108
T & operator*() const
Provides access to the managed object.
Definition UniquePtr_inl.h:120
plUniquePtr(plUniquePtr< U > &&other)
Move constructs a unique ptr from another. The other unique ptr will be empty afterwards to guarantee...
T * Release()
Releases the managed object without destroying it. The unique ptr will be empty afterwards.
Definition UniquePtr_inl.h:79
plUniquePtr(const plInternal::NewInstance< U > &instance)
Creates a unique ptr from a freshly created instance through PL_NEW or PL_DEFAULT_NEW.
~plUniquePtr()
Destroys the managed object using the stored allocator.
Definition UniquePtr_inl.h:38
plUniquePtr(U *pInstance, plAllocator *pAllocator)
Creates a unique ptr from a pointer and an allocator. The passed allocator will be used to destroy th...
T * operator->() const
Provides access to the managed object.
Definition UniquePtr_inl.h:126
plUniquePtr()
Creates an empty unique ptr.
bool operator==(const plUniquePtr< T > &rhs) const
Compares the unique ptr against another unique ptr.
Definition UniquePtr_inl.h:138
T * Borrow() const
Borrows the managed object. The unique ptr stays unmodified.
Definition UniquePtr_inl.h:102
plUniquePtr< T > & operator=(const plInternal::NewInstance< U > &instance)
Sets the unique ptr from a freshly created instance through PL_NEW or PL_DEFAULT_NEW.
plUniquePtr< T > & operator=(plUniquePtr< U > &&other)
Move assigns a unique ptr from another. The other unique ptr will be empty afterwards to guarantee th...
Definition Allocator_inl.h:18