mirror of
https://github.com/boostorg/endian.git
synced 2025-08-01 21:44:31 +02:00
Test and doc updates for Pierre Talbot's int8_t/uint8_t reverse_value() and templated reverse() patch.
This commit is contained in:
@@ -91,23 +91,19 @@ namespace endian
|
|||||||
enum class <a name="order">order</a> {big, little, native};
|
enum class <a name="order">order</a> {big, little, native};
|
||||||
|
|
||||||
// reverse byte order (i.e. endianness)
|
// reverse byte order (i.e. endianness)
|
||||||
|
int8_t <a href="#reverse_value">reverse_value</a>(int8_t x) noexcept;
|
||||||
int16_t <a href="#reverse_value">reverse_value</a>(int16_t x) noexcept;
|
int16_t <a href="#reverse_value">reverse_value</a>(int16_t x) noexcept;
|
||||||
int32_t <a href="#reverse_value">reverse_value</a>(int32_t x) noexcept;
|
int32_t <a href="#reverse_value">reverse_value</a>(int32_t x) noexcept;
|
||||||
int64_t <a href="#reverse_value">reverse_value</a>(int64_t x) noexcept;
|
int64_t <a href="#reverse_value">reverse_value</a>(int64_t x) noexcept;
|
||||||
|
uint8_t <a href="#reverse_value">reverse_value</a>(uint8_t x) noexcept;
|
||||||
uint16_t <a href="#reverse_value">reverse_value</a>(uint16_t x) noexcept;
|
uint16_t <a href="#reverse_value">reverse_value</a>(uint16_t x) noexcept;
|
||||||
uint32_t <a href="#reverse_value">reverse_value</a>(uint32_t x) noexcept;
|
uint32_t <a href="#reverse_value">reverse_value</a>(uint32_t x) noexcept;
|
||||||
uint64_t <a href="#reverse_value">reverse_value</a>(uint64_t x) noexcept;
|
uint64_t <a href="#reverse_value">reverse_value</a>(uint64_t x) noexcept;
|
||||||
float <a href="#reverse_value">reverse_value</a>(float x) noexcept;
|
float <a href="#reverse_value">reverse_value</a>(float x) noexcept;
|
||||||
double <a href="#reverse_value">reverse_value</a>(double x) noexcept;
|
double <a href="#reverse_value">reverse_value</a>(double x) noexcept;
|
||||||
|
|
||||||
void <a href="#reverse">reverse</a>(int16_t& x) noexcept;
|
template <class Value>
|
||||||
void <a href="#reverse">reverse</a>(int32_t& x) noexcept;
|
void <a href="#reverse">reverse</a>(Value& x) noexcept;
|
||||||
void <a href="#reverse">reverse</a>(int64_t& x) noexcept;
|
|
||||||
void <a href="#reverse">reverse</a>(uint16_t& x) noexcept;
|
|
||||||
void <a href="#reverse">reverse</a>(uint32_t& x) noexcept;
|
|
||||||
void <a href="#reverse">reverse</a>(uint64_t& x) noexcept;
|
|
||||||
void <a href="#reverse">reverse</a>(float& x) noexcept;
|
|
||||||
void <a href="#reverse">reverse</a>(double& x) noexcept;
|
|
||||||
|
|
||||||
// reverse byte order unless native endianness is big
|
// reverse byte order unless native endianness is big
|
||||||
template <class ReversibleValue >
|
template <class ReversibleValue >
|
||||||
@@ -203,9 +199,11 @@ udt_conversion_example.cpp</a> for an example of a UDT that can used in the
|
|||||||
<a href="#little_endian">little_endian</a></code>, and <code>
|
<a href="#little_endian">little_endian</a></code>, and <code>
|
||||||
<a href="#convert_generic">convert</a></code> function templates.</p>
|
<a href="#convert_generic">convert</a></code> function templates.</p>
|
||||||
<h3><a name="Functions">Functions</a></h3>
|
<h3><a name="Functions">Functions</a></h3>
|
||||||
<pre><a name="reverse_value"></a>int16_t reverse_value(int16_t x) noexcept;
|
<pre><a name="reverse_value"></a>int8_t reverse_value(int8_t x) noexcept;
|
||||||
|
int16_t reverse_value(int16_t x) noexcept;
|
||||||
int32_t reverse_value(int32_t x) noexcept;
|
int32_t reverse_value(int32_t x) noexcept;
|
||||||
int64_t reverse_value(int64_t x) noexcept;
|
int64_t reverse_value(int64_t x) noexcept;
|
||||||
|
uint8_t reverse_value(uint8_t x) noexcept;
|
||||||
uint16_t reverse_value(uint16_t x) noexcept;
|
uint16_t reverse_value(uint16_t x) noexcept;
|
||||||
uint32_t reverse_value(uint32_t x) noexcept;
|
uint32_t reverse_value(uint32_t x) noexcept;
|
||||||
uint64_t reverse_value(uint64_t x) noexcept;
|
uint64_t reverse_value(uint64_t x) noexcept;
|
||||||
@@ -215,14 +213,8 @@ double reverse_value(double x) noexcept;</pre>
|
|||||||
<p><i>Returns:</i> <i><code>x</code></i>, with the order of its
|
<p><i>Returns:</i> <i><code>x</code></i>, with the order of its
|
||||||
constituent bytes reversed.</p>
|
constituent bytes reversed.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<pre><a name="reverse"></a>void reverse(int16_t& x) noexcept;
|
<pre><a name="reverse"></a>template <class Value>
|
||||||
void reverse(int32_t& x) noexcept;
|
void reverse(Value& x) noexcept;</pre>
|
||||||
void reverse(int64_t& x) noexcept;
|
|
||||||
void reverse(uint16_t& x) noexcept;
|
|
||||||
void reverse(uint32_t& x) noexcept;
|
|
||||||
void reverse(uint64_t& x) noexcept;
|
|
||||||
void reverse(float& x) noexcept;
|
|
||||||
void reverse(double& x) noexcept;</pre>
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p><i>Postconditions:</i> The order of the constituent bytes of
|
<p><i>Postconditions:</i> The order of the constituent bytes of
|
||||||
<code>x</code> are reversed.</p>
|
<code>x</code> are reversed.</p>
|
||||||
@@ -333,10 +325,12 @@ provided.</p>
|
|||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
<h2><a name="Acknowledgements">Acknowledgements</a></h2><p>Tomas Puverle was instrumental in identifying and articulating the need to
|
<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 floating point types and 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 <a href="../include/boost/endian/detail/intrinsic.hpp">boost/endian/detail/intrinsic.hpp</a>.</p>
|
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 floating point types and 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 <a href="../include/boost/endian/detail/intrinsic.hpp">boost/endian/detail/intrinsic.hpp</a>.
|
||||||
|
Pierre Talbot provided the <code>int8_t reverse_value()</code> and templated
|
||||||
|
<code>reverse()</code> implementations.</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Last revised:
|
<p>Last revised:
|
||||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->29 May, 2013<!--webbot bot="Timestamp" endspan i-checksum="13994" --></p>
|
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->16 April, 2014<!--webbot bot="Timestamp" endspan i-checksum="29929" --></p>
|
||||||
<p>© Copyright Beman Dawes, 2011, 2013</p>
|
<p>© Copyright Beman Dawes, 2011, 2013</p>
|
||||||
<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>
|
<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>
|
||||||
|
|
||||||
|
@@ -16,9 +16,7 @@
|
|||||||
64-bit <code>(double)</code> floating point, as requested.</li>
|
64-bit <code>(double)</code> floating point, as requested.</li>
|
||||||
<li>Both the endian types and endian conversion functions now support UDTs, as requested.</li>
|
<li>Both the endian types and endian conversion functions now support UDTs, as requested.</li>
|
||||||
<li>Both the endian types and endian conversion functions have been renamed,
|
<li>Both the endian types and endian conversion functions have been renamed,
|
||||||
using a naming pattern that is consistent for both integer and floating point,
|
using a naming pattern that is consistent for both integer and floating point.</li>
|
||||||
and that emphasizes that aligned types are usually preferred compared to
|
|
||||||
unaligned types which are deliberately given slightly uglier names.</li>
|
|
||||||
<li>The conversion functions have been much revised,
|
<li>The conversion functions have been much revised,
|
||||||
refactored, and otherwise improved based on review comments.<ul>
|
refactored, and otherwise improved based on review comments.<ul>
|
||||||
<li>Both return-by-value and modify-in-place interfaces are provided, as
|
<li>Both return-by-value and modify-in-place interfaces are provided, as
|
||||||
@@ -43,6 +41,10 @@
|
|||||||
<li>Acknowledgements have been updated.</li>
|
<li>Acknowledgements have been updated.</li>
|
||||||
<li>Headers have been reorganized to make them easier to read,
|
<li>Headers have been reorganized to make them easier to read,
|
||||||
with a synopsis at the front and implementation following, as requested.</li>
|
with a synopsis at the front and implementation following, as requested.</li>
|
||||||
|
<li><code>reverse_value()</code> overloads for <code>int8_t</code> and <code>
|
||||||
|
uint8_t</code> have been added for improved generality. (Pierre Talbot)</li>
|
||||||
|
<li>Overloads of <code>reverse()</code> have been replaced with a single <code>
|
||||||
|
reverse()</code> template. (Pierre Talbot)</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@@ -534,9 +534,7 @@ and 16, 32, and 64-bit aligned integers.</p>
|
|||||||
64-bit <code>(double)</code> floating point, as requested.</li>
|
64-bit <code>(double)</code> floating point, as requested.</li>
|
||||||
<li>Both the endian types and endian conversion functions now support UDTs, as requested.</li>
|
<li>Both the endian types and endian conversion functions now support UDTs, as requested.</li>
|
||||||
<li>The endian type aliases have been renamed,
|
<li>The endian type aliases have been renamed,
|
||||||
using a naming pattern that is consistent for both integer and floating point,
|
using a naming pattern that is consistent for both integer and floating point.</li>
|
||||||
and that emphasizes that aligned types are usually preferred compared to
|
|
||||||
unaligned types. Unaligned types are deliberately given slightly uglier names.</li>
|
|
||||||
<li>The conversion functions have been much revised,
|
<li>The conversion functions have been much revised,
|
||||||
refactored, and otherwise improved based on review comments.<ul>
|
refactored, and otherwise improved based on review comments.<ul>
|
||||||
<li>Functions have been renamed to clarify their functionality.</li>
|
<li>Functions have been renamed to clarify their functionality.</li>
|
||||||
@@ -565,24 +563,17 @@ and 16, 32, and 64-bit aligned integers.</p>
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
|
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
|
||||||
<p>Comments and suggestions were
|
<p>Comments and suggestions were received from Adder, Benaka Moorthi,
|
||||||
received from
|
Christopher Kohlhoff, Cliff Green, Daniel James, Gennaro Proto, Giovanni Piero
|
||||||
Adder, Benaka Moorthi,
|
Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, John Filo, John
|
||||||
Christopher Kohlhoff,
|
Maddock, Kim Barrett, Marsh Ray, Martin Bonner, Mathias Gaunard, Matias
|
||||||
Cliff Green, Daniel James, Gennaro Proto,
|
Capeletto, Neil Mayhew, Paul Bristow, Pierre Talbot, Phil Endecott, Pyry Jahkola,
|
||||||
Giovanni Piero Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn,
|
Rene Rivera, Robert Stewart, Roland Schwarz, Scott McMurray, Sebastian Redl, Tim
|
||||||
John Filo, John Maddock,
|
Blechmann, Tim Moore, tymofey, Tomas Puverle, Vincente Botet, Yuval Ronen and
|
||||||
Kim Barrett,
|
Vitaly Budovski,.</p>
|
||||||
Marsh Ray,
|
|
||||||
Martin Bonner, Mathias Gaunard, Matias Capeletto,
|
|
||||||
Neil Mayhew, Paul Bristow, Phil Endecott, Pyry Jahkola, Rene Rivera,
|
|
||||||
Robert Stewart, Roland Schwarz, Scott McMurray,
|
|
||||||
Sebastian Redl,
|
|
||||||
Tim Blechmann, Tim Moore, tymofey, Tomas Puverle, Vincente Botet, Yuval Ronen
|
|
||||||
and Vitaly Budovski,.</p>
|
|
||||||
<hr>
|
<hr>
|
||||||
<p>Last revised:
|
<p>Last revised:
|
||||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->01 September, 2013<!--webbot bot="Timestamp" endspan i-checksum="39334" --></p>
|
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->16 April, 2014<!--webbot bot="Timestamp" endspan i-checksum="29929" --></p>
|
||||||
<p>© Copyright Beman Dawes, 2011, 2013</p>
|
<p>© Copyright Beman Dawes, 2011, 2013</p>
|
||||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
<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>
|
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/ LICENSE_1_0.txt</a></p>
|
||||||
|
@@ -35,11 +35,11 @@ namespace endian
|
|||||||
|
|
||||||
// reverse byte order (i.e. endianness)
|
// reverse byte order (i.e. endianness)
|
||||||
//
|
//
|
||||||
inline int8_t reverse_value(int8_t x) BOOST_NOEXCEPT;
|
inline int8_t reverse_value(int8_t x) BOOST_NOEXCEPT;
|
||||||
inline int16_t reverse_value(int16_t x) BOOST_NOEXCEPT;
|
inline int16_t reverse_value(int16_t x) BOOST_NOEXCEPT;
|
||||||
inline int32_t reverse_value(int32_t x) BOOST_NOEXCEPT;
|
inline int32_t reverse_value(int32_t x) BOOST_NOEXCEPT;
|
||||||
inline int64_t reverse_value(int64_t x) BOOST_NOEXCEPT;
|
inline int64_t reverse_value(int64_t x) BOOST_NOEXCEPT;
|
||||||
inline uint8_t reverse_value(uint8_t x) BOOST_NOEXCEPT;
|
inline uint8_t reverse_value(uint8_t x) BOOST_NOEXCEPT;
|
||||||
inline uint16_t reverse_value(uint16_t x) BOOST_NOEXCEPT;
|
inline uint16_t reverse_value(uint16_t x) BOOST_NOEXCEPT;
|
||||||
inline uint32_t reverse_value(uint32_t x) BOOST_NOEXCEPT;
|
inline uint32_t reverse_value(uint32_t x) BOOST_NOEXCEPT;
|
||||||
inline uint64_t reverse_value(uint64_t x) BOOST_NOEXCEPT;
|
inline uint64_t reverse_value(uint64_t x) BOOST_NOEXCEPT;
|
||||||
|
@@ -18,6 +18,8 @@
|
|||||||
namespace be = boost::endian;
|
namespace be = boost::endian;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
using boost::int8_t;
|
||||||
|
using boost::uint8_t;
|
||||||
using boost::int16_t;
|
using boost::int16_t;
|
||||||
using boost::uint16_t;
|
using boost::uint16_t;
|
||||||
using boost::int32_t;
|
using boost::int32_t;
|
||||||
@@ -29,6 +31,20 @@ namespace
|
|||||||
{
|
{
|
||||||
// values for tests
|
// values for tests
|
||||||
|
|
||||||
|
void native_value(int8_t& x) {x = static_cast<int8_t>(0xF0U);}
|
||||||
|
void native_value(uint8_t& x) {x = static_cast<uint8_t>(0xF0U);}
|
||||||
|
# ifdef BOOST_BIG_ENDIAN
|
||||||
|
void big_value(int8_t& x) {x = static_cast<int8_t>(0xF0U);}
|
||||||
|
void big_value(uint8_t& x) {x = static_cast<uint8_t>(0xF0U);}
|
||||||
|
void little_value(int8_t& x) {x = static_cast<int8_t>(0xF0U);}
|
||||||
|
void little_value(uint8_t& x) {x = static_cast<uint8_t>(0xF0U);}
|
||||||
|
# else
|
||||||
|
void big_value(int8_t& x) {x = static_cast<int8_t>(0xF0U);}
|
||||||
|
void big_value(uint8_t& x) {x = static_cast<uint8_t>(0xF0U);}
|
||||||
|
void little_value(int8_t& x) {x = static_cast<int8_t>(0xF0U);}
|
||||||
|
void little_value(uint8_t& x) {x = static_cast<uint8_t>(0xF0U);}
|
||||||
|
# endif
|
||||||
|
|
||||||
void native_value(int16_t& x) {x = static_cast<int16_t>(0xF102U);}
|
void native_value(int16_t& x) {x = static_cast<int16_t>(0xF102U);}
|
||||||
void native_value(uint16_t& x) {x = static_cast<uint16_t>(0xF102U);}
|
void native_value(uint16_t& x) {x = static_cast<uint16_t>(0xF102U);}
|
||||||
# ifdef BOOST_BIG_ENDIAN
|
# ifdef BOOST_BIG_ENDIAN
|
||||||
@@ -243,6 +259,11 @@ int cpp_main(int, char * [])
|
|||||||
|
|
||||||
//std::cerr << std::hex;
|
//std::cerr << std::hex;
|
||||||
|
|
||||||
|
cout << "int8_t" << endl;
|
||||||
|
test<int8_t>();
|
||||||
|
cout << "uint8_t" << endl;
|
||||||
|
test<uint8_t>();
|
||||||
|
cout << "int32_t" << endl;
|
||||||
cout << "int16_t" << endl;
|
cout << "int16_t" << endl;
|
||||||
test<int16_t>();
|
test<int16_t>();
|
||||||
cout << "uint16_t" << endl;
|
cout << "uint16_t" << endl;
|
||||||
|
Reference in New Issue
Block a user