feat(memory): add template function overload for Memmove and Memcmp

This commit is contained in:
_Redstone_c_ 2022-12-15 23:37:41 +08:00
parent 015b6df809
commit 6b42dbdc05
2 changed files with 24 additions and 1 deletions

View File

@ -71,6 +71,10 @@ void TestMemoryBuffer()
Memory::Memmove(PtrA, PtrA + 2, 6);
always_check((TempA << 16) == TempB);
TempA = 0x0123456789ABCDEF;
Memory::Memmove(TempB, TempA);
always_check(TempB == TempA);
TempA = 1004;
TempB = 1005;
TempC = 1005;
@ -78,8 +82,13 @@ void TestMemoryBuffer()
int32 ResultA = Memory::Memcmp(PtrA, PtrB, sizeof(int64));
int32 ResultB = Memory::Memcmp(PtrB, PtrC, sizeof(int64));
int32 ResultC = Memory::Memcmp(PtrC, PtrD, sizeof(int64));
always_check((ResultA < 0) != (ResultB < 0));
always_check((ResultA < 0) == (ResultC < 0));
always_check(ResultB == 0);
int32 ResultD = Memory::Memcmp(TempA, TempB);
int32 ResultE = Memory::Memcmp(TempB, TempC);
int32 ResultF = Memory::Memcmp(TempC, TempD);
always_check((ResultD < 0) == (ResultF < 0));
always_check(ResultE == 0);
Memory::Memset(PtrA, 0x3F, sizeof(int64));
always_check(TempA == 0x3F3F3F3F3F3F3F3F);

View File

@ -53,6 +53,20 @@ FORCEINLINE void* Memcpy(void* Destination, const void* Source, size_t Count)
return std::memcpy(Destination, Source, Count);
}
template <typename T>
FORCEINLINE void Memmove(T& Destination, const T& Source)
{
static_assert(!CPointer<T>, "For pointers use the three parameters function");
Memmove(&Destination, &Source, sizeof(T));
}
template <typename T>
FORCEINLINE int32 Memcmp(const T& BufferLHS, const T& BufferRHS)
{
static_assert(!CPointer<T>, "For pointers use the three parameters function");
return Memcmp(&BufferLHS, &BufferRHS, sizeof(T));
}
template <typename T>
FORCEINLINE void Memset(T& Source, uint8 ValueToSet)
{