Fix: Don't allow right-click to close world generation progress window. (#13084)
[openttd-github.git] / src / core / mem_func.hpp
blob202d1ebe1521f4ad75b23c3d8f351395c07c5d9a
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 */
8 /** @file mem_func.hpp Functions related to memory operations. */
10 #ifndef MEM_FUNC_HPP
11 #define MEM_FUNC_HPP
13 #include "math_func.hpp"
15 /**
16 * Type-safe version of memcpy().
18 * @param destination Pointer to the destination buffer
19 * @param source Pointer to the source buffer
20 * @param num number of items to be copied. (!not number of bytes!)
22 template <typename T>
23 inline void MemCpyT(T *destination, const T *source, size_t num = 1)
25 memcpy(destination, source, num * sizeof(T));
28 /**
29 * Type-safe version of memmove().
31 * @param destination Pointer to the destination buffer
32 * @param source Pointer to the source buffer
33 * @param num number of items to be copied. (!not number of bytes!)
35 template <typename T>
36 inline void MemMoveT(T *destination, const T *source, size_t num = 1)
38 memmove(destination, source, num * sizeof(T));
41 /**
42 * Type-safe version of memset().
44 * @param ptr Pointer to the destination buffer
45 * @param value Value to be set
46 * @param num number of items to be set (!not number of bytes!)
48 template <typename T>
49 inline void MemSetT(T *ptr, uint8_t value, size_t num = 1)
51 memset(ptr, value, num * sizeof(T));
54 /**
55 * Type-safe version of memcmp().
57 * @param ptr1 Pointer to the first buffer
58 * @param ptr2 Pointer to the second buffer
59 * @param num Number of items to compare. (!not number of bytes!)
60 * @return an int value indicating the relationship between the content of the two buffers
62 template <typename T>
63 inline int MemCmpT(const T *ptr1, const T *ptr2, size_t num = 1)
65 return memcmp(ptr1, ptr2, num * sizeof(T));
68 #endif /* MEM_FUNC_HPP */