2015-10-16 10:30:34 -04:00
|
|
|
|
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
|
|
|
|
|
<head>
|
|
|
|
|
|
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
|
|
|
|
|
|
<meta name="ProgId" content="FrontPage.Editor.Document">
|
2013-05-28 11:04:03 -04:00
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
2014-11-12 08:26:01 -05:00
|
|
|
|
<title>Endian Conversion Functions</title>
|
|
|
|
|
|
<link href="styles.css" rel="stylesheet">
|
2011-05-27 20:18:13 +00:00
|
|
|
|
</head>
|
|
|
|
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
2013-05-28 17:06:32 -04:00
|
|
|
|
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
|
2011-05-27 20:18:13 +00:00
|
|
|
|
<tr>
|
2013-05-28 17:06:32 -04:00
|
|
|
|
<td>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
<a href="../../../index.html">
|
2015-01-19 07:41:28 -05:00
|
|
|
|
<img src="../../../boost.png" alt="Boost logo" align="middle" border="0" width="277" height="86" ></a></td>
|
2013-05-28 17:06:32 -04:00
|
|
|
|
<td align="middle">
|
2014-11-19 15:58:15 -05:00
|
|
|
|
<b>
|
2014-12-10 08:30:30 -05:00
|
|
|
|
<font size="6">Endian Conversion Functions</font></b></td>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
</tr>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
|
|
|
|
|
|
<tr>
|
2015-01-02 10:46:53 -05:00
|
|
|
|
<td><b>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
<a href="index.html">Endian Home</a>
|
2011-09-04 13:51:49 +00:00
|
|
|
|
<a href="conversion.html">Conversion Functions</a>
|
2014-11-19 15:58:15 -05:00
|
|
|
|
<a href="arithmetic.html">Arithmetic Types</a>
|
2015-01-02 10:46:53 -05:00
|
|
|
|
<a href="buffers.html">Buffer Types</a>
|
|
|
|
|
|
<a href="choosing_approach.html">Choosing Approach</a></b></td>
|
2011-09-04 13:51:49 +00:00
|
|
|
|
</tr>
|
|
|
|
|
|
</table>
|
2013-05-28 21:11:18 -04:00
|
|
|
|
|
|
|
|
|
|
<p></p>
|
|
|
|
|
|
|
2011-09-04 13:51:49 +00:00
|
|
|
|
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" align="right">
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td width="100%" bgcolor="#D7EEFF" align="center">
|
|
|
|
|
|
<i><b>Contents</b></i></td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td width="100%" bgcolor="#E8F5FF">
|
|
|
|
|
|
<a href="#Introduction">Introduction</a><br>
|
|
|
|
|
|
<a href="#Reference">Reference</a><br>
|
|
|
|
|
|
<a href="#Synopsis">Synopsis</a><br>
|
2013-05-19 17:08:42 -04:00
|
|
|
|
<a href="#Requirements">Requirements</a><br>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<code><a href="#EndianReversible">EndianReversible</a></code><br>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
<a href="#Customization-points">Customization for
|
|
|
|
|
|
UDTs</a><br>
|
|
|
|
|
|
<a href="#Functions">Functions</a><br>
|
2013-05-28 11:04:03 -04:00
|
|
|
|
<a href="#FAQ">FAQ</a><br>
|
2011-09-04 13:51:49 +00:00
|
|
|
|
<a href="#Acknowledgements">Acknowledgements</a></td>
|
|
|
|
|
|
</tr>
|
2015-01-17 16:53:41 -05:00
|
|
|
|
</table>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
|
|
|
|
|
<h2><a name="Introduction">Introduction</a></h2>
|
|
|
|
|
|
|
2013-05-28 21:33:07 -04:00
|
|
|
|
<p>Header <a href="../include/boost/endian/conversion.hpp">boost/endian/conversion.hpp</a>
|
2013-05-19 17:08:42 -04:00
|
|
|
|
provides byte order reversal and conversion functions that convert objects of
|
2015-03-25 08:05:49 -04:00
|
|
|
|
the built-in
|
|
|
|
|
|
integer types
|
2013-05-19 17:08:42 -04:00
|
|
|
|
between native, big, or little endian byte
|
2013-05-18 16:53:27 -04:00
|
|
|
|
ordering. User defined types are also supported.</p>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<h2><a name="Reference">Reference</a></h2>
|
|
|
|
|
|
|
2015-02-11 09:02:58 -05:00
|
|
|
|
<p>Functions are implemented <code>inline</code> if appropriate.<code> </code>
|
|
|
|
|
|
For C++03 compilers, <code> noexcept</code> is
|
2015-10-16 10:30:34 -04:00
|
|
|
|
elided.
|
2014-12-10 09:58:01 -05:00
|
|
|
|
Boost scoped enum emulation is used so that the library still works for compilers that do not support scoped enums.</p>
|
|
|
|
|
|
|
2015-10-16 10:30:34 -04:00
|
|
|
|
<h3><a name="Definitions">Definitions</a></h3>
|
|
|
|
|
|
<p><b><i>Endianness</i></b> refers to the ordering of bytes within internal or
|
|
|
|
|
|
external integers and other arithmetic data. Most-significant byte first is
|
|
|
|
|
|
called <b><i>big endian</i></b> ordering. Least-significant byte first is called
|
|
|
|
|
|
<b><i>little endian</i></b> ordering. Other orderings are possible and some CPU
|
|
|
|
|
|
architectures support both big and little ordering.</p>
|
|
|
|
|
|
<blockquote>
|
|
|
|
|
|
<p>[<i>Note:</i> The names are derived from
|
|
|
|
|
|
<a href="http://en.wikipedia.org/wiki/Jonathan_Swift" title="Jonathan Swift">
|
|
|
|
|
|
Jonathan Swift</a>'s satirical novel <i>
|
|
|
|
|
|
<a href="http://en.wikipedia.org/wiki/Gulliver's_Travels" title="Gulliver's Travels">
|
|
|
|
|
|
Gulliver’s Travels</a></i>, where rival kingdoms opened their soft-boiled eggs
|
|
|
|
|
|
at different ends. Wikipedia has an extensive description of
|
|
|
|
|
|
<a href="https://en.wikipedia.org/wiki/Endianness">Endianness</a>. <i>—end note</i>]</p>
|
|
|
|
|
|
</blockquote>
|
|
|
|
|
|
<p>The standard integral types (C++std 3.9.1) except <code>bool</code>
|
|
|
|
|
|
are collectively called the <b> <i>endian types</i></b>.</p>
|
|
|
|
|
|
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<h3>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
Header <code><boost/endian/conversion.hpp></code>
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<a name="Synopsis">Synopsis</a></h3>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
2015-02-11 09:02:58 -05:00
|
|
|
|
<pre>#define BOOST_ENDIAN_INTRINSIC_MSG \
|
|
|
|
|
|
"<b><font face="Arial"><i>message describing presence or absence of intrinsics</i></font></b>"
|
2013-05-19 17:08:42 -04:00
|
|
|
|
|
|
|
|
|
|
namespace boost
|
2011-05-27 20:18:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
namespace endian
|
|
|
|
|
|
{
|
2014-08-12 10:34:37 -04:00
|
|
|
|
enum class <a name="order">order</a>
|
|
|
|
|
|
{
|
2015-10-16 10:30:34 -04:00
|
|
|
|
native = <b><i>see below,
|
|
|
|
|
|
</i></b> big = <b><i>see below</i></b>,
|
|
|
|
|
|
little = <b><i>see below</i></b>,
|
|
|
|
|
|
<b><i> </i></b>};
|
2011-09-03 17:50:46 +00:00
|
|
|
|
|
2014-12-10 08:30:30 -05:00
|
|
|
|
int8_t <a href="#endian_reverse">endian_reverse</a>(int8_t x) noexcept;
|
|
|
|
|
|
int16_t <a href="#endian_reverse">endian_reverse</a>(int16_t x) noexcept;
|
|
|
|
|
|
int32_t <a href="#endian_reverse">endian_reverse</a>(int32_t x) noexcept;
|
|
|
|
|
|
int64_t <a href="#endian_reverse">endian_reverse</a>(int64_t x) noexcept;
|
|
|
|
|
|
uint8_t <a href="#endian_reverse">endian_reverse</a>(uint8_t x) noexcept;
|
|
|
|
|
|
uint16_t <a href="#endian_reverse">endian_reverse</a>(uint16_t x) noexcept;
|
|
|
|
|
|
uint32_t <a href="#endian_reverse">endian_reverse</a>(uint32_t x) noexcept;
|
|
|
|
|
|
uint64_t <a href="#endian_reverse">endian_reverse</a>(uint64_t x) noexcept;
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
template <class EndianReversible>
|
|
|
|
|
|
EndianReversible big_to_native(EndianReversible x) noexcept;
|
|
|
|
|
|
template <class EndianReversible>
|
|
|
|
|
|
EndianReversible native_to_big(EndianReversible x) noexcept;
|
|
|
|
|
|
template <class EndianReversible>
|
|
|
|
|
|
EndianReversible little_to_native(EndianReversible x) noexcept;
|
|
|
|
|
|
template <class EndianReversible>
|
|
|
|
|
|
EndianReversible native_to_little(EndianReversible x) noexcept;
|
|
|
|
|
|
template <order O1, order O2, class EndianReversible>
|
|
|
|
|
|
EndianReversible conditional_reverse(EndianReversible x) noexcept;
|
|
|
|
|
|
template <class EndianReversible>
|
|
|
|
|
|
EndianReversible conditional_reverse(EndianReversible x,
|
2014-12-09 20:43:47 -05:00
|
|
|
|
order order1, order order2) noexcept;
|
|
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
template <class EndianReversible>
|
|
|
|
|
|
void endian_reverse_inplace(EndianReversible& x) noexcept;
|
2014-12-09 20:43:47 -05:00
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
template <class EndianReversibleInplace>
|
|
|
|
|
|
void big_to_native_inplace(EndianReversibleInplace& x) noexcept;
|
|
|
|
|
|
template <class EndianReversibleInplace>
|
|
|
|
|
|
void native_to_big_inplace(EndianReversibleInplace& x) noexcept;
|
|
|
|
|
|
template <class EndianReversibleInplace>
|
|
|
|
|
|
void little_to_native_inplace(EndianReversibleInplace& x) noexcept;
|
|
|
|
|
|
template <class EndianReversibleInplace>
|
|
|
|
|
|
void native_to_little_inplace(EndianReversibleInplace& x) noexcept;
|
|
|
|
|
|
template <order O1, order O2, class EndianReversibleInplace>
|
|
|
|
|
|
void conditional_reverse_inplace(EndianReversibleInplace& x) noexcept;
|
|
|
|
|
|
template <class EndianReversibleInplace>
|
|
|
|
|
|
void conditional_reverse_inplace(EndianReversibleInplace& x,
|
2014-12-09 20:43:47 -05:00
|
|
|
|
order order1, order order2) noexcept;
|
2011-09-03 17:50:46 +00:00
|
|
|
|
|
|
|
|
|
|
} // namespace endian
|
2011-05-27 20:18:13 +00:00
|
|
|
|
} // namespace boost</pre>
|
2015-10-16 10:30:34 -04:00
|
|
|
|
<p>The values of <code>order::little</code> and <code>order::big</code> shall
|
|
|
|
|
|
not be equal to one another. </p>
|
|
|
|
|
|
<p><a name="native-order-specification"></a>The value of <code>order::native</code>
|
|
|
|
|
|
shall be:</p>
|
|
|
|
|
|
<ul>
|
|
|
|
|
|
<li>equal to <code>order::big</code> if the execution environment is big
|
|
|
|
|
|
endian, otherwise</li>
|
|
|
|
|
|
<li>equal to <code>order::little</code> if the execution environment is little
|
|
|
|
|
|
endian, otherwise</li>
|
|
|
|
|
|
<li>unequal to both <code>order::little</code> and <code>order::big</code>.</li>
|
|
|
|
|
|
</ul>
|
2013-05-19 11:07:33 -04:00
|
|
|
|
<h3><a name="Requirements">Requirements</a></h3>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<h4><a name="Template-argument-requirements">Template argument requirements</a></h4>
|
2015-10-16 10:30:34 -04:00
|
|
|
|
<p>The template definitions in the <code>boost/endian/conversion.hpp</code>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
header refer to various named requirements whose details are set out in the
|
|
|
|
|
|
tables in this subsection. In these tables, <code>T</code> is an object or
|
|
|
|
|
|
reference type to be supplied by a C++ program instantiating a template; <code>x</code>
|
|
|
|
|
|
is a value of type (possibly <code>const</code>) <code>T</code>; <code>mlx</code> is a
|
|
|
|
|
|
modifiable lvalue of type <code>T</code>.</p>
|
2013-05-19 11:07:33 -04:00
|
|
|
|
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
|
|
|
|
|
<tr>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<td colspan="3" align="center"><b><code><a name="EndianReversible">EndianReversible</a></code></b>
|
|
|
|
|
|
requirements (in addition to <b><code>CopyConstructible</code></b>)</td>
|
2013-05-19 11:07:33 -04:00
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<td><b>Expression</b></td>
|
|
|
|
|
|
<td><b>Return<br>
|
|
|
|
|
|
type</b></td>
|
|
|
|
|
|
<td><b>Requirements</b></td>
|
2013-05-19 11:07:33 -04:00
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<td valign="top"><code>endian_reverse(x)</code></td>
|
|
|
|
|
|
<td align="center" valign="top"><code>T</code></td>
|
|
|
|
|
|
<td> <code>T</code> is an endian type or a class type.<p>If <code>T</code> is
|
|
|
|
|
|
an endian type, returns the value of <code>x</code> with the order of bytes
|
|
|
|
|
|
reversed.</p>
|
2015-02-11 09:02:58 -05:00
|
|
|
|
<p>If <code>T</code> is a class type, the function:</p>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<ul>
|
|
|
|
|
|
<li>Returns the value of <code>x</code>
|
|
|
|
|
|
with the order of bytes reversed for all data members of types or arrays of
|
|
|
|
|
|
types that meet the <code>EndianReversible</code> requirements, and;</li>
|
|
|
|
|
|
<li>Is a non-member function in the same namespace as <code>T</code> that
|
|
|
|
|
|
can be found by argument dependent lookup (ADL). </li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td colspan="2" align="center"><b><code><a name="EndianReversibleInplace">EndianReversibleInplace</a></code></b>
|
|
|
|
|
|
requirements (in addition to <b><code>CopyConstructible</code></b>)</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td><b>Expression</b></td>
|
|
|
|
|
|
<td><b>Requirements</b></td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td valign="top"><code>endian_reverse_inplace(mlx)</code></td>
|
|
|
|
|
|
<td> <code>T</code> is an endian type or a class type.<p>If <code>T</code> is
|
|
|
|
|
|
an endian type, reverses the order of bytes in <code>mlx</code>.</p>
|
2015-02-11 09:02:58 -05:00
|
|
|
|
<p>If <code>T</code> is a class type, the function:</p>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<ul>
|
|
|
|
|
|
<li>Reverses the order of bytes of all data members of <code>mlx</code>
|
|
|
|
|
|
that have types or arrays of
|
|
|
|
|
|
types that meet the <code>EndianReversible</code> or <code>EndianReversibleInplace</code>
|
|
|
|
|
|
requirements, and;</li>
|
|
|
|
|
|
<li>Is a non-member function in the same namespace as <code>T</code> that
|
|
|
|
|
|
can be found by argument dependent lookup (ADL). </li>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
</td>
|
2013-05-19 11:07:33 -04:00
|
|
|
|
</tr>
|
|
|
|
|
|
</table>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
|
2014-12-10 09:39:03 -05:00
|
|
|
|
<p> [<i>Note:</i> Because there is a function template for <code>endian_reverse_inplace</code>
|
2014-12-10 08:30:30 -05:00
|
|
|
|
that calls <code>endian_reverse</code>, only <code>endian_reverse</code>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
is required for a user-defined type to meet the <code>EndianReversibleInplace</code>
|
|
|
|
|
|
requirements. Although User-defined types are not required to supply an <code>endian_reverse_inplace</code>
|
2015-02-11 09:02:58 -05:00
|
|
|
|
function, doing so may improve efficiency. <i> —end note</i>]</p>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
|
|
|
|
|
|
<h4> <a name="Customization-points">Customization points</a> for user-defined types (<a name="UDT">UDT</a>s)</h4>
|
|
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<p> This subsection describes requirements on the Endian library's implementation.</p>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<p> The library's function templates requiring <code>
|
|
|
|
|
|
<a href="#EndianReversible">EndianReversible</a></code> are
|
2014-12-09 07:04:48 -05:00
|
|
|
|
required to perform reversal of endianness if needed by making an unqualified
|
2014-12-11 11:41:44 -05:00
|
|
|
|
call to <code>endian_reverse()</code>.</p>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<p> The library's function templates requiring <code>
|
|
|
|
|
|
<a href="#EndianReversibleInplace">EndianReversibleInplace</a></code> are required to perform reversal of endianness if needed by making an
|
|
|
|
|
|
unqualified call to <code>endian_reverse_inplace()</code>.</p>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
|
2015-01-17 16:53:41 -05:00
|
|
|
|
<p> See <b><code>example/udt_conversion_example.cpp</code></b> for an example user-defined type.</p>
|
2014-12-09 07:04:48 -05:00
|
|
|
|
|
2013-05-19 11:07:33 -04:00
|
|
|
|
<h3><a name="Functions">Functions</a></h3>
|
2014-12-10 08:30:30 -05:00
|
|
|
|
<pre><a name="endian_reverse"></a>int8_t endian_reverse(int8_t x) noexcept;
|
|
|
|
|
|
int16_t endian_reverse(int16_t x) noexcept;
|
|
|
|
|
|
int32_t endian_reverse(int32_t x) noexcept;
|
|
|
|
|
|
int64_t endian_reverse(int64_t x) noexcept;
|
|
|
|
|
|
uint8_t endian_reverse(uint8_t x) noexcept;
|
|
|
|
|
|
uint16_t endian_reverse(uint16_t x) noexcept;
|
|
|
|
|
|
uint32_t endian_reverse(uint32_t x) noexcept;
|
2015-03-25 08:05:49 -04:00
|
|
|
|
uint64_t endian_reverse(uint64_t x) noexcept;</pre>
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<blockquote>
|
2015-10-16 10:30:34 -04:00
|
|
|
|
<p><i>Returns:</i> <i><code>x</code></i>, with the order of its
|
2013-05-19 11:07:33 -04:00
|
|
|
|
constituent bytes reversed.</p>
|
2015-02-11 09:02:58 -05:00
|
|
|
|
<p><i>Remarks:</i> The type of <i><code>x</code></i> meets the <code>EndianReversible</code> requirements.</p>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<p>[<i>Note:</i> The Boost.Endian library does not provide overloads for the C++ standard library
|
|
|
|
|
|
supplied types. <i>—end note</i>]</p>
|
2011-09-03 17:50:46 +00:00
|
|
|
|
</blockquote>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversible>
|
|
|
|
|
|
EndianReversible big_to_native(EndianReversible x) noexcept;</pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
|
|
|
|
|
<p>
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<i>Returns:</i> <code>conditional_reverse<order::big, order::native>(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversible>
|
|
|
|
|
|
EndianReversible native_to_big(EndianReversible x) noexcept; </pre>
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<blockquote>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<p><i>Returns:</i> <code>conditional_reverse<order::native, order::big>(x)</code>.</p>
|
2011-09-03 17:50:46 +00:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversible>
|
|
|
|
|
|
EndianReversible little_to_native(EndianReversible x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
|
|
|
|
|
<p><i>Returns:</i> <code>conditional_reverse<order::little, order::native>(x)</code>.</p>
|
|
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversible>
|
|
|
|
|
|
EndianReversible native_to_little(EndianReversible x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
|
|
|
|
|
<p><i>Returns:</i> <code>conditional_reverse<order::native, order::little>(x)</code>.</p>
|
|
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <order O1, order O2, class EndianReversible>
|
|
|
|
|
|
EndianReversible conditional_reverse(EndianReversible x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<p><i>Returns:</i> <code>x</code> if <code>O1 == O2,</code> otherwise <code>endian_reverse(x)</code>.</p>
|
|
|
|
|
|
<p><i>Remarks: </i>Whether <code>x</code> or <code>endian_reverse(x)</code> is to be returned shall be determined at compile time.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversible>
|
|
|
|
|
|
EndianReversible conditional_reverse(EndianReversible x,
|
2014-12-09 20:43:47 -05:00
|
|
|
|
order order1, order order2) noexcept; </pre>
|
|
|
|
|
|
<blockquote>
|
2014-12-10 08:30:30 -05:00
|
|
|
|
<p><i>Returns:</i> <code>order1 == order2 ? x : endian_reverse(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversible>
|
|
|
|
|
|
void endian_reverse_inplace(EndianReversible& x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<blockquote>
|
2014-12-10 08:30:30 -05:00
|
|
|
|
<p><i>Effects:</i> <code>x</code> <code>= endian_reverse(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversibleInplace>
|
|
|
|
|
|
void big_to_native_inplace(EndianReversibleInplace& x) noexcept; </pre>
|
2011-09-03 17:50:46 +00:00
|
|
|
|
<blockquote>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<p>
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<i>Effects:</i> <code>conditional_reverse_inplace<order::big, order::native>(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversibleInplace>
|
|
|
|
|
|
void native_to_big_inplace(EndianReversibleInplace& x) noexcept; </pre>
|
2013-05-19 08:26:09 -04:00
|
|
|
|
<blockquote>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<p>
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<i>Effects:</i> <code>conditional_reverse_inplace<order::native, order::big>(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversibleInplace>
|
|
|
|
|
|
void little_to_native_inplace(EndianReversibleInplace& x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
|
|
|
|
|
<p>
|
2014-12-10 09:39:03 -05:00
|
|
|
|
<i>Effects:</i> <code>conditional_reverse_inplace<order::little, order::native>(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversibleInplace>
|
|
|
|
|
|
void native_to_little_inplace(EndianReversibleInplace& x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
|
|
|
|
|
<p>
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<i>Effects:</i> <code>conditional_reverse_inplace<order::native, order::little>(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <order O1, order O2, class EndianReversibleInplace>
|
|
|
|
|
|
void conditional_reverse_inplace(EndianReversibleInplace& x) noexcept; </pre>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<blockquote>
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<p><i>Effects:</i> None if <code>O1 == O2,</code> otherwise <code>endian_reverse_inplace(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
<p><i>Remarks: </i>Which effect applies shall be determined at compile time.</p>
|
|
|
|
|
|
</blockquote>
|
2014-12-11 11:41:44 -05:00
|
|
|
|
<pre>template <class EndianReversibleInplace>
|
|
|
|
|
|
void conditional_reverse_inplace(EndianReversibleInplace& x,
|
2014-12-09 20:43:47 -05:00
|
|
|
|
order order1, order order2) noexcept; </pre>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<blockquote>
|
2014-12-10 09:39:03 -05:00
|
|
|
|
<p><i>Effects: </i>If <code>order1 == order2</code> then <code>endian_reverse_inplace(x)</code>.</p>
|
2014-12-09 20:43:47 -05:00
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
2013-05-19 17:08:42 -04:00
|
|
|
|
|
2013-05-28 11:04:03 -04:00
|
|
|
|
<h2> <a name="FAQ">FAQ</a></h2>
|
|
|
|
|
|
|
|
|
|
|
|
<p>See the <a href="index.html#FAQ">Endian home page</a> FAQ for a library-wide
|
|
|
|
|
|
FAQ.</p>
|
|
|
|
|
|
|
|
|
|
|
|
<p><b>Why are both value returning and modify-in-place functions provided?</b></p>
|
|
|
|
|
|
|
|
|
|
|
|
<blockquote>
|
|
|
|
|
|
|
|
|
|
|
|
<p>Returning the result by value is the standard C and C++ idiom for functions that compute a
|
|
|
|
|
|
value from an argument. Modify-in-place functions allow cleaner code in many real-world
|
2014-12-09 20:43:47 -05:00
|
|
|
|
endian use cases and are more efficient for user-defined types that have
|
2013-05-28 11:04:03 -04:00
|
|
|
|
members such as string data that do not need to be reversed. Thus both forms are
|
|
|
|
|
|
provided.</p>
|
|
|
|
|
|
|
|
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
2014-12-16 08:49:01 -05:00
|
|
|
|
<p><b>Why are exact-length 8, 16, 32, and 64-bit integers supported rather than the built-in
|
2014-12-11 12:05:31 -05:00
|
|
|
|
char, short, int, long, long long, etc?</b></p>
|
|
|
|
|
|
|
|
|
|
|
|
<blockquote>
|
|
|
|
|
|
|
|
|
|
|
|
<p>The primary use case, portable file or network data, needs these de facto
|
|
|
|
|
|
standard sizes. Using types that vary with the platform would greatly limit
|
|
|
|
|
|
portability for both programs and data.</p>
|
|
|
|
|
|
|
|
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
2015-07-21 14:44:36 -04:00
|
|
|
|
<p><b>Why not use the Linux names (htobe16, htole16, be16toh, le16toh, etc.) ?</b></p>
|
|
|
|
|
|
|
|
|
|
|
|
<blockquote>
|
|
|
|
|
|
|
|
|
|
|
|
<p>Those names are non-standard and vary even between POSIX-like operating
|
|
|
|
|
|
systems. A C++ library TS was going to use those names, but found they were
|
|
|
|
|
|
sometimes implemented as macros. Since macros do not respect scoping and
|
|
|
|
|
|
namespace rules, to use them would be very error prone.</p>
|
|
|
|
|
|
|
|
|
|
|
|
</blockquote>
|
|
|
|
|
|
|
2015-03-25 08:05:49 -04:00
|
|
|
|
<h2><a name="Acknowledgements">Acknowledgements</a></h2><p>Tomas Puverle was instrumental
|
|
|
|
|
|
in identifying and articulating the need to support endian conversion as separate from
|
|
|
|
|
|
endian integer types. Phil Endecott suggested the form of the value returning signatures.
|
|
|
|
|
|
Vicente Botet and other reviewers suggested supporting user defined types.
|
|
|
|
|
|
General reverse template implementation approach using std::reverse suggested by Mathias Gaunard.
|
|
|
|
|
|
Portable implementation approach for 16, 32, and 64-bit integers suggested by tymofey,
|
|
|
|
|
|
with avoidance of undefined behavior as suggested by Giovanni Piero Deretta,
|
|
|
|
|
|
and a further refinement suggested by Pyry Jahkola.
|
|
|
|
|
|
Intrinsic builtins implementation approach for 16, 32, and 64-bit integers suggested by
|
|
|
|
|
|
several reviewers, and by David Stone, who provided his Boost licensed macro implementation
|
|
|
|
|
|
that became the starting point for <b><code>boost/endian/detail/intrinsic.hpp</code></b>.
|
2014-12-10 08:30:30 -05:00
|
|
|
|
Pierre Talbot provided the <code>int8_t endian_reverse()</code> and templated
|
2014-12-10 09:58:01 -05:00
|
|
|
|
<code>endian_reverse_inplace()</code> implementations.</p>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
<hr>
|
2015-10-16 10:30:34 -04:00
|
|
|
|
<p>Last revised:
|
|
|
|
|
|
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->14 October, 2015<!--webbot bot="Timestamp" endspan i-checksum="38874" --></p>
|
2013-05-28 11:04:03 -04:00
|
|
|
|
<p>© Copyright Beman Dawes, 2011, 2013</p>
|
2013-05-19 08:26:09 -04:00
|
|
|
|
<p>Distributed under the Boost Software License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/ LICENSE_1_0.txt</a></p>
|
2011-05-27 20:18:13 +00:00
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
|
|
|
|
|
|
|
</html>
|