OpenTTD Source: src/core/mem_func.hpp Source File

OpenTTD Source 14.1

mem_func.hpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #ifndef MEM_FUNC_HPP
11 #define MEM_FUNC_HPP
12
13 #include "math_func.hpp"
14
22 template <typename T>
23 inline void MemCpyT(T *destination, const T *source, size_t num = 1)
24 {
25 memcpy(destination, source, num * sizeof(T));
26 }
27
35 template <typename T>
36 inline void MemMoveT(T *destination, const T *source, size_t num = 1)
37 {
38 memmove(destination, source, num * sizeof(T));
39 }
40
48 template <typename T>
49 inline void MemSetT(T *ptr, byte value, size_t num = 1)
50 {
51 memset(ptr, value, num * sizeof(T));
52 }
53
62 template <typename T>
63 inline int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
64 {
65 return memcmp(ptr1, ptr2, num * sizeof(T));
66 }
67
68 #endif /* MEM_FUNC_HPP */
math_func.hpp
MemCpyT
void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
Definition: mem_func.hpp:23
MemCmpT
int MemCmpT(const T *ptr1, const T *ptr2, size_t num=1)
Type-safe version of memcmp().
Definition: mem_func.hpp:63
MemMoveT
void MemMoveT(T *destination, const T *source, size_t num=1)
Type-safe version of memmove().
Definition: mem_func.hpp:36
MemSetT
void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
Definition: mem_func.hpp:49