diff --git a/boost/endian/conversion.hpp b/boost/endian/conversion.hpp index c079e07..907a427 100644 --- a/boost/endian/conversion.hpp +++ b/boost/endian/conversion.hpp @@ -17,25 +17,25 @@ namespace boost { namespace endian { - // unconditional modifying (i.e. in-place) endianness reversal + // unconditional modifying (i.e. in-place) reverse byte order - inline void invert(int16_t& x); - inline void invert(int32_t& x); - inline void invert(int64_t& x); - inline void invert(uint16_t& x); - inline void invert(uint32_t& x); - inline void invert(uint64_t& x); + inline void reorder(int16_t& x); + inline void reorder(int32_t& x); + inline void reorder(int64_t& x); + inline void reorder(uint16_t& x); + inline void reorder(uint32_t& x); + inline void reorder(uint64_t& x); - // unconditional non-modifying endianness reversing copy + // unconditional non-modifying reverse byte order copy - inline void invert(int16_t source, int16_t& target); - inline void invert(int32_t source, int32_t& target); - inline void invert(int64_t source, int64_t& target); - inline void invert(uint16_t source, uint16_t& target); - inline void invert(uint32_t source, uint32_t& target); - inline void invert(uint64_t source, uint64_t& target); + inline void reorder(int16_t source, int16_t& target); + inline void reorder(int32_t source, int32_t& target); + inline void reorder(int64_t source, int64_t& target); + inline void reorder(uint16_t source, uint16_t& target); + inline void reorder(uint32_t source, uint32_t& target); + inline void reorder(uint64_t source, uint64_t& target); - // conditional modifying (i.e. in-place) endianness reversal; + // conditional modifying (i.e. in-place) reverse byte order; // no effect if native endianness and indicated endianness are the same template inline void native_to_big(T& x); @@ -43,7 +43,7 @@ namespace endian template inline void big_to_native(T& x); template inline void little_to_native(T& x); - // non-modifying copy conditionally reversing endianness; + // non-modifying conditional reverse byte order copy; // copy the source argument to the target argument, converting to or from the // indicated endianness if different than native endianness @@ -54,7 +54,7 @@ namespace endian //----------------------------------- implementation -----------------------------------// - inline void invert(int16_t& x) + inline void reorder(int16_t& x) { char* rep = reinterpret_cast(&x); char tmp; @@ -63,7 +63,7 @@ namespace endian *(rep+1) = tmp; } - inline void invert(int32_t& x) + inline void reorder(int32_t& x) { char* rep = reinterpret_cast(&x); char tmp; @@ -75,7 +75,7 @@ namespace endian *(rep+2) = tmp; } - inline void invert(int64_t& x) + inline void reorder(int64_t& x) { char* rep = reinterpret_cast(&x); char tmp; @@ -93,7 +93,7 @@ namespace endian *(rep+4) = tmp; } - inline void invert(uint16_t& x) + inline void reorder(uint16_t& x) { char* rep = reinterpret_cast(&x); char tmp; @@ -102,7 +102,7 @@ namespace endian *(rep+1) = tmp; } - inline void invert(uint32_t& x) + inline void reorder(uint32_t& x) { char* rep = reinterpret_cast(&x); char tmp; @@ -114,7 +114,7 @@ namespace endian *(rep+2) = tmp; } - inline void invert(uint64_t& x) + inline void reorder(uint64_t& x) { char* rep = reinterpret_cast(&x); char tmp; @@ -132,7 +132,7 @@ namespace endian *(rep+4) = tmp; } - inline void invert(int16_t source, int16_t& target) + inline void reorder(int16_t source, int16_t& target) { const char* s (reinterpret_cast(&source)); char * t (reinterpret_cast(&target) + sizeof(target) - 1); @@ -140,7 +140,7 @@ namespace endian *--t = *++s; } - inline void invert(int32_t source, int32_t& target) + inline void reorder(int32_t source, int32_t& target) { const char* s (reinterpret_cast(&source)); char * t (reinterpret_cast(&target) + sizeof(target) - 1); @@ -150,7 +150,7 @@ namespace endian *--t = *++s; } - inline void invert(int64_t source, int64_t& target) + inline void reorder(int64_t source, int64_t& target) { const char* s (reinterpret_cast(&source)); char * t (reinterpret_cast(&target) + sizeof(target) - 1); @@ -164,7 +164,7 @@ namespace endian *--t = *++s; } - inline void invert(uint16_t source, uint16_t& target) + inline void reorder(uint16_t source, uint16_t& target) { const char* s (reinterpret_cast(&source)); char * t (reinterpret_cast(&target) + sizeof(target) - 1); @@ -172,7 +172,7 @@ namespace endian *--t = *++s; } - inline void invert(uint32_t source, uint32_t& target) + inline void reorder(uint32_t source, uint32_t& target) { const char* s (reinterpret_cast(&source)); char * t (reinterpret_cast(&target) + sizeof(target) - 1); @@ -182,7 +182,7 @@ namespace endian *--t = *++s; } - inline void invert(uint64_t source, uint64_t& target) + inline void reorder(uint64_t source, uint64_t& target) { const char* s (reinterpret_cast(&source)); char * t (reinterpret_cast(&target) + sizeof(target) - 1); @@ -197,23 +197,23 @@ namespace endian } #ifdef BOOST_LITTLE_ENDIAN - template inline void native_to_big(T& x) { invert(x); } + template inline void native_to_big(T& x) { reorder(x); } template inline void native_to_little(T&) {} - template inline void big_to_native(T& x) { invert(x); } + template inline void big_to_native(T& x) { reorder(x); } template inline void little_to_native(T&) {} - template inline void native_to_big(T source, T& target) { invert(source, target); } + template inline void native_to_big(T source, T& target) { reorder(source, target); } template inline void native_to_little(T source, T& target) { target = source; } - template inline void big_to_native(T source, T& target) { invert(source, target); } + template inline void big_to_native(T source, T& target) { reorder(source, target); } template inline void little_to_native(T source, T& target) { target = source; } #else template inline void native_to_big(T&) {} - template inline void native_to_little(T& x) { invert(x); } + template inline void native_to_little(T& x) { reorder(x); } template inline void big_to_native(T&) {} - template inline void little_to_native(T& x) { invert(x); } + template inline void little_to_native(T& x) { reorder(x); } template inline void native_to_big(T native, T& big) { target = source; } - template inline void native_to_little(T native, T& little) { invert(source, target); } + template inline void native_to_little(T native, T& little) { reorder(source, target); } template inline void big_to_native(T big, T& native) { target = source; } - template inline void little_to_native(T little, T& native) { invert(source, target); } + template inline void little_to_native(T little, T& native) { reorder(source, target); } #endif } // namespace endian diff --git a/libs/endian/doc/conversion.html b/libs/endian/doc/conversion.html index acd1071..9cf54b3 100644 --- a/libs/endian/doc/conversion.html +++ b/libs/endian/doc/conversion.html @@ -46,34 +46,32 @@ ordering.

{ namespace endian { - // invert: verb: put upside down or in the opposite position, order, or arrangement. + // unconditional modifying (i.e. in-place) reverse byte order - // unconditional modifying (i.e. in-place) endianness reversal + inline void reorder(int16_t& x); + inline void reorder(int32_t& x); + inline void reorder(int64_t& x); + inline void reorder(uint16_t& x); + inline void reorder(uint32_t& x); + inline void reorder(uint64_t& x); - inline void invert(int16_t& x); - inline void invert(int32_t& x); - inline void invert(int64_t& x); - inline void invert(uint16_t& x); - inline void invert(uint32_t& x); - inline void invert(uint64_t& x); + // unconditional non-modifying reverse byte order copy - // unconditional non-modifying endianness reversing copy + inline void reorder(int16_t source, int16_t& target); + inline void reorder(int32_t source, int32_t& target); + inline void reorder(int64_t source, int64_t& target); + inline void reorder(uint16_t source, uint16_t& target); + inline void reorder(uint32_t source, uint32_t& target); + inline void reorder(uint64_t source, uint64_t& target); - inline void invert(int16_t source, int16_t& target); - inline void invert(int32_t source, int32_t& target); - inline void invert(int64_t source, int64_t& target); - inline void invert(uint16_t source, uint16_t& target); - inline void invert(uint32_t source, uint32_t& target); - inline void invert(uint64_t source, uint64_t& target); - - // conditional modifying (i.e. in-place) endianness reversal + // conditional modifying (i.e. in-place) reverse byte order template <class T> void native_to_big(T& x); template <class T> void native_to_little(T& x); template <class T> void big_to_native(T& x); template <class T> void little_to_native(T& x); - // non-modifying copy conditionally reversing endianness; + // non-modifying conditional reverse byte order copy template <class T> void native_to_big(T source, T& target); template <class T> void native_to_little(T source, T& target); @@ -83,21 +81,21 @@ namespace endian } // namespace endian } // namespace boost

Members

-
inline void invert(int16_t& x);
-inline void invert(int32_t& x);
-inline void invert(int64_t& x);
-inline void invert(uint16_t& x);
-inline void invert(uint32_t& x);
-inline void invert(uint64_t& x);
+
inline void reorder(int16_t& x);
+inline void reorder(int32_t& x);
+inline void reorder(int64_t& x);
+inline void reorder(uint16_t& x);
+inline void reorder(uint32_t& x);
+inline void reorder(uint64_t& x);

Effects: Reverses the byte order of x.

-
inline void invert(int16_t source, int16_t& target);
-inline void invert(int32_t source, int32_t& target);
-inline void invert(int64_t source, int64_t& target);
-inline void invert(uint16_t source, uint16_t& target);
-inline void invert(uint32_t source, uint32_t& target);
-inline void invert(uint64_t source, uint64_t& target);
+
inline void reorder(int16_t source, int16_t& target);
+inline void reorder(int32_t source, int32_t& target);
+inline void reorder(int64_t source, int64_t& target);
+inline void reorder(uint16_t source, uint16_t& target);
+inline void reorder(uint32_t source, uint32_t& target);
+inline void reorder(uint64_t source, uint64_t& target);

Effects: Copies source to target, reversing the byte order.

@@ -108,7 +106,7 @@ template <class T> void big_to_native(T& x); template <class T> void little_to_native(T& x);

Effects: If the native byte ordering and indicated byte - ordering are different, invert(x), otherwise no effect.

+ ordering are different, reorder(x), otherwise no effect.

template <class T> void native_to_big(T source, T& target);
 template <class T> void native_to_little(T source, T& target);
@@ -116,7 +114,7 @@ template <class T> void big_to_native(T source, T& target);
 template <class T> void little_to_native(T source, T& target);

Effects: If the native byte ordering and indicated byte - ordering are different, invert(source, target), otherwise + ordering are different, reorder(source, target), otherwise target = source.

Acknowledgements

diff --git a/libs/endian/example/endian_example.cpp b/libs/endian/example/endian_example.cpp index b252434..8fc7f36 100644 --- a/libs/endian/example/endian_example.cpp +++ b/libs/endian/example/endian_example.cpp @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include using namespace boost::endian; @@ -41,14 +41,14 @@ namespace int cpp_main(int, char * []) { - BOOST_TEST_EQ( sizeof( header ), 16U ); // requirement for interoperability + BOOST_STATIC_ASSERT( sizeof( header ) == 16U ); // requirement for interoperability header h; - h.file_code = 0x04030201; + h.file_code = 0x01020304; h.file_length = sizeof( header ); h.version = -1; - h.shape_type = 0x04030201; + h.shape_type = 0x01020304; // Low-level I/O such as POSIX read/write or fread/fwrite is sometimes // used for binary file operations when ultimate efficiency is important. @@ -74,5 +74,5 @@ int cpp_main(int, char * []) std::cout << "created file " << filename << '\n'; - return ::boost::report_errors(); + return 0; } diff --git a/libs/endian/test/conversion_test.cpp b/libs/endian/test/conversion_test.cpp index b824562..096c4e4 100644 --- a/libs/endian/test/conversion_test.cpp +++ b/libs/endian/test/conversion_test.cpp @@ -19,127 +19,127 @@ namespace be = boost::endian; namespace { - void test_in_place_invert() + void test_in_place_reorder() { - std::cout << "test_in_place_invert...\n"; + std::cout << "test_in_place_reorder...\n"; boost::int64_t i64 = 0x0102030405060708LL; - be::invert(i64); + be::reorder(i64); BOOST_TEST_EQ(i64, 0x0807060504030201LL); - be::invert(i64); + be::reorder(i64); BOOST_TEST_EQ(i64, 0x0102030405060708LL); i64 = 0xfefdfcfbfaf9f8f7LL; - be::invert(i64); + be::reorder(i64); BOOST_TEST_EQ(i64, static_cast(0xf7f8f9fafbfcfdfeULL)); - be::invert(i64); + be::reorder(i64); BOOST_TEST_EQ(i64, static_cast(0xfefdfcfbfaf9f8f7ULL)); boost::int32_t i32 = 0x01020304; - be::invert(i32); + be::reorder(i32); BOOST_TEST_EQ(i32, 0x04030201); - be::invert(i32); + be::reorder(i32); BOOST_TEST_EQ(i32, 0x01020304); i32 = 0xfefdfcfb; - be::invert(i32); + be::reorder(i32); BOOST_TEST_EQ(i32, static_cast(0xfbfcfdfe)); - be::invert(i32); + be::reorder(i32); BOOST_TEST_EQ(i32, static_cast(0xfefdfcfb)); boost::int16_t i16 = 0x0102; - be::invert(i16); + be::reorder(i16); BOOST_TEST_EQ(i16, 0x0201); - be::invert(i16); + be::reorder(i16); BOOST_TEST_EQ(i16, 0x0102); i16 = static_cast(static_cast(0xfefd)); - be::invert(i16); + be::reorder(i16); BOOST_TEST_EQ(i16, static_cast(static_cast(0xfdfe))); - be::invert(i16); + be::reorder(i16); BOOST_TEST_EQ(i16, static_cast(static_cast(0xfefd))); boost::uint64_t ui64 = 0x0102030405060708ULL; - be::invert(ui64); + be::reorder(ui64); BOOST_TEST_EQ(ui64, 0x0807060504030201ULL); - be::invert(ui64); + be::reorder(ui64); BOOST_TEST_EQ(ui64, 0x0102030405060708ULL); boost::uint32_t ui32 = 0x01020304; - be::invert(ui32); + be::reorder(ui32); BOOST_TEST_EQ(ui32, static_cast(0x04030201)); - be::invert(ui32); + be::reorder(ui32); BOOST_TEST_EQ(ui32, static_cast(0x01020304)); boost::uint16_t ui16 = 0x0102; - be::invert(ui16); + be::reorder(ui16); BOOST_TEST_EQ(ui16, 0x0201); - be::invert(ui16); + be::reorder(ui16); BOOST_TEST_EQ(ui16, static_cast(0x0102)); - std::cout << " test_in_place_invert complete\n"; + std::cout << " test_in_place_reorder complete\n"; } - void test_copying_invert() + void test_copying_reorder() { - std::cout << "test_copying_invert...\n"; + std::cout << "test_copying_reorder...\n"; boost::int64_t i64 = 0x0102030405060708LL, j64, k64; - be::invert(i64, j64); + be::reorder(i64, j64); BOOST_TEST_EQ(j64, 0x0807060504030201LL); BOOST_TEST_EQ(i64, 0x0102030405060708LL); - be::invert(j64, k64); + be::reorder(j64, k64); BOOST_TEST_EQ(k64, 0x0102030405060708LL); i64 = 0xfefdfcfbfaf9f8f7LL; - be::invert(i64, j64); + be::reorder(i64, j64); BOOST_TEST_EQ(j64, static_cast(0xf7f8f9fafbfcfdfeLL)); - be::invert(j64, k64); + be::reorder(j64, k64); BOOST_TEST_EQ(k64, static_cast(0xfefdfcfbfaf9f8f7LL)); boost::int32_t i32 = 0x01020304, j32, k32; - be::invert(i32, j32); + be::reorder(i32, j32); BOOST_TEST_EQ(j32, 0x04030201); - be::invert(j32, k32); + be::reorder(j32, k32); BOOST_TEST_EQ(k32, 0x01020304); i32 = 0xfefdfcfb; - be::invert(i32, j32); + be::reorder(i32, j32); BOOST_TEST_EQ(j32, static_cast(0xfbfcfdfe)); - be::invert(j32, k32); + be::reorder(j32, k32); BOOST_TEST_EQ(k32, static_cast(0xfefdfcfb)); boost::int16_t i16 = 0x0102, j16, k16; - be::invert(i16, j16); + be::reorder(i16, j16); BOOST_TEST_EQ(j16, 0x0201); - be::invert(j16, k16); + be::reorder(j16, k16); BOOST_TEST_EQ(k16, 0x0102); i16 = static_cast(static_cast(0xfefd)); - be::invert(i16, j16); + be::reorder(i16, j16); BOOST_TEST_EQ(j16, static_cast(static_cast(0xfdfe))); - be::invert(j16, k16); + be::reorder(j16, k16); BOOST_TEST_EQ(k16, static_cast(static_cast(0xfefd))); boost::uint64_t ui64 = 0x0102030405060708ULL, uj64, uk64; - be::invert(ui64, uj64); + be::reorder(ui64, uj64); BOOST_TEST_EQ(uj64, 0x0807060504030201ULL); - be::invert(uj64, uk64); + be::reorder(uj64, uk64); BOOST_TEST_EQ(uk64, 0x0102030405060708ULL); boost::uint32_t ui32 = 0x01020304, uj32, uk32; - be::invert(ui32, uj32); + be::reorder(ui32, uj32); BOOST_TEST_EQ(uj32, static_cast(0x04030201)); - be::invert(uj32, uk32); + be::reorder(uj32, uk32); BOOST_TEST_EQ(uk32, static_cast(0x01020304)); boost::uint16_t ui16 = 0x0102, uj16, uk16; - be::invert(ui16, uj16); + be::reorder(ui16, uj16); BOOST_TEST_EQ(uj16, 0x0201); - be::invert(uj16, uk16); + be::reorder(uj16, uk16); BOOST_TEST_EQ(uk16, 0x0102); - std::cout << " test_copying_invert complete\n"; + std::cout << " test_copying_reorder complete\n"; } const boost::int64_t ni64 = 0x0102030405060708LL; @@ -196,9 +196,9 @@ namespace const boost::uint16_t lui16 = 0x0102; # endif - void test_in_place_conditional_invert() + void test_in_place_conditional_reorder() { - std::cout << "test_in_place_conditional_invert...\n"; + std::cout << "test_in_place_conditional_reorder...\n"; boost::int64_t i64; @@ -308,12 +308,12 @@ namespace be::little_to_native(ui16); BOOST_TEST_EQ(ui16, nui16); - std::cout << " test_in_place_conditional_invert complete\n"; + std::cout << " test_in_place_conditional_reorder complete\n"; } - void test_copying_conditional_invert() + void test_copying_conditional_reorder() { - std::cout << "test_copying_conditional_invert...\n"; + std::cout << "test_copying_conditional_reorder...\n"; boost::int64_t i64, ti64; @@ -423,7 +423,7 @@ namespace be::little_to_native(ui16, tui16); BOOST_TEST_EQ(tui16, nui16); - std::cout << " test_copying_conditional_invert complete\n"; + std::cout << " test_copying_conditional_reorder complete\n"; } } // unnamed namespace @@ -431,10 +431,10 @@ namespace int cpp_main(int, char * []) { std::cerr << std::hex; - test_in_place_invert(); - test_copying_invert(); - test_in_place_conditional_invert(); - test_copying_conditional_invert(); + test_in_place_reorder(); + test_copying_reorder(); + test_in_place_conditional_reorder(); + test_copying_conditional_reorder(); return ::boost::report_errors(); }