skidd13@10962: /* $Id$ */ skidd13@10962: skidd13@10962: /** @file mem_func.hpp Functions related to memory operations. */ skidd13@10962: skidd13@10962: #ifndef MEM_FUNC_HPP skidd13@10962: #define MEM_FUNC_HPP skidd13@10962: skidd13@10962: #include skidd13@10962: #include "math_func.hpp" skidd13@10962: skidd13@10962: /** skidd13@10962: * Type-safe version of memcpy(). skidd13@10962: * skidd13@10962: * @param destination Pointer to the destination buffer skidd13@10962: * @param source Pointer to the source buffer skidd13@10962: * @param num number of items to be copied. (!not number of bytes!) skidd13@10962: */ skidd13@10962: template skidd13@11049: static FORCEINLINE void MemCpyT(T *destination, const T *source, uint num = 1) skidd13@10962: { skidd13@10962: memcpy(destination, source, num * sizeof(T)); skidd13@10962: } skidd13@10962: skidd13@10962: /** skidd13@10963: * Type-safe version of memmove(). skidd13@10963: * skidd13@10963: * @param destination Pointer to the destination buffer skidd13@10963: * @param source Pointer to the source buffer skidd13@10963: * @param num number of items to be copied. (!not number of bytes!) skidd13@10963: */ skidd13@10963: template skidd13@11049: static FORCEINLINE void MemMoveT(T *destination, const T *source, uint num = 1) skidd13@10963: { skidd13@10963: memmove(destination, source, num * sizeof(T)); skidd13@10963: } skidd13@10963: skidd13@10963: /** skidd13@10963: * Type-safe version of memset(). skidd13@10963: * skidd13@10963: * @param ptr Pointer to the destination buffer skidd13@10963: * @param value Value to be set skidd13@10963: * @param num number of items to be set (!not number of bytes!) skidd13@10963: */ skidd13@10963: template skidd13@11049: static FORCEINLINE void MemSetT(T *ptr, int value, uint num = 1) skidd13@10963: { skidd13@10963: memset(ptr, value, num * sizeof(T)); skidd13@10963: } skidd13@10963: skidd13@10963: /** skidd13@10963: * Type-safe version of memcmp(). skidd13@10963: * skidd13@10963: * @param ptr1 Pointer to the first buffer skidd13@10963: * @param ptr2 Pointer to the second buffer skidd13@10963: * @param num Number of items to compare. (!not number of bytes!) skidd13@10963: * @return an int value indicating the relationship between the content of the two buffers skidd13@10963: */ skidd13@10963: template skidd13@11049: static FORCEINLINE int MemCmpT(const T *ptr1, const T *ptr2, uint num = 1) skidd13@10963: { skidd13@10963: return memcmp(ptr1, ptr2, num * sizeof(T)); skidd13@10963: } skidd13@10963: skidd13@10963: /** skidd13@10962: * Type safe memory reverse operation. skidd13@10962: * Reverse a block of memory in steps given by the skidd13@10962: * type of the pointers. skidd13@10962: * skidd13@10962: * @param ptr1 Start-pointer to the block of memory. skidd13@10962: * @param ptr2 End-pointer to the block of memory. skidd13@10962: */ skidd13@11049: template skidd13@11049: static FORCEINLINE void MemReverseT(T *ptr1, T *ptr2) skidd13@10962: { skidd13@10962: assert(ptr1 != NULL && ptr2 != NULL); skidd13@10962: assert(ptr1 < ptr2); skidd13@10962: skidd13@10962: do { skidd13@10962: Swap(*ptr1, *ptr2); skidd13@10962: } while (++ptr1 < --ptr2); skidd13@10962: } skidd13@10962: skidd13@10962: /** skidd13@10962: * Type safe memory reverse operation (overloaded) skidd13@10962: * skidd13@10962: * @param ptr Pointer to the block of memory. skidd13@10962: * @param num The number of items we want to reverse. skidd13@10962: */ skidd13@11049: template skidd13@11049: static FORCEINLINE void MemReverseT(T *ptr, uint num) skidd13@10962: { skidd13@10962: assert(ptr != NULL); skidd13@10962: skidd13@10962: MemReverseT(ptr, ptr + (num - 1)); skidd13@10962: } skidd13@10962: skidd13@10962: #endif /* MEM_FUNC_HPP */