diff --git a/doc/conversion.html b/doc/conversion.html index ae07043..3e47f40 100644 --- a/doc/conversion.html +++ b/doc/conversion.html @@ -91,23 +91,19 @@ namespace endian enum class order {big, little, native}; // reverse byte order (i.e. endianness) + int8_t reverse_value(int8_t x) noexcept; int16_t reverse_value(int16_t x) noexcept; int32_t reverse_value(int32_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; uint32_t reverse_value(uint32_t x) noexcept; uint64_t reverse_value(uint64_t x) noexcept; float reverse_value(float x) noexcept; double reverse_value(double x) noexcept; - void reverse(int16_t& x) noexcept; - void reverse(int32_t& x) noexcept; - 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; + template <class Value> + void reverse(Value& x) noexcept; // reverse byte order unless native endianness is big template <class ReversibleValue > @@ -203,9 +199,11 @@ udt_conversion_example.cpp for an example of a UDT that can used in the little_endian, and convert function templates.

Functions

-
int16_t  reverse_value(int16_t x) noexcept;
+
int8_t  reverse_value(int8_t x) noexcept;
+int16_t  reverse_value(int16_t x) noexcept;
 int32_t  reverse_value(int32_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;
 uint32_t reverse_value(uint32_t x) noexcept;
 uint64_t reverse_value(uint64_t x) noexcept;
@@ -215,14 +213,8 @@ double   reverse_value(double x) noexcept;

Returns: x, with the order of its constituent bytes reversed.

-
void reverse(int16_t& x) noexcept;
-void reverse(int32_t& x) noexcept;
-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;
+
template <class Value>
+  void     reverse(Value& x) noexcept;

Postconditions: The order of the constituent bytes of x are reversed.

@@ -333,10 +325,12 @@ provided.

Acknowledgements

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 boost/endian/detail/intrinsic.hpp.

+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 boost/endian/detail/intrinsic.hpp. +Pierre Talbot provided the int8_t reverse_value() and templated +reverse() implementations.


Last revised: -29 May, 2013

+16 April, 2014

© Copyright Beman Dawes, 2011, 2013

Distributed under the Boost Software License, Version 1.0. See www.boost.org/ LICENSE_1_0.txt

diff --git a/doc/done_list.html b/doc/done_list.html index 23ccd3d..cba161d 100644 --- a/doc/done_list.html +++ b/doc/done_list.html @@ -16,9 +16,7 @@ 64-bit (double) floating point, as requested.
  • Both the endian types and endian conversion functions now support UDTs, as requested.
  • Both the endian types and endian conversion functions have been renamed, - using a naming pattern that is consistent for both integer and floating point, - and that emphasizes that aligned types are usually preferred compared to - unaligned types which are deliberately given slightly uglier names.
  • + using a naming pattern that is consistent for both integer and floating point.
  • The conversion functions have been much revised, refactored, and otherwise improved based on review comments. diff --git a/doc/index.html b/doc/index.html index 7b7f0b5..265e839 100644 --- a/doc/index.html +++ b/doc/index.html @@ -534,9 +534,7 @@ and 16, 32, and 64-bit aligned integers.

    64-bit (double) floating point, as requested.
  • Both the endian types and endian conversion functions now support UDTs, as requested.
  • The endian type aliases have been renamed, - using a naming pattern that is consistent for both integer and floating point, - and that emphasizes that aligned types are usually preferred compared to - unaligned types. Unaligned types are deliberately given slightly uglier names.
  • + using a naming pattern that is consistent for both integer and floating point.
  • The conversion functions have been much revised, refactored, and otherwise improved based on review comments.

    Acknowledgements

    -

    Comments and suggestions were -received from -Adder, Benaka Moorthi, -Christopher Kohlhoff, -Cliff Green, Daniel James, Gennaro Proto, -Giovanni Piero Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, -John Filo, John Maddock, -Kim Barrett, -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,.

    +

    Comments and suggestions were received from Adder, Benaka Moorthi, +Christopher Kohlhoff, Cliff Green, Daniel James, Gennaro Proto, Giovanni Piero +Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, John Filo, John +Maddock, Kim Barrett, Marsh Ray, Martin Bonner, Mathias Gaunard, Matias +Capeletto, Neil Mayhew, Paul Bristow, Pierre Talbot, 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,.


    Last revised: -01 September, 2013

    +16 April, 2014

    © Copyright Beman Dawes, 2011, 2013

    Distributed under the Boost Software License, Version 1.0. See www.boost.org/ LICENSE_1_0.txt

    diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index b1fb702..4b570e4 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -35,11 +35,11 @@ namespace endian // 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 int32_t reverse_value(int32_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 uint32_t reverse_value(uint32_t x) BOOST_NOEXCEPT; inline uint64_t reverse_value(uint64_t x) BOOST_NOEXCEPT; diff --git a/test/converter_test.cpp b/test/converter_test.cpp index 045f850..38b6111 100644 --- a/test/converter_test.cpp +++ b/test/converter_test.cpp @@ -18,6 +18,8 @@ namespace be = boost::endian; using std::cout; using std::endl; +using boost::int8_t; +using boost::uint8_t; using boost::int16_t; using boost::uint16_t; using boost::int32_t; @@ -29,6 +31,20 @@ namespace { // values for tests + void native_value(int8_t& x) {x = static_cast(0xF0U);} + void native_value(uint8_t& x) {x = static_cast(0xF0U);} +# ifdef BOOST_BIG_ENDIAN + void big_value(int8_t& x) {x = static_cast(0xF0U);} + void big_value(uint8_t& x) {x = static_cast(0xF0U);} + void little_value(int8_t& x) {x = static_cast(0xF0U);} + void little_value(uint8_t& x) {x = static_cast(0xF0U);} +# else + void big_value(int8_t& x) {x = static_cast(0xF0U);} + void big_value(uint8_t& x) {x = static_cast(0xF0U);} + void little_value(int8_t& x) {x = static_cast(0xF0U);} + void little_value(uint8_t& x) {x = static_cast(0xF0U);} +# endif + void native_value(int16_t& x) {x = static_cast(0xF102U);} void native_value(uint16_t& x) {x = static_cast(0xF102U);} # ifdef BOOST_BIG_ENDIAN @@ -243,6 +259,11 @@ int cpp_main(int, char * []) //std::cerr << std::hex; + cout << "int8_t" << endl; + test(); + cout << "uint8_t" << endl; + test(); + cout << "int32_t" << endl; cout << "int16_t" << endl; test(); cout << "uint16_t" << endl;