diff --git a/include/boost/endian/converters.hpp b/include/boost/endian/converters.hpp index 1e4d9c7..110de01 100644 --- a/include/boost/endian/converters.hpp +++ b/include/boost/endian/converters.hpp @@ -5,36 +5,21 @@ // Distributed under the Boost Software License, Version 1.0. // http://www.boost.org/LICENSE_1_0.txt -#ifndef BOOST_ENDIAN_CONVERSION2_HPP -#define BOOST_ENDIAN_CONVERSION2_HPP +#ifndef BOOST_ENDIAN_CONVERTERS_HPP +#define BOOST_ENDIAN_CONVERTERS_HPP #include #include #include -//--------------------------------------------------------------------------------------// -// -// This header explores -// -- value returning interface approach suggested by Phil Endecott. -// -- additional reorder overloads for floating point types as requested by Vicente -// Botet and others. -// -- reorder implementation approach suggested by tymofey, with avoidance of -// undefined behavior as suggested by Giovanni Piero Deretta, and a further -// refinement suggested by Pyry Jahkola. -// -- general reorder function template to meet requests for UDT support by -// Vicente Botet and others. -// -- general reorder function template implementation approach using std::reverse -// suggested by Mathias Gaunard -// -//--------------------------------------------------------------------------------------// - //------------------------------------- synopsis ---------------------------------------// namespace boost { -namespace endian2 +namespace endian { // reverse byte order (i.e. endianness) + // value returning interface approach suggested by Phil Endecott. inline int16_t reorder(int16_t x); inline int32_t reorder(int32_t x); @@ -43,6 +28,8 @@ namespace endian2 inline uint32_t reorder(uint32_t x); inline uint64_t reorder(uint64_t x); + // additional reorder overloads for floating point types as requested by Vicente + // Botet and others. // TODO: Need implementation // TODO: Need to verify the return does not invoke undefined behavior (as might happen // if there are unutterable floating point values, such as happens with the unutterable @@ -50,20 +37,23 @@ namespace endian2 inline float reorder(float x); inline double reorder(double x); - // TODO: Would pass by value be better for the following functions? + // general reorder function template to meet requests for UDT support by Vicente + // Botet and others. + template + inline T reorder(T x); template - inline T reorder(const T& x); - - template - inline T big(const T& x); + inline T big(T x); // Return: x if native endianness is big, otherwise reorder(x); template - inline T little(const T& x); + inline T little(T x); // Return: x if native endianness is little, otherwise reorder(x); //----------------------------------- implementation -----------------------------------// +// -- reorder implementation approach suggested by tymofey, with avoidance of +// undefined behavior as suggested by Giovanni Piero Deretta, and a further +// refinement suggested by Pyry Jahkola. inline int16_t reorder(int16_t x) { @@ -116,8 +106,10 @@ namespace endian2 } +// general reorder function template implementation approach using std::reverse +// suggested by Mathias Gaunard template - inline T reorder(const T& x) + inline T reorder(T x) { T tmp; std::reverse( @@ -147,7 +139,7 @@ namespace endian2 # endif } -} // namespace endian2 +} // namespace endian } // namespace boost -#endif // BOOST_ENDIAN_CONVERSION2_HPP +#endif // BOOST_ENDIAN_CONVERTERS_HPP diff --git a/test/converter_test.cpp b/test/converter_test.cpp index d1397c1..8babbc5 100644 --- a/test/converter_test.cpp +++ b/test/converter_test.cpp @@ -9,12 +9,12 @@ #include -#include +#include #include #include #include -namespace be = boost::endian2; +namespace be = boost::endian; namespace { diff --git a/test/msvc10/converter_test/converter_test.vcxproj b/test/msvc10/converter_test/converter_test.vcxproj new file mode 100644 index 0000000..bfd3d1c --- /dev/null +++ b/test/msvc10/converter_test/converter_test.vcxproj @@ -0,0 +1,81 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {EAE18F4D-AAF2-4C19-86FB-1144B5BD5993} + Win32Proj + converter_test + + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + \ No newline at end of file