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