mem_func.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef MEM_FUNC_HPP
00013 #define MEM_FUNC_HPP
00014
00015 #include <string.h>
00016 #include "math_func.hpp"
00017
00025 template <typename T>
00026 static FORCEINLINE void MemCpyT(T *destination, const T *source, size_t num = 1)
00027 {
00028 memcpy(destination, source, num * sizeof(T));
00029 }
00030
00038 template <typename T>
00039 static FORCEINLINE void MemMoveT(T *destination, const T *source, size_t num = 1)
00040 {
00041 memmove(destination, source, num * sizeof(T));
00042 }
00043
00051 template <typename T>
00052 static FORCEINLINE void MemSetT(T *ptr, byte value, size_t num = 1)
00053 {
00054 memset(ptr, value, num * sizeof(T));
00055 }
00056
00065 template <typename T>
00066 static FORCEINLINE int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
00067 {
00068 return memcmp(ptr1, ptr2, num * sizeof(T));
00069 }
00070
00079 template <typename T>
00080 static FORCEINLINE void MemReverseT(T *ptr1, T *ptr2)
00081 {
00082 assert(ptr1 != NULL && ptr2 != NULL);
00083 assert(ptr1 < ptr2);
00084
00085 do {
00086 Swap(*ptr1, *ptr2);
00087 } while (++ptr1 < --ptr2);
00088 }
00089
00096 template <typename T>
00097 static FORCEINLINE void MemReverseT(T *ptr, size_t num)
00098 {
00099 assert(ptr != NULL);
00100
00101 MemReverseT(ptr, ptr + (num - 1));
00102 }
00103
00104 #endif