OpenTTD Source 20250205-master-gfd85ab1e2c
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
22template <typename T>
23inline void MemCpyT(T *destination, const T *source, size_t num = 1)
24{
25 memcpy(destination, source, num * sizeof(T));
26}
27
35template <typename T>
36inline void MemMoveT(T *destination, const T *source, size_t num = 1)
37{
38 memmove(destination, source, num * sizeof(T));
39}
40
48template <typename T>
49inline void MemSetT(T *ptr, uint8_t value, size_t num = 1)
50{
51 memset(ptr, value, num * sizeof(T));
52}
53
62template <typename T>
63inline 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 */
Integer math functions.
void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
Definition mem_func.hpp:23
void MemMoveT(T *destination, const T *source, size_t num=1)
Type-safe version of memmove().
Definition mem_func.hpp:36
int MemCmpT(const T *ptr1, const T *ptr2, size_t num=1)
Type-safe version of memcmp().
Definition mem_func.hpp:63
void MemSetT(T *ptr, uint8_t value, size_t num=1)
Type-safe version of memset().
Definition mem_func.hpp:49