feat(memory): add template function overload for Memmove and Memcmp
This commit is contained in:
parent
015b6df809
commit
6b42dbdc05
@ -71,6 +71,10 @@ void TestMemoryBuffer()
|
|||||||
Memory::Memmove(PtrA, PtrA + 2, 6);
|
Memory::Memmove(PtrA, PtrA + 2, 6);
|
||||||
always_check((TempA << 16) == TempB);
|
always_check((TempA << 16) == TempB);
|
||||||
|
|
||||||
|
TempA = 0x0123456789ABCDEF;
|
||||||
|
Memory::Memmove(TempB, TempA);
|
||||||
|
always_check(TempB == TempA);
|
||||||
|
|
||||||
TempA = 1004;
|
TempA = 1004;
|
||||||
TempB = 1005;
|
TempB = 1005;
|
||||||
TempC = 1005;
|
TempC = 1005;
|
||||||
@ -78,8 +82,13 @@ void TestMemoryBuffer()
|
|||||||
int32 ResultA = Memory::Memcmp(PtrA, PtrB, sizeof(int64));
|
int32 ResultA = Memory::Memcmp(PtrA, PtrB, sizeof(int64));
|
||||||
int32 ResultB = Memory::Memcmp(PtrB, PtrC, sizeof(int64));
|
int32 ResultB = Memory::Memcmp(PtrB, PtrC, sizeof(int64));
|
||||||
int32 ResultC = Memory::Memcmp(PtrC, PtrD, 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);
|
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));
|
Memory::Memset(PtrA, 0x3F, sizeof(int64));
|
||||||
always_check(TempA == 0x3F3F3F3F3F3F3F3F);
|
always_check(TempA == 0x3F3F3F3F3F3F3F3F);
|
||||||
|
@ -53,6 +53,20 @@ FORCEINLINE void* Memcpy(void* Destination, const void* Source, size_t Count)
|
|||||||
return std::memcpy(Destination, Source, 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>
|
template <typename T>
|
||||||
FORCEINLINE void Memset(T& Source, uint8 ValueToSet)
|
FORCEINLINE void Memset(T& Source, uint8 ValueToSet)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user