mem_func.hpp

Go to the documentation of this file.
00001 /* $Id: mem_func.hpp 18809 2010-01-15 16:41:15Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef MEM_FUNC_HPP
00013 #define MEM_FUNC_HPP
00014 
00015 #include "math_func.hpp"
00016 
00024 template <typename T>
00025 static FORCEINLINE void MemCpyT(T *destination, const T *source, size_t num = 1)
00026 {
00027   memcpy(destination, source, num * sizeof(T));
00028 }
00029 
00037 template <typename T>
00038 static FORCEINLINE void MemMoveT(T *destination, const T *source, size_t num = 1)
00039 {
00040   memmove(destination, source, num * sizeof(T));
00041 }
00042 
00050 template <typename T>
00051 static FORCEINLINE void MemSetT(T *ptr, byte value, size_t num = 1)
00052 {
00053   memset(ptr, value, num * sizeof(T));
00054 }
00055 
00064 template <typename T>
00065 static FORCEINLINE int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
00066 {
00067   return memcmp(ptr1, ptr2, num * sizeof(T));
00068 }
00069 
00078 template <typename T>
00079 static FORCEINLINE void MemReverseT(T *ptr1, T *ptr2)
00080 {
00081   assert(ptr1 != NULL && ptr2 != NULL);
00082   assert(ptr1 < ptr2);
00083 
00084   do {
00085     Swap(*ptr1, *ptr2);
00086   } while (++ptr1 < --ptr2);
00087 }
00088 
00095 template <typename T>
00096 static FORCEINLINE void MemReverseT(T *ptr, size_t num)
00097 {
00098   assert(ptr != NULL);
00099 
00100   MemReverseT(ptr, ptr + (num - 1));
00101 }
00102 
00103 #endif /* MEM_FUNC_HPP */

Generated on Sat Jul 31 21:37:45 2010 for OpenTTD by  doxygen 1.6.1