refactor(*): remove TObserverPtr and use raw pointer instead
This commit is contained in:
parent
9785326b18
commit
ec2a240c23
@ -6,7 +6,6 @@
|
||||
#include "Memory/UniquePointer.h"
|
||||
#include "Memory/SharedPointer.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Memory/InOutPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
@ -26,7 +25,6 @@ void TestMemory()
|
||||
TestPointerTraits();
|
||||
TestUniquePointer();
|
||||
TestSharedPointer();
|
||||
TestObserverPointer();
|
||||
TestInOutPointer();
|
||||
}
|
||||
|
||||
@ -1047,71 +1045,6 @@ void TestSharedPointer()
|
||||
|
||||
}
|
||||
|
||||
void TestObserverPointer()
|
||||
{
|
||||
{
|
||||
int32 IntA;
|
||||
int32 IntB;
|
||||
|
||||
TObserverPtr<int32> TempA;
|
||||
TObserverPtr<int32> TempB = nullptr;
|
||||
TObserverPtr<int32> TempC(&IntA);
|
||||
TObserverPtr<int32> TempD(TempC);
|
||||
|
||||
TempA = TempC;
|
||||
TempB = MakeObserver<int32>(&IntB);
|
||||
|
||||
always_check(TempA == TempC);
|
||||
always_check(TempB == &IntB);
|
||||
always_check(TempB.IsValid());
|
||||
|
||||
always_check(TempA.Release() == &IntA);
|
||||
always_check(!TempA.IsValid());
|
||||
|
||||
TempA.Reset(&IntA);
|
||||
|
||||
always_check(TempA == &IntA);
|
||||
|
||||
always_check(GetTypeHash(TempA) == GetTypeHash(&IntA));
|
||||
|
||||
Swap(TempA, TempB);
|
||||
|
||||
always_check(TempA == &IntB);
|
||||
always_check(TempB == &IntA);
|
||||
}
|
||||
|
||||
{
|
||||
int32 IntA[4];
|
||||
int32 IntB[4];
|
||||
|
||||
TObserverPtr<int32[]> TempA;
|
||||
TObserverPtr<int32[]> TempB = nullptr;
|
||||
TObserverPtr<int32[]> TempC(IntA);
|
||||
TObserverPtr<int32[]> TempD(TempC);
|
||||
|
||||
TempA = TempC;
|
||||
TempB = MakeObserver<int32[]>(IntB);
|
||||
|
||||
always_check(TempA == TempC);
|
||||
always_check(TempB == IntB);
|
||||
always_check(TempB.IsValid());
|
||||
|
||||
always_check(TempA.Release() == IntA);
|
||||
always_check(!TempA.IsValid());
|
||||
|
||||
TempA.Reset(IntA);
|
||||
|
||||
always_check(TempA == IntA);
|
||||
|
||||
always_check(GetTypeHash(TempA) == GetTypeHash(&IntA));
|
||||
|
||||
Swap(TempA, TempB);
|
||||
|
||||
always_check(TempA == IntB);
|
||||
always_check(TempB == IntA);
|
||||
}
|
||||
}
|
||||
|
||||
void TestInOutPointer()
|
||||
{
|
||||
{
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
#include "Miscellaneous/ConstantIterator.h"
|
||||
|
||||
@ -256,20 +255,20 @@ public:
|
||||
Impl.ArrayMax = NumToAllocate;
|
||||
Impl.Pointer = Impl->Allocate(Max());
|
||||
|
||||
Memory::CopyConstruct<ElementType>(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL).Get(), Num());
|
||||
Memory::CopyConstruct<ElementType>(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL), Num());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (GetNum(IL) <= Num())
|
||||
{
|
||||
Memory::CopyAssign(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL).Get(), GetNum(IL));
|
||||
Memory::CopyAssign(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL), GetNum(IL));
|
||||
Memory::Destruct(Impl.Pointer + GetNum(IL), Num() - GetNum(IL));
|
||||
}
|
||||
else if (GetNum(IL) <= Max())
|
||||
{
|
||||
Memory::CopyAssign(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL).Get(), Num());
|
||||
Memory::CopyConstruct<ElementType>(Impl.Pointer + Num(), NAMESPACE_REDCRAFT::GetData(IL).Get() + Num(), GetNum(IL) - Num());
|
||||
Memory::CopyAssign(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL), Num());
|
||||
Memory::CopyConstruct<ElementType>(Impl.Pointer + Num(), NAMESPACE_REDCRAFT::GetData(IL) + Num(), GetNum(IL) - Num());
|
||||
}
|
||||
else check_no_entry();
|
||||
|
||||
@ -869,8 +868,8 @@ public:
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE TObserverPtr< ElementType[]> GetData() { return TObserverPtr< ElementType[]>(Impl.Pointer); }
|
||||
NODISCARD FORCEINLINE TObserverPtr<const ElementType[]> GetData() const { return TObserverPtr<const ElementType[]>(Impl.Pointer); }
|
||||
NODISCARD FORCEINLINE ElementType* GetData() { return Impl.Pointer; }
|
||||
NODISCARD FORCEINLINE const ElementType* GetData() const { return Impl.Pointer; }
|
||||
|
||||
/** @return The iterator to the first or end element. */
|
||||
NODISCARD FORCEINLINE Iterator Begin() { return Iterator(this, Impl.Pointer); }
|
||||
@ -1003,8 +1002,8 @@ private:
|
||||
|
||||
NODISCARD friend FORCEINLINE strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer <=> RHS.Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE U& operator*() const { CheckThis(true); return *Pointer; }
|
||||
NODISCARD FORCEINLINE U* operator->() const { CheckThis(true); return Pointer; }
|
||||
NODISCARD FORCEINLINE U& operator*() const { CheckThis(true ); return *Pointer; }
|
||||
NODISCARD FORCEINLINE U* operator->() const { CheckThis(false); return Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE U& operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; }
|
||||
|
||||
@ -1024,8 +1023,6 @@ private:
|
||||
|
||||
NODISCARD friend FORCEINLINE ptrdiff operator-(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE explicit operator TObserverPtr<U[]>() const { CheckThis(); return TObserverPtr<U[]>(Pointer); }
|
||||
|
||||
private:
|
||||
|
||||
# if DO_CHECK
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "Containers/StaticArray.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -85,7 +84,6 @@ public:
|
||||
template <size_t N> requires (Extent == DynamicExtent || N == Extent)
|
||||
FORCEINLINE constexpr TArrayView(ElementType(&InArray)[N])
|
||||
{
|
||||
// @TODO: Refactor this to use the GetData() function.
|
||||
Impl.Pointer = InArray;
|
||||
|
||||
if constexpr (Extent == DynamicExtent)
|
||||
@ -96,19 +94,19 @@ public:
|
||||
|
||||
/** Constructs an array view that is a view over the array 'InArray'. */
|
||||
template <typename U, size_t N> requires (CConvertibleTo<U(*)[], ElementType(*)[]>)
|
||||
FORCEINLINE constexpr TArrayView(TStaticArray<U, N>& InArray) : TArrayView(InArray.GetData().Get(), InArray.Num()) { }
|
||||
FORCEINLINE constexpr TArrayView(TStaticArray<U, N>& InArray) : TArrayView(InArray.GetData(), InArray.Num()) { }
|
||||
|
||||
/** Constructs an array view that is a view over the array 'InArray'. */
|
||||
template <typename U, size_t N> requires (CConvertibleTo<const U(*)[], ElementType(*)[]>)
|
||||
FORCEINLINE constexpr TArrayView(const TStaticArray<U, N>& InArray) : TArrayView(InArray.GetData().Get(), InArray.Num()) { }
|
||||
FORCEINLINE constexpr TArrayView(const TStaticArray<U, N>& InArray) : TArrayView(InArray.GetData(), InArray.Num()) { }
|
||||
|
||||
/** Constructs an array view that is a view over the array 'InArray'. */
|
||||
template <typename U, typename Allocator> requires (CConvertibleTo<U(*)[], ElementType(*)[]>)
|
||||
FORCEINLINE constexpr TArrayView(TArray<U, Allocator>& InArray) : TArrayView(InArray.GetData().Get(), InArray.Num()) { }
|
||||
FORCEINLINE constexpr TArrayView(TArray<U, Allocator>& InArray) : TArrayView(InArray.GetData(), InArray.Num()) { }
|
||||
|
||||
/** Constructs an array view that is a view over the array 'InArray'. */
|
||||
template <typename U, typename Allocator> requires (CConvertibleTo<const U(*)[], ElementType(*)[]>)
|
||||
FORCEINLINE constexpr TArrayView(const TArray<U, Allocator>& InArray) : TArrayView(InArray.GetData().Get(), InArray.Num()) { }
|
||||
FORCEINLINE constexpr TArrayView(const TArray<U, Allocator>& InArray) : TArrayView(InArray.GetData(), InArray.Num()) { }
|
||||
|
||||
/** Converting constructor from another array view 'InValue'. */
|
||||
template <typename U, size_t N> requires ((Extent == DynamicExtent || N == DynamicExtent || N == Extent) && CConvertibleTo<U(*)[], ElementType(*)[]>)
|
||||
@ -116,8 +114,7 @@ public:
|
||||
{
|
||||
checkf(Extent == DynamicExtent || Extent == InValue.Num(), TEXT("Illegal view extent. Please check InValue.Num()."));
|
||||
|
||||
// @TODO: Refactor this to use the GetData() function.
|
||||
Impl.Pointer = InValue.GetData().Get();
|
||||
Impl.Pointer = InValue.GetData();
|
||||
|
||||
if constexpr (Extent == DynamicExtent)
|
||||
{
|
||||
@ -231,11 +228,11 @@ public:
|
||||
|
||||
if constexpr (!CConst<ElementType>)
|
||||
{
|
||||
return TArrayView<uint8, BytesExtent>(reinterpret_cast<uint8*>(GetData().Get()), NumBytes());
|
||||
return TArrayView<uint8, BytesExtent>(reinterpret_cast<uint8*>(GetData()), NumBytes());
|
||||
}
|
||||
else
|
||||
{
|
||||
return TArrayView<const uint8, BytesExtent>(reinterpret_cast<const uint8*>(GetData().Get()), NumBytes());
|
||||
return TArrayView<const uint8, BytesExtent>(reinterpret_cast<const uint8*>(GetData()), NumBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,11 +241,11 @@ public:
|
||||
{
|
||||
constexpr size_t BytesExtent = Extent != DynamicExtent ? sizeof(ElementType) * Extent : DynamicExtent;
|
||||
|
||||
return TArrayView<const uint8, BytesExtent>(reinterpret_cast<const uint8*>(GetData().Get()), NumBytes());
|
||||
return TArrayView<const uint8, BytesExtent>(reinterpret_cast<const uint8*>(GetData()), NumBytes());
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr<ElementType[]> GetData() const { return TObserverPtr<ElementType[]>(Impl.Pointer); }
|
||||
NODISCARD FORCEINLINE constexpr ElementType* GetData() const { return Impl.Pointer; }
|
||||
|
||||
/** @return The iterator to the first or end element. */
|
||||
NODISCARD FORCEINLINE constexpr Iterator Begin() const { return Iterator(this, Impl.Pointer); }
|
||||
@ -318,8 +315,8 @@ public:
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const Iterator& LHS, const Iterator& RHS) { return LHS.Pointer <=> RHS.Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T& operator*() const { CheckThis(true); return *Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr T* operator->() const { CheckThis(true); return Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr T& operator*() const { CheckThis(true ); return *Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr T* operator->() const { CheckThis(false); return Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T& operator[](ptrdiff Index) const { Iterator Temp = *this + Index; return *Temp; }
|
||||
|
||||
@ -339,8 +336,6 @@ public:
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const Iterator& LHS, const Iterator& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr<T[]>() const { CheckThis(); return TObserverPtr<T[]>(Pointer); }
|
||||
|
||||
private:
|
||||
|
||||
# if DO_CHECK
|
||||
|
@ -785,8 +785,8 @@ public:
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE TObserverPtr< BlockType[]> GetData() { return TObserverPtr< BlockType[]>(Impl.Pointer); }
|
||||
NODISCARD FORCEINLINE TObserverPtr<const BlockType[]> GetData() const { return TObserverPtr<const BlockType[]>(Impl.Pointer); }
|
||||
NODISCARD FORCEINLINE BlockType* GetData() { return Impl.Pointer; }
|
||||
NODISCARD FORCEINLINE const BlockType* GetData() const { return Impl.Pointer; }
|
||||
|
||||
/** @return The iterator to the first or end bit. */
|
||||
NODISCARD FORCEINLINE Iterator Begin() { return Iterator(this, Impl.Pointer, 0); }
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include "Templates/Noncopyable.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -403,7 +402,7 @@ public:
|
||||
|
||||
NODISCARD FORCEINLINE constexpr TIteratorReferenceType<IteratorType> operator*() const requires (CDereferenceable<const IteratorType>) { CheckThis(true); return *Current; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr TIteratorPointerType<IteratorType> operator->() const requires (CContiguousIterator<IteratorType>) { CheckThis(true); return ToAddress(Current); }
|
||||
NODISCARD FORCEINLINE constexpr TIteratorPointerType<IteratorType> operator->() const requires (CContiguousIterator<IteratorType>) { CheckThis(false); return ToAddress(Current); }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr TIteratorReferenceType<IteratorType> operator[](ptrdiff Index) const requires (CRandomAccessIterator<IteratorType>) { TCountedIterator Temp = *this + Index; return *Temp; }
|
||||
|
||||
@ -428,8 +427,6 @@ public:
|
||||
NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TCountedIterator& LHS, FDefaultSentinel) { LHS.CheckThis(); return -LHS.Num(); }
|
||||
NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(FDefaultSentinel, const TCountedIterator& RHS) { RHS.CheckThis(); return RHS.Num(); }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr<ElementType[]>() const requires (CContiguousIterator<IteratorType>) { CheckThis(); return TObserverPtr<ElementType[]>(Current); }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr const IteratorType& GetBase() const& { CheckThis(); return Current; }
|
||||
NODISCARD FORCEINLINE constexpr IteratorType GetBase() && { CheckThis(); return Current; }
|
||||
NODISCARD FORCEINLINE constexpr ptrdiff Num() const { CheckThis(); return Length; }
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
#include "Miscellaneous/ConstantIterator.h"
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "Containers/Iterator.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -67,8 +66,8 @@ public:
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr< ElementType[]> GetData() { return TObserverPtr< ElementType[]>(_); }
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr<const ElementType[]> GetData() const { return TObserverPtr<const ElementType[]>(_); }
|
||||
NODISCARD FORCEINLINE constexpr ElementType* GetData() { return _; }
|
||||
NODISCARD FORCEINLINE constexpr const ElementType* GetData() const { return _; }
|
||||
|
||||
/** @return The iterator to the first or end element. */
|
||||
NODISCARD FORCEINLINE constexpr Iterator Begin() { return Iterator(this, _); }
|
||||
@ -151,8 +150,8 @@ private:
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer <=> RHS.Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr U& operator*() const { CheckThis(true); return *Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr U* operator->() const { CheckThis(true); return Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr U& operator*() const { CheckThis(true ); return *Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr U* operator->() const { CheckThis(false); return Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr U& operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; }
|
||||
|
||||
@ -172,8 +171,6 @@ private:
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr<U[]>() const { CheckThis(); return TObserverPtr<U[]>(Pointer); }
|
||||
|
||||
private:
|
||||
|
||||
# if DO_CHECK
|
||||
|
@ -435,8 +435,8 @@ public:
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr< BlockType[]> GetData() { return TObserverPtr< BlockType[]>(Impl); }
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr<const BlockType[]> GetData() const { return TObserverPtr<const BlockType[]>(Impl); }
|
||||
NODISCARD FORCEINLINE constexpr BlockType* GetData() { return Impl; }
|
||||
NODISCARD FORCEINLINE constexpr const BlockType* GetData() const { return Impl; }
|
||||
|
||||
/** @return The iterator to the first or end bit. */
|
||||
NODISCARD FORCEINLINE constexpr Iterator Begin() { return Iterator(this, Impl, 0); }
|
||||
|
@ -1,155 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "Memory/PointerTraits.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
template <typename T> requires (CObject<T> && !CBoundedArray<T>)
|
||||
class TObserverPtr;
|
||||
|
||||
NAMESPACE_PRIVATE_BEGIN
|
||||
|
||||
template <typename T> struct TIsTObserverPtr : FFalse { };
|
||||
template <typename T> struct TIsTObserverPtr<TObserverPtr<T>> : FTrue { };
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
template <typename T>
|
||||
concept CTObserverPtr = NAMESPACE_PRIVATE::TIsTObserverPtr<TRemoveCV<T>>::Value;
|
||||
|
||||
template <typename T> requires (CObject<T> && !CBoundedArray<T>)
|
||||
class TObserverPtr
|
||||
{
|
||||
public:
|
||||
|
||||
using ElementType = T;
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr() : Pointer(nullptr) { }
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr(nullptr_t) : TObserverPtr() { }
|
||||
|
||||
FORCEINLINE constexpr explicit TObserverPtr(T* InPtr) : Pointer(InPtr) { }
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr(const TObserverPtr&) = default;
|
||||
FORCEINLINE constexpr TObserverPtr(TObserverPtr&&) = default;
|
||||
|
||||
template <typename U> requires (CConvertibleTo<U*, T*> && !CArray<U>)
|
||||
FORCEINLINE constexpr TObserverPtr(TObserverPtr<U> InValue) : Pointer(InValue.Pointer) { }
|
||||
|
||||
FORCEINLINE constexpr ~TObserverPtr() = default;
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr& operator=(const TObserverPtr&) = default;
|
||||
FORCEINLINE constexpr TObserverPtr& operator=(TObserverPtr&&) = default;
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr bool operator==(const TObserverPtr& LHS, const TObserverPtr& RHS) { return LHS.Get() == RHS.Get(); }
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const TObserverPtr& LHS, const TObserverPtr& RHS) { return LHS.Get() <=> RHS.Get(); }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr bool operator==(T* InPtr) const& { return Get() == InPtr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr strong_ordering operator<=>(T* InPtr) const& { return Get() <=> InPtr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T* Release() { return Exchange(Pointer, nullptr); }
|
||||
|
||||
FORCEINLINE constexpr void Reset(T* InPtr = nullptr) { Pointer = InPtr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T* Get() const { return Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr bool IsValid() const { return Get() != nullptr; }
|
||||
NODISCARD FORCEINLINE constexpr explicit operator bool() const { return Get() != nullptr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T& operator*() const { checkf(IsValid(), TEXT("Read access violation. Please check IsValid().")); return *Get(); }
|
||||
NODISCARD FORCEINLINE constexpr T* operator->() const { checkf(IsValid(), TEXT("Read access violation. Please check IsValid().")); return Get(); }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr explicit operator ElementType*() const { return Get(); }
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr size_t GetTypeHash(const TObserverPtr& A) { return GetTypeHash(A.Get()); }
|
||||
|
||||
friend FORCEINLINE constexpr void Swap(TObserverPtr& A, TObserverPtr& B) { Swap(A.Pointer, B.Pointer); }
|
||||
|
||||
private:
|
||||
|
||||
T* Pointer;
|
||||
|
||||
template <typename U> requires (CObject<U> && !CBoundedArray<U>)
|
||||
friend class TObserverPtr;
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class TObserverPtr<T[]>
|
||||
{
|
||||
public:
|
||||
|
||||
using ElementType = T;
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr() : Pointer(nullptr) { }
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr(nullptr_t) : TObserverPtr() { }
|
||||
|
||||
template <typename U = T*> requires (CPointer<U> && CConvertibleTo<TRemovePointer<U>(*)[], T(*)[]>)
|
||||
FORCEINLINE constexpr explicit TObserverPtr(U InPtr) : Pointer(InPtr) { }
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr(const TObserverPtr&) = default;
|
||||
FORCEINLINE constexpr TObserverPtr(TObserverPtr&&) = default;
|
||||
|
||||
template <typename U> requires (CConvertibleTo<TRemoveExtent<U>(*)[], T(*)[]> && CArray<U>)
|
||||
FORCEINLINE constexpr TObserverPtr(TObserverPtr<U> InValue) : Pointer(InValue.Pointer) { }
|
||||
|
||||
FORCEINLINE constexpr ~TObserverPtr() = default;
|
||||
|
||||
FORCEINLINE constexpr TObserverPtr& operator=(const TObserverPtr&) = default;
|
||||
FORCEINLINE constexpr TObserverPtr& operator=(TObserverPtr&&) = default;
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr bool operator==(const TObserverPtr& LHS, const TObserverPtr& RHS) { return LHS.Get() == RHS.Get(); }
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const TObserverPtr& LHS, const TObserverPtr& RHS) { return LHS.Get() <=> RHS.Get(); }
|
||||
|
||||
template <typename U = T*> requires (CNullPointer<U> || (CPointer<U> && CConvertibleTo<TRemovePointer<U>(*)[], T(*)[]>))
|
||||
NODISCARD FORCEINLINE constexpr bool operator==(U InPtr) const& { return Get() == InPtr; }
|
||||
|
||||
template <typename U = T*> requires (CNullPointer<U> || (CPointer<U> && CConvertibleTo<TRemovePointer<U>(*)[], T(*)[]>))
|
||||
NODISCARD FORCEINLINE constexpr strong_ordering operator<=>(U InPtr) const& { return Get() <=> InPtr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T* Release() { return Exchange(Pointer, nullptr); }
|
||||
|
||||
template <typename U = T*> requires (CNullPointer<U> || (CPointer<U> && CConvertibleTo<TRemovePointer<U>(*)[], T(*)[]>))
|
||||
FORCEINLINE constexpr void Reset(U InPtr = nullptr) { Pointer = InPtr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T* Get() const { return Pointer; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr bool IsValid() const { return Get() != nullptr; }
|
||||
NODISCARD FORCEINLINE constexpr explicit operator bool() const { return Get() != nullptr; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr T& operator[](size_t Index) const { checkf(IsValid(), TEXT("Read access violation. Please check IsValid().")); return Get()[Index]; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr explicit operator ElementType*() const { return Get(); }
|
||||
|
||||
NODISCARD friend FORCEINLINE constexpr size_t GetTypeHash(const TObserverPtr& A) { return GetTypeHash(A.Get()); }
|
||||
|
||||
friend FORCEINLINE constexpr void Swap(TObserverPtr& A, TObserverPtr& B) { Swap(A.Pointer, B.Pointer); }
|
||||
|
||||
private:
|
||||
|
||||
T* Pointer;
|
||||
|
||||
template <typename U> requires (CObject<U> && !CBoundedArray<U>)
|
||||
friend class TObserverPtr;
|
||||
|
||||
};
|
||||
|
||||
template <typename T> requires (CObject<T> && !CBoundedArray<T>)
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr<T> MakeObserver(TRemoveExtent<T>* InPtr) { return TObserverPtr<T>(InPtr); }
|
||||
|
||||
DEFINE_TPointerTraits(TObserverPtr);
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
@ -157,8 +157,8 @@ public:
|
||||
|
||||
NODISCARD FORCEINLINE constexpr strong_ordering operator<=>(FDefaultSentinel) const& { return static_cast<ptrdiff>(0) <=> Length; }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr const TRemoveReference<T>& operator*() const { CheckThis(true); return *Current; }
|
||||
NODISCARD FORCEINLINE constexpr const TRemoveReference<T>* operator->() const { CheckThis(true); return ToAddress(Current); }
|
||||
NODISCARD FORCEINLINE constexpr const TRemoveReference<T>& operator*() const { CheckThis(true ); return *Current; }
|
||||
NODISCARD FORCEINLINE constexpr const TRemoveReference<T>* operator->() const { CheckThis(false); return ToAddress(Current); }
|
||||
|
||||
NODISCARD FORCEINLINE constexpr const TRemoveReference<T>& operator[](ptrdiff) const { return *this; }
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -129,9 +128,9 @@ public:
|
||||
NODISCARD friend FORCEINLINE auto operator<=>(const TString& LHS, const TString& RHS) { return TStringView<ElementType>(LHS) <=> TStringView<ElementType>(RHS); }
|
||||
|
||||
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
||||
NODISCARD friend FORCEINLINE auto operator<=>(const TString& LHS, ElementType RHS) { return TStringView<ElementType>(LHS) <=> RHS; }
|
||||
NODISCARD friend FORCEINLINE auto operator<=>(const TString& LHS, ElementType RHS) { return TStringView<ElementType>(LHS) <=> RHS; }
|
||||
NODISCARD friend FORCEINLINE auto operator<=>(const TString& LHS, const ElementType* RHS) { return TStringView<ElementType>(LHS) <=> RHS; }
|
||||
NODISCARD friend FORCEINLINE auto operator<=>(ElementType LHS, const TString& RHS) { return LHS <=> TStringView<ElementType>(RHS); }
|
||||
NODISCARD friend FORCEINLINE auto operator<=>( ElementType LHS, const TString& RHS) { return LHS <=> TStringView<ElementType>(RHS); }
|
||||
NODISCARD friend FORCEINLINE auto operator<=>(const ElementType* LHS, const TString& RHS) { return LHS <=> TStringView<ElementType>(RHS); }
|
||||
|
||||
/** Inserts 'InValue' before 'Index' in the string. */
|
||||
@ -663,8 +662,8 @@ public:
|
||||
|
||||
NAMESPACE_STD::mbstate_t State = NAMESPACE_STD::mbstate_t();
|
||||
|
||||
const char* BeginFrom = View.GetData().Get();
|
||||
const char* EndFrom = BeginFrom + View.Num();
|
||||
const char* BeginFrom = ToAddress(View.Begin());
|
||||
const char* EndFrom = ToAddress(View.End());
|
||||
|
||||
wchar Buffer[FWChar::MaxCodeUnitLength];
|
||||
|
||||
@ -711,8 +710,8 @@ public:
|
||||
|
||||
NAMESPACE_STD::mbstate_t State = NAMESPACE_STD::mbstate_t();
|
||||
|
||||
const wchar* BeginFrom = View.GetData().Get();
|
||||
const wchar* EndFrom = BeginFrom + View.Num();
|
||||
const wchar* BeginFrom = ToAddress(View.Begin());
|
||||
const wchar* EndFrom = ToAddress(View.End());
|
||||
|
||||
char Buffer[FChar::MaxCodeUnitLength];
|
||||
|
||||
@ -836,7 +835,7 @@ public:
|
||||
// wchar -> unicodechar -> ... for Linux
|
||||
else if constexpr (PLATFORM_LINUX && CSameAs<W, wchar>)
|
||||
{
|
||||
return Self(Self, TStringView(reinterpret_cast<const u32char*>(View.GetData().Get()), View.Num()));
|
||||
return Self(Self, TStringView(reinterpret_cast<const u32char*>(View.GetData()), View.Num()));
|
||||
}
|
||||
|
||||
// unicodechar u32char -> u8char
|
||||
@ -930,7 +929,7 @@ public:
|
||||
|
||||
if constexpr (PLATFORM_LINUX && (CSameAs<T, char> || CSameAs<T, wchar>))
|
||||
{
|
||||
return Self(Self, TStringView(reinterpret_cast<const wchar*>(View.GetData().Get()), View.Num()));
|
||||
return Self(Self, TStringView(reinterpret_cast<const wchar*>(View.GetData()), View.Num()));
|
||||
}
|
||||
else NativeData.Insert(NativeData.End(), View.Begin(), View.End());
|
||||
|
||||
@ -967,7 +966,7 @@ public:
|
||||
}
|
||||
|
||||
/** @return The non-modifiable standard C character string version of the string. */
|
||||
NODISCARD FORCEINLINE const ElementType* ToCString() const { return NativeData.GetData().Get(); }
|
||||
NODISCARD FORCEINLINE const ElementType* ToCString() const { return GetData(); }
|
||||
|
||||
/** @return The target-encoded string from the T-encoded string. */
|
||||
NODISCARD FORCEINLINE auto ToString() const { return EncodeTo<char>(); }
|
||||
@ -990,8 +989,8 @@ public:
|
||||
FORCEINLINE void Shrink() { NativeData.Shrink(); }
|
||||
|
||||
/** @return The pointer to the underlying character storage. */
|
||||
NODISCARD FORCEINLINE TObserverPtr< ElementType[]> GetData() { return NativeData.GetData(); }
|
||||
NODISCARD FORCEINLINE TObserverPtr<const ElementType[]> GetData() const { return NativeData.GetData(); }
|
||||
NODISCARD FORCEINLINE ElementType* GetData() { return NativeData.GetData(); }
|
||||
NODISCARD FORCEINLINE const ElementType* GetData() const { return NativeData.GetData(); }
|
||||
|
||||
/** @return The iterator to the first or end character. */
|
||||
NODISCARD FORCEINLINE Iterator Begin() { return NativeData.Begin(); }
|
||||
@ -1068,7 +1067,7 @@ using FU32String = TString<u32char>;
|
||||
using FUnicodeString = TString<unicodechar>;
|
||||
|
||||
template <CCharType T> template <typename Allocator> constexpr TStringView<T>::TStringView(const TString<ElementType, Allocator>& InString)
|
||||
: TStringView(InString.GetData().Get(), InString.Num()) { }
|
||||
: TStringView(InString.GetData(), InString.Num()) { }
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
#include "Miscellaneous/ConstantIterator.h"
|
||||
|
||||
@ -155,7 +154,7 @@ public:
|
||||
Count = Num() - Offset;
|
||||
}
|
||||
|
||||
Memory::CopyAssign(Dest, GetData().Get() + Offset, Count);
|
||||
Memory::CopyAssign(Dest, GetData() + Offset, Count);
|
||||
|
||||
return Count;
|
||||
}
|
||||
@ -405,7 +404,7 @@ public:
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE constexpr TObserverPtr<const ElementType[]> GetData() const { return NativeData.GetData(); }
|
||||
NODISCARD FORCEINLINE constexpr const ElementType* GetData() const { return NativeData.GetData(); }
|
||||
|
||||
/** @return The iterator to the first or end element. */
|
||||
NODISCARD FORCEINLINE constexpr Iterator Begin() const { return NativeData.Begin(); }
|
||||
|
@ -3,44 +3,43 @@
|
||||
#include "CoreTypes.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "TypeTraits/Swappable.h"
|
||||
#include "Memory/ObserverPointer.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
/** @return The pointer to the container element storage. */
|
||||
template <typename T> requires (requires(T&& Container) { { Container.GetData() } -> CTObserverPtr; })
|
||||
FORCEINLINE constexpr decltype(auto) GetData(T&& Container)
|
||||
template <typename T> requires (requires(T&& Container) { { Container.GetData() } -> CPointer; })
|
||||
FORCEINLINE constexpr auto GetData(T&& Container)
|
||||
{
|
||||
return Container.GetData();
|
||||
}
|
||||
|
||||
/** Overloads the GetData algorithm for arrays. */
|
||||
template <typename T, size_t N> FORCEINLINE constexpr TObserverPtr< T[]> GetData( T(& Container)[N]) { return TObserverPtr< T[]>(Container); }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr TObserverPtr< T[]> GetData( T(&& Container)[N]) { return TObserverPtr< T[]>(Container); }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr TObserverPtr<const T[]> GetData(const T(& Container)[N]) { return TObserverPtr<const T[]>(Container); }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr TObserverPtr<const T[]> GetData(const T(&& Container)[N]) { return TObserverPtr<const T[]>(Container); }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr T* GetData( T(& Container)[N]) { return Container; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr T* GetData( T(&& Container)[N]) { return Container; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr const T* GetData(const T(& Container)[N]) { return Container; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr const T* GetData(const T(&& Container)[N]) { return Container; }
|
||||
|
||||
/** Overloads the GetData algorithm for initializer_list. */
|
||||
template <typename T>
|
||||
FORCEINLINE constexpr TObserverPtr<const T[]> GetData(initializer_list<T> Container)
|
||||
FORCEINLINE constexpr const T* GetData(initializer_list<T> Container)
|
||||
{
|
||||
return TObserverPtr<const T[]>(Container.begin());
|
||||
return Container.begin();
|
||||
}
|
||||
|
||||
/** @return The number of elements in the container. */
|
||||
template <typename T> requires (requires(T&& Container) { { Container.Num() } -> CConvertibleTo<size_t>; })
|
||||
FORCEINLINE constexpr decltype(auto) GetNum(T&& Container)
|
||||
FORCEINLINE constexpr auto GetNum(T&& Container)
|
||||
{
|
||||
return Container.Num();
|
||||
}
|
||||
|
||||
/** Overloads the GetNum algorithm for arrays. */
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum( T(& Container)[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum( T(&& Container)[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum(const T(& Container)[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum(const T(&& Container)[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum( T(& )[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum( T(&&)[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum(const T(& )[N]) { return N; }
|
||||
template <typename T, size_t N> FORCEINLINE constexpr size_t GetNum(const T(&&)[N]) { return N; }
|
||||
|
||||
/** Overloads the GetNum algorithm for initializer_list. */
|
||||
template <typename T>
|
||||
@ -69,7 +68,7 @@ FORCEINLINE constexpr size_t GetTypeHash(T(&A)[N])
|
||||
{
|
||||
Result = HashCombine(Result, GetTypeHash(A[Index]));
|
||||
}
|
||||
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user