SeqAn3
3.4.0
The Modern C++ library for sequence analysis.
Toggle main menu visibility
Loading...
Searching...
No Matches
to_little_endian.hpp
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin
2
// SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik
3
// SPDX-License-Identifier: BSD-3-Clause
4
9
10
#pragma once
11
12
#include <bit>
13
#include <concepts>
14
15
// Find correct header for byte-order conversion functions.
16
#if __has_include(<endian.h>)
// unix GLIBC
17
# include <endian.h>
18
#elif __has_include(<sys/endian.h>)
// *BSD
19
# include <sys/endian.h>
20
#endif
// __has_include(endian.h)
21
22
#include <
seqan3/core/platform.hpp
>
23
24
namespace
seqan3::detail
25
{
38
template
<std::
int
egral type>
39
constexpr
type to_little_endian(type
const
in)
noexcept
40
{
41
if
constexpr
(std::endian::native == std::endian::little)
42
{
43
return
in;
44
}
45
else
if
constexpr
(std::endian::native == std::endian::big)
46
{
47
static_assert
(
sizeof
(type) <= 8,
48
"Can only convert the byte encoding for integral numbers with a size of up to 8 bytes."
);
49
static_assert
(std::has_single_bit(
sizeof
(type)),
50
"Can only convert the byte encoding for integral numbers whose byte size is a power of two."
);
51
52
if
constexpr
(
sizeof
(type) == 2)
53
return
htole16(in);
54
else
if
constexpr
(
sizeof
(type) == 4)
55
return
htole32(in);
56
else
if
constexpr
(
sizeof
(type) == 8)
57
return
htole64(in);
58
else
59
return
in;
// single byte.
60
}
61
else
62
{
63
static_assert
(std::endian::native == std::endian::little || std::endian::native == std::endian::big,
64
"Expected a little-endian or big-endian platform."
);
65
}
66
}
67
68
}
// namespace seqan3::detail
platform.hpp
Provides platform and dependency checks.
Hide me
Version:
seqan3
utility
detail
to_little_endian.hpp
Generated on
for SeqAn3 by
1.17.0