Ark Server API (ASE) - Wiki
|
#include "../BasicTypes.h"
#include "PointerIsConvertibleFromTo.h"
#include "../HAL/UnrealMemory.h"
#include "../Containers/TArray.h"
#include "../Containers/Map.h"
#include "SharedPointerInternals.h"
Go to the source code of this file.
Namespaces | |
namespace | UE4SharedPointer_Private |
Functions | |
template<class CastToType , class CastFromType , int Mode> | |
FORCEINLINE TSharedRef< CastToType, Mode > | StaticCastSharedRef (TSharedRef< CastFromType, Mode > const &InSharedRef) |
template<typename ObjectType , int Mode> | |
FORCEINLINE TSharedRef< ObjectType, Mode > | UE4SharedPointer_Private::MakeSharedRef (ObjectType *InObject, SharedPointerInternals::FReferenceControllerBase *InSharedReferenceCount) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TSharedRef< ObjectTypeA, Mode > const &InSharedRefA, TSharedRef< ObjectTypeB, Mode > const &InSharedRefB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TSharedRef< ObjectTypeA, Mode > const &InSharedRefA, TSharedRef< ObjectTypeB, Mode > const &InSharedRefB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TSharedPtr< ObjectTypeA, Mode > const &InSharedPtrA, TSharedPtr< ObjectTypeB, Mode > const &InSharedPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TSharedPtr< ObjectTypeA, Mode > const &InSharedPtrA, TSharedPtr< ObjectTypeB, Mode > const &InSharedPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TSharedRef< ObjectTypeA, Mode > const &InSharedRef, TSharedPtr< ObjectTypeB, Mode > const &InSharedPtr) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TSharedRef< ObjectTypeA, Mode > const &InSharedRef, TSharedPtr< ObjectTypeB, Mode > const &InSharedPtr) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TSharedPtr< ObjectTypeB, Mode > const &InSharedPtr, TSharedRef< ObjectTypeA, Mode > const &InSharedRef) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TSharedPtr< ObjectTypeB, Mode > const &InSharedPtr, TSharedRef< ObjectTypeA, Mode > const &InSharedRef) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, TSharedRef< ObjectTypeB, Mode > const &InSharedRefB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, TSharedPtr< ObjectTypeB, Mode > const &InSharedPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TSharedRef< ObjectTypeA, Mode > const &InSharedRefA, TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (TSharedPtr< ObjectTypeA, Mode > const &InSharedPtrA, TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , int Mode> | |
FORCEINLINE bool | operator== (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, decltype(nullptr)) |
template<class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator== (decltype(nullptr), TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, TSharedRef< ObjectTypeB, Mode > const &InSharedRefB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, TSharedPtr< ObjectTypeB, Mode > const &InSharedPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TSharedRef< ObjectTypeA, Mode > const &InSharedRefA, TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (TSharedPtr< ObjectTypeA, Mode > const &InSharedPtrA, TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class ObjectTypeA , int Mode> | |
FORCEINLINE bool | operator!= (TWeakPtr< ObjectTypeA, Mode > const &InWeakPtrA, decltype(nullptr)) |
template<class ObjectTypeB , int Mode> | |
FORCEINLINE bool | operator!= (decltype(nullptr), TWeakPtr< ObjectTypeB, Mode > const &InWeakPtrB) |
template<class CastToType , class CastFromType , int Mode> | |
FORCEINLINE TSharedPtr< CastToType, Mode > | StaticCastSharedPtr (TSharedPtr< CastFromType, Mode > const &InSharedPtr) |
template<class CastToType , class CastFromType , int Mode> | |
FORCEINLINE TSharedRef< CastToType, Mode > | ConstCastSharedRef (TSharedRef< CastFromType, Mode > const &InSharedRef) |
template<class CastToType , class CastFromType , int Mode> | |
FORCEINLINE TSharedPtr< CastToType, Mode > | ConstCastSharedPtr (TSharedPtr< CastFromType, Mode > const &InSharedPtr) |
template<class ObjectType > | |
FORCEINLINE SharedPointerInternals::FRawPtrProxy< ObjectType > | MakeShareable (ObjectType *InObject) |
template<class ObjectType , class DeleterType > | |
FORCEINLINE SharedPointerInternals::FRawPtrProxy< ObjectType > | MakeShareable (ObjectType *InObject, DeleterType &&InDeleter) |
template<typename InObjectType , int InMode = ESPMode::Fast, typename... InArgTypes> | |
FORCEINLINE TSharedRef< InObjectType, InMode > | MakeShared (InArgTypes &&... Args) |
template<class Type > | |
FORCEINLINE void | CleanupPointerArray (TArray< TWeakPtr< Type > > &PointerArray) |
template<class KeyType , class ValueType > | |
FORCEINLINE void | CleanupPointerMap (TMap< TWeakPtr< KeyType >, ValueType > &PointerMap) |
FORCEINLINE void CleanupPointerArray | ( | TArray< TWeakPtr< Type > > & | PointerArray | ) |
Given a TArray of TWeakPtr's, will remove any invalid pointers.
PointerArray | The pointer array to prune invalid pointers out of |
Definition at line 1634 of file SharedPointer.h.
FORCEINLINE void CleanupPointerMap | ( | TMap< TWeakPtr< KeyType >, ValueType > & | PointerMap | ) |
Given a TMap of TWeakPtr's, will remove any invalid pointers. Not the most efficient.
PointerMap | The pointer map to prune invalid pointers out of |
Definition at line 1652 of file SharedPointer.h.
FORCEINLINE TSharedPtr< CastToType, Mode > ConstCastSharedPtr | ( | TSharedPtr< CastFromType, Mode > const & | InSharedPtr | ) |
Casts a 'const' shared pointer to 'mutable' shared pointer. (const_cast)
InSharedPtr | The shared pointer to cast |
Definition at line 1589 of file SharedPointer.h.
FORCEINLINE TSharedRef< CastToType, Mode > ConstCastSharedRef | ( | TSharedRef< CastFromType, Mode > const & | InSharedRef | ) |
Casts a 'const' shared reference to 'mutable' shared reference. (const_cast)
InSharedRef | The shared reference to cast |
Definition at line 1578 of file SharedPointer.h.
FORCEINLINE SharedPointerInternals::FRawPtrProxy< ObjectType > MakeShareable | ( | ObjectType * | InObject | ) |
MakeShareable utility function. Wrap object pointers with MakeShareable to allow them to be implicitly converted to shared pointers! This is useful in assignment operations, or when returning a shared pointer from a function.
Definition at line 1601 of file SharedPointer.h.
FORCEINLINE SharedPointerInternals::FRawPtrProxy< ObjectType > MakeShareable | ( | ObjectType * | InObject, |
DeleterType && | InDeleter ) |
MakeShareable utility function. Wrap object pointers with MakeShareable to allow them to be implicitly converted to shared pointers! This is useful in assignment operations, or when returning a shared pointer from a function.
Definition at line 1613 of file SharedPointer.h.
FORCEINLINE TSharedRef< InObjectType, InMode > MakeShared | ( | InArgTypes &&... | Args | ) |
MakeShared utility function. Allocates a new ObjectType and reference controller in a single memory block. Equivalent to std::make_shared.
Definition at line 1623 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | decltype(nullptr) | , |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global inequality operator for TWeakPtr
Definition at line 1556 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TSharedPtr< ObjectTypeA, Mode > const & | InSharedPtrA, |
TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtrB ) |
Global inequality operator for TSharedPtr
Definition at line 1358 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TSharedPtr< ObjectTypeA, Mode > const & | InSharedPtrA, |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1534 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtr, |
TSharedRef< ObjectTypeA, Mode > const & | InSharedRef ) |
Tests to see if a TSharedRef is not "equal" to a TSharedPtr (shared pointer is invalid, or both refer to different objects) (reverse)
Definition at line 1402 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TSharedRef< ObjectTypeA, Mode > const & | InSharedRef, |
TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtr ) |
Tests to see if a TSharedRef is not "equal" to a TSharedPtr (shared pointer is invalid, or both refer to different objects)
Definition at line 1380 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TSharedRef< ObjectTypeA, Mode > const & | InSharedRefA, |
TSharedRef< ObjectTypeB, Mode > const & | InSharedRefB ) |
Global inequality operator for TSharedRef
Definition at line 1336 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TSharedRef< ObjectTypeA, Mode > const & | InSharedRefA, |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1523 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
decltype(nullptr) | ) |
Global inequality operator for TWeakPtr
Definition at line 1545 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1512 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
TSharedRef< ObjectTypeB, Mode > const & | InSharedRefB ) |
Global equality operator for TWeakPtr
Definition at line 1501 of file SharedPointer.h.
FORCEINLINE bool operator!= | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global inequality operator for TWeakPtr
Definition at line 1490 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | decltype(nullptr) | , |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1479 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TSharedPtr< ObjectTypeA, Mode > const & | InSharedPtrA, |
TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtrB ) |
Global equality operator for TSharedPtr
Definition at line 1347 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TSharedPtr< ObjectTypeA, Mode > const & | InSharedPtrA, |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1457 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtr, |
TSharedRef< ObjectTypeA, Mode > const & | InSharedRef ) |
Tests to see if a TSharedRef is "equal" to a TSharedPtr (both are valid and refer to the same object) (reverse)
Definition at line 1391 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TSharedRef< ObjectTypeA, Mode > const & | InSharedRef, |
TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtr ) |
Tests to see if a TSharedRef is "equal" to a TSharedPtr (both are valid and refer to the same object)
Definition at line 1369 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TSharedRef< ObjectTypeA, Mode > const & | InSharedRefA, |
TSharedRef< ObjectTypeB, Mode > const & | InSharedRefB ) |
Global equality operator for TSharedRef
Definition at line 1325 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TSharedRef< ObjectTypeA, Mode > const & | InSharedRefA, |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1446 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
decltype(nullptr) | ) |
Global equality operator for TWeakPtr
Definition at line 1468 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
TSharedPtr< ObjectTypeB, Mode > const & | InSharedPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1435 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
TSharedRef< ObjectTypeB, Mode > const & | InSharedRefB ) |
Global equality operator for TWeakPtr
Definition at line 1424 of file SharedPointer.h.
FORCEINLINE bool operator== | ( | TWeakPtr< ObjectTypeA, Mode > const & | InWeakPtrA, |
TWeakPtr< ObjectTypeB, Mode > const & | InWeakPtrB ) |
Global equality operator for TWeakPtr
Definition at line 1413 of file SharedPointer.h.
FORCEINLINE TSharedPtr< CastToType, Mode > StaticCastSharedPtr | ( | TSharedPtr< CastFromType, Mode > const & | InSharedPtr | ) |
Casts a shared pointer of one type to another type. (static_cast) Useful for down-casting.
InSharedPtr | The shared pointer to cast |
Definition at line 1567 of file SharedPointer.h.
FORCEINLINE TSharedRef< CastToType, Mode > StaticCastSharedRef | ( | TSharedRef< CastFromType, Mode > const & | InSharedRef | ) |
SharedPointer - Unreal smart pointer library
This is a smart pointer library consisting of shared references (TSharedRef), shared pointers (TSharedPtr), weak pointers (TWeakPtr) as well as related helper functions and classes. This implementation is modeled after the C++0x standard library's shared_ptr as well as Boost smart pointers.
Benefits of using shared references and pointers:
Clean syntax. You can copy, dereference and compare shared pointers just like regular C++ pointers. Prevents memory leaks. Resources are destroyed automatically when there are no more shared references. Weak referencing. Weak pointers allow you to safely check when an object has been destroyed. Thread safety. Includes "thread safe" version that can be safely accessed from multiple threads. Ubiquitous. You can create shared pointers to virtually *any* type of object. Runtime safety. Shared references are never null and can always be dereferenced. No reference cycles. Use weak pointers to break reference cycles. Confers intent. You can easily tell an object *owner* from an *observer*. Performance. Shared pointers have minimal overhead. All operations are constant-time. Robust features. Supports 'const', forward declarations to incomplete types, type-casting, etc. Memory. Only twice the size of a C++ pointer in 64-bit (plus a shared 16-byte reference controller.)
This library contains the following smart pointers:
TSharedRef - Non-nullable, reference counted non-intrusive authoritative smart pointer TSharedPtr - Reference counted non-intrusive authoritative smart pointer TWeakPtr - Reference counted non-intrusive weak pointer reference
Additionally, the following helper classes and functions are defined:
MakeShareable() - Used to initialize shared pointers from C++ pointers (enables implicit conversion) TSharedFromThis - You can derive your own class from this to acquire a TSharedRef from "this" StaticCastSharedRef() - Static cast utility function, typically used to downcast to a derived type. ConstCastSharedRef() - Converts a 'const' reference to 'mutable' smart reference StaticCastSharedPtr() - Dynamic cast utility function, typically used to downcast to a derived type. ConstCastSharedPtr() - Converts a 'const' smart pointer to 'mutable' smart pointer
Examples:
Tips:
Limitations:
- Shared pointers are not compatible with Unreal objects (UObject classes)! - Currently only types with that have regular destructors (no custom deleters) - Dynamically-allocated arrays are not supported yet (e.g. MakeSharable( new int32[20] )) - Implicit conversion of TSharedPtr/TSharedRef to bool is not supported yet
Differences from other implementations (e.g. boost:shared_ptr, std::shared_ptr):
- Type names and method names are more consistent with Unreal's codebase - You must use Pin() to convert weak pointers to shared pointers (no explicit constructor) - Thread-safety features are optional instead of forced - TSharedFromThis returns a shared *reference*, not a shared *pointer* - Some features were omitted (e.g. use_count(), unique(), etc.) - No exceptions are allowed (all related features have been omitted) - Custom allocators and custom delete functions are not supported yet - Our implementation supports non-nullable smart pointers (TSharedRef) - Several other new features added, such as MakeShareable and nullptr assignment
Why did we write our own Unreal shared pointer instead of using available alternatives?
- std::shared_ptr (and even tr1::shared_ptr) is not yet available on all platforms - Allows for a more consistent implementation on all compilers and platforms - Can work seamlessly with other Unreal containers and types - Better control over platform specifics, including threading and optimizations - We want thread-safety features to be optional (for performance) - We've added our own improvements (MakeShareable, assign to nullptr, etc.) - Exceptions were not needed nor desired in our implementation - We wanted more control over performance (inlining, memory, use of virtuals, etc.) - Potentially easier to debug (liberal code comments, etc.) - Prefer not to introduce new third party dependencies when not needed
Casts a shared reference of one type to another type. (static_cast) Useful for down-casting.
InSharedRef | The shared reference to cast |
Definition at line 118 of file SharedPointer.h.