OpenTTD: src/core/mem_func.hpp Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

mem_func.hpp
Go to the documentation of this file.
1 /* $Id: mem_func.hpp 23640 2011-12-20 17:57:56Z truebrain $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef MEM_FUNC_HPP
13 #define MEM_FUNC_HPP
14
15 #include "math_func.hpp"
16
24 template <typename T>
25 static inline void MemCpyT(T *destination, const T *source, size_t num = 1)
26 {
27 memcpy(destination, source, num * sizeof(T));
28 }
29
37 template <typename T>
38 static inline void MemMoveT(T *destination, const T *source, size_t num = 1)
39 {
40 memmove(destination, source, num * sizeof(T));
41 }
42
50 template <typename T>
51 static inline void MemSetT(T *ptr, byte value, size_t num = 1)
52 {
53 memset(ptr, value, num * sizeof(T));
54 }
55
64 template <typename T>
65 static inline int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
66 {
67 return memcmp(ptr1, ptr2, num * sizeof(T));
68 }
69
78 template <typename T>
79 static inline void MemReverseT(T *ptr1, T *ptr2)
80 {
81 assert(ptr1 != NULL && ptr2 != NULL);
82 assert(ptr1 < ptr2);
83
84 do {
85 Swap(*ptr1, *ptr2);
86 } while (++ptr1 < --ptr2);
87 }
88
95 template <typename T>
96 static inline void MemReverseT(T *ptr, size_t num)
97 {
98 assert(ptr != NULL);
99
100 MemReverseT(ptr, ptr + (num - 1));
101 }
102
103 #endif /* MEM_FUNC_HPP */