mem_func.hpp

Go to the documentation of this file.
00001 /* $Id: mem_func.hpp 15571 2009-02-24 22:25:23Z smatz $ */
00002 
00005 #ifndef MEM_FUNC_HPP
00006 #define MEM_FUNC_HPP
00007 
00008 #include <string.h>
00009 #include "math_func.hpp"
00010 
00018 template <typename T>
00019 static FORCEINLINE void MemCpyT(T *destination, const T *source, uint num = 1)
00020 {
00021   memcpy(destination, source, num * sizeof(T));
00022 }
00023 
00031 template <typename T>
00032 static FORCEINLINE void MemMoveT(T *destination, const T *source, uint num = 1)
00033 {
00034   memmove(destination, source, num * sizeof(T));
00035 }
00036 
00044 template <typename T>
00045 static FORCEINLINE void MemSetT(T *ptr, byte value, uint num = 1)
00046 {
00047   memset(ptr, value, num * sizeof(T));
00048 }
00049 
00058 template <typename T>
00059 static FORCEINLINE int MemCmpT(const T *ptr1, const T *ptr2, uint num = 1)
00060 {
00061   return memcmp(ptr1, ptr2, num * sizeof(T));
00062 }
00063 
00072 template <typename T>
00073 static FORCEINLINE void MemReverseT(T *ptr1, T *ptr2)
00074 {
00075   assert(ptr1 != NULL && ptr2 != NULL);
00076   assert(ptr1 < ptr2);
00077 
00078   do {
00079     Swap(*ptr1, *ptr2);
00080   } while (++ptr1 < --ptr2);
00081 }
00082 
00089 template <typename T>
00090 static FORCEINLINE void MemReverseT(T *ptr, uint num)
00091 {
00092   assert(ptr != NULL);
00093 
00094   MemReverseT(ptr, ptr + (num - 1));
00095 }
00096 
00097 #endif /* MEM_FUNC_HPP */

Generated on Wed Jul 15 20:35:57 2009 for OpenTTD by  doxygen 1.5.6