|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74215 - in sandbox/endian: boost/endian libs/endian/doc libs/endian/example libs/endian/test
From: bdawes_at_[hidden]
Date: 2011-09-03 16:42:29
Author: bemandawes
Date: 2011-09-03 16:42:28 EDT (Sat, 03 Sep 2011)
New Revision: 74215
URL: http://svn.boost.org/trac/boost/changeset/74215
Log:
Ha! Replace invert() with reorder(). That finally feels right.
Text files modified:
sandbox/endian/boost/endian/conversion.hpp | 76 ++++++++++++++--------------
sandbox/endian/libs/endian/doc/conversion.html | 66 ++++++++++++-------------
sandbox/endian/libs/endian/example/endian_example.cpp | 10 +-
sandbox/endian/libs/endian/test/conversion_test.cpp | 104 ++++++++++++++++++++--------------------
4 files changed, 127 insertions(+), 129 deletions(-)
Modified: sandbox/endian/boost/endian/conversion.hpp
==============================================================================
--- sandbox/endian/boost/endian/conversion.hpp (original)
+++ sandbox/endian/boost/endian/conversion.hpp 2011-09-03 16:42:28 EDT (Sat, 03 Sep 2011)
@@ -17,25 +17,25 @@
{
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);
-
- // unconditional non-modifying endianness reversing 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& 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 reverse byte order 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);
- // 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 <class T> inline void native_to_big(T& x);
@@ -43,7 +43,7 @@
template <class T> inline void big_to_native(T& x);
template <class T> 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 @@
//----------------------------------- implementation -----------------------------------//
- inline void invert(int16_t& x)
+ inline void reorder(int16_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
@@ -63,7 +63,7 @@
*(rep+1) = tmp;
}
- inline void invert(int32_t& x)
+ inline void reorder(int32_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
@@ -75,7 +75,7 @@
*(rep+2) = tmp;
}
- inline void invert(int64_t& x)
+ inline void reorder(int64_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
@@ -93,7 +93,7 @@
*(rep+4) = tmp;
}
- inline void invert(uint16_t& x)
+ inline void reorder(uint16_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
@@ -102,7 +102,7 @@
*(rep+1) = tmp;
}
- inline void invert(uint32_t& x)
+ inline void reorder(uint32_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
@@ -114,7 +114,7 @@
*(rep+2) = tmp;
}
- inline void invert(uint64_t& x)
+ inline void reorder(uint64_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
@@ -132,7 +132,7 @@
*(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<const char*>(&source));
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
@@ -140,7 +140,7 @@
*--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<const char*>(&source));
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
@@ -150,7 +150,7 @@
*--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<const char*>(&source));
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
@@ -164,7 +164,7 @@
*--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<const char*>(&source));
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
@@ -172,7 +172,7 @@
*--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<const char*>(&source));
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
@@ -182,7 +182,7 @@
*--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<const char*>(&source));
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
@@ -197,23 +197,23 @@
}
#ifdef BOOST_LITTLE_ENDIAN
- template <class T> inline void native_to_big(T& x) { invert(x); }
+ template <class T> inline void native_to_big(T& x) { reorder(x); }
template <class T> inline void native_to_little(T&) {}
- template <class T> inline void big_to_native(T& x) { invert(x); }
+ template <class T> inline void big_to_native(T& x) { reorder(x); }
template <class T> inline void little_to_native(T&) {}
- template <class T> inline void native_to_big(T source, T& target) { invert(source, target); }
+ template <class T> inline void native_to_big(T source, T& target) { reorder(source, target); }
template <class T> inline void native_to_little(T source, T& target) { target = source; }
- template <class T> inline void big_to_native(T source, T& target) { invert(source, target); }
+ template <class T> inline void big_to_native(T source, T& target) { reorder(source, target); }
template <class T> inline void little_to_native(T source, T& target) { target = source; }
#else
template <class T> inline void native_to_big(T&) {}
- template <class T> inline void native_to_little(T& x) { invert(x); }
+ template <class T> inline void native_to_little(T& x) { reorder(x); }
template <class T> inline void big_to_native(T&) {}
- template <class T> inline void little_to_native(T& x) { invert(x); }
+ template <class T> inline void little_to_native(T& x) { reorder(x); }
template <class T> inline void native_to_big(T native, T& big) { target = source; }
- template <class T> inline void native_to_little(T native, T& little) { invert(source, target); }
+ template <class T> inline void native_to_little(T native, T& little) { reorder(source, target); }
template <class T> inline void big_to_native(T big, T& native) { target = source; }
- template <class T> inline void little_to_native(T little, T& native) { invert(source, target); }
+ template <class T> inline void little_to_native(T little, T& native) { reorder(source, target); }
#endif
} // namespace endian
Modified: sandbox/endian/libs/endian/doc/conversion.html
==============================================================================
--- sandbox/endian/libs/endian/doc/conversion.html (original)
+++ sandbox/endian/libs/endian/doc/conversion.html 2011-09-03 16:42:28 EDT (Sat, 03 Sep 2011)
@@ -46,34 +46,32 @@
{
namespace endian
{
- // invert: <span class="f">verb: p</span>ut 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);
+
+ // unconditional non-modifying reverse byte order 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& 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 endianness reversing 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);
-
- // 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 boost</pre>
<h3 dir="ltr">Members</h3>
-<pre dir="ltr">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);</pre>
+<pre dir="ltr">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);</pre>
<blockquote>
<p dir="ltr"><i>Effects:</i> Reverses the byte order of <i><code>x</code></i>.</p>
</blockquote>
-<pre dir="ltr">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);</pre>
+<pre dir="ltr">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);</pre>
<blockquote>
<p dir="ltr"><i>Effects:</i> Copies <code>source</code> to <code>target</code>,
reversing the byte order.</p>
@@ -108,7 +106,7 @@
template <class T> void little_to_native(T& x);</pre>
<blockquote>
<p dir="ltr"><i>Effects:</i> If the native byte ordering and indicated byte
- ordering are different, <code>invert(x)</code>, otherwise no effect.</p>
+ ordering are different, <code>reorder(x)</code>, otherwise no effect.</p>
</blockquote>
<pre dir="ltr">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 little_to_native(T source, T& target);</pre>
<blockquote>
<p dir="ltr"><i>Effects:</i> If the native byte ordering and indicated byte
- ordering are different, <code>invert(source, target)</code>, otherwise <code>
+ ordering are different, <code>reorder(source, target)</code>, otherwise <code>
target = source</code>.</p>
</blockquote>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
Modified: sandbox/endian/libs/endian/example/endian_example.cpp
==============================================================================
--- sandbox/endian/libs/endian/example/endian_example.cpp (original)
+++ sandbox/endian/libs/endian/example/endian_example.cpp 2011-09-03 16:42:28 EDT (Sat, 03 Sep 2011)
@@ -16,8 +16,8 @@
#include <iostream>
#include <cstdio>
#include <boost/endian/types.hpp>
-#include <boost/detail/lightweight_test.hpp>
#include <boost/detail/lightweight_main.hpp>
+#include <boost/static_assert.hpp>
using namespace boost::endian;
@@ -41,14 +41,14 @@
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 <cstdio> fread/fwrite is sometimes
// used for binary file operations when ultimate efficiency is important.
@@ -74,5 +74,5 @@
std::cout << "created file " << filename << '\n';
- return ::boost::report_errors();
+ return 0;
}
Modified: sandbox/endian/libs/endian/test/conversion_test.cpp
==============================================================================
--- sandbox/endian/libs/endian/test/conversion_test.cpp (original)
+++ sandbox/endian/libs/endian/test/conversion_test.cpp 2011-09-03 16:42:28 EDT (Sat, 03 Sep 2011)
@@ -19,127 +19,127 @@
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<boost::int64_t>(0xf7f8f9fafbfcfdfeULL));
- be::invert(i64);
+ be::reorder(i64);
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(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<boost::int32_t>(0xfbfcfdfe));
- be::invert(i32);
+ be::reorder(i32);
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(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<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
- be::invert(i16);
+ be::reorder(i16);
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
- be::invert(i16);
+ be::reorder(i16);
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(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<boost::uint32_t>(0x04030201));
- be::invert(ui32);
+ be::reorder(ui32);
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(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<boost::uint16_t>(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<boost::int64_t>(0xf7f8f9fafbfcfdfeLL));
- be::invert(j64, k64);
+ be::reorder(j64, k64);
BOOST_TEST_EQ(k64, static_cast<boost::int64_t>(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<boost::int32_t>(0xfbfcfdfe));
- be::invert(j32, k32);
+ be::reorder(j32, k32);
BOOST_TEST_EQ(k32, static_cast<boost::int32_t>(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<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
- be::invert(i16, j16);
+ be::reorder(i16, j16);
BOOST_TEST_EQ(j16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
- be::invert(j16, k16);
+ be::reorder(j16, k16);
BOOST_TEST_EQ(k16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(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<boost::uint32_t>(0x04030201));
- be::invert(uj32, uk32);
+ be::reorder(uj32, uk32);
BOOST_TEST_EQ(uk32, static_cast<boost::uint32_t>(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 @@
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 @@
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 @@
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 @@
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();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk