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/>.
8 /** @file mem_func.hpp Functions related to memory operations. */
13 #include "math_func.hpp"
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!)
23 inline void MemCpyT(T
*destination
, const T
*source
, size_t num
= 1)
25 memcpy(destination
, source
, num
* sizeof(T
));
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!)
36 inline void MemMoveT(T
*destination
, const T
*source
, size_t num
= 1)
38 memmove(destination
, source
, num
* sizeof(T
));
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!)
49 inline void MemSetT(T
*ptr
, uint8_t value
, size_t num
= 1)
51 memset(ptr
, value
, num
* sizeof(T
));
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
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 */