2 * Copyright 2013 Sveriges Television AB http://casparcg.com/
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
20 * Author: Robert Nagy, ronag89@gmail.com
25 #include <type_traits>
35 typename std::enable_if<sizeof(T) == sizeof(std::uint8_t), T>::type swap_byte_order(
42 typename std::enable_if<sizeof(T) == sizeof(std::uint16_t), T>::type swap_byte_order(
46 auto swapped = _byteswap_ushort(reinterpret_cast<const unsigned short&>(value));
48 auto swapped = __builtin_bswap16(value);
51 return reinterpret_cast<const T&>(swapped);
55 typename std::enable_if<sizeof(T) == sizeof(std::uint32_t), T>::type swap_byte_order(
59 auto swapped = _byteswap_ulong(reinterpret_cast<const unsigned long&>(value));
61 auto swapped = __builtin_bswap32(value);
64 return reinterpret_cast<const T&>(swapped);
68 typename std::enable_if<sizeof(T) == sizeof(std::uint64_t), T>::type swap_byte_order(
72 auto swapped = _byteswap_uint64(reinterpret_cast<const unsigned long long&>(value));
74 auto swapped = __builtin_bswap64(value);
77 return reinterpret_cast<const T&>(swapped);