mirror of
https://github.com/boostorg/endian.git
synced 2025-08-02 05:54:31 +02:00
Rename flip() to invert()
git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@74214 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
@@ -19,24 +19,24 @@ namespace endian
|
|||||||
{
|
{
|
||||||
// unconditional modifying (i.e. in-place) endianness reversal
|
// unconditional modifying (i.e. in-place) endianness reversal
|
||||||
|
|
||||||
inline void flip(int16_t& x);
|
inline void invert(int16_t& x);
|
||||||
inline void flip(int32_t& x);
|
inline void invert(int32_t& x);
|
||||||
inline void flip(int64_t& x);
|
inline void invert(int64_t& x);
|
||||||
inline void flip(uint16_t& x);
|
inline void invert(uint16_t& x);
|
||||||
inline void flip(uint32_t& x);
|
inline void invert(uint32_t& x);
|
||||||
inline void flip(uint64_t& x);
|
inline void invert(uint64_t& x);
|
||||||
|
|
||||||
// unconditional non-modifying endianness reversing copy
|
// unconditional non-modifying endianness reversing copy
|
||||||
|
|
||||||
inline void flip(int16_t source, int16_t& target);
|
inline void invert(int16_t source, int16_t& target);
|
||||||
inline void flip(int32_t source, int32_t& target);
|
inline void invert(int32_t source, int32_t& target);
|
||||||
inline void flip(int64_t source, int64_t& target);
|
inline void invert(int64_t source, int64_t& target);
|
||||||
inline void flip(uint16_t source, uint16_t& target);
|
inline void invert(uint16_t source, uint16_t& target);
|
||||||
inline void flip(uint32_t source, uint32_t& target);
|
inline void invert(uint32_t source, uint32_t& target);
|
||||||
inline void flip(uint64_t source, uint64_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) endianness reversal;
|
||||||
// no effect if native endianness and specified endianness are the same
|
// no effect if native endianness and indicated endianness are the same
|
||||||
|
|
||||||
template <class T> inline void native_to_big(T& x);
|
template <class T> inline void native_to_big(T& x);
|
||||||
template <class T> inline void native_to_little(T& x);
|
template <class T> inline void native_to_little(T& x);
|
||||||
@@ -54,7 +54,7 @@ namespace endian
|
|||||||
|
|
||||||
//----------------------------------- implementation -----------------------------------//
|
//----------------------------------- implementation -----------------------------------//
|
||||||
|
|
||||||
inline void flip(int16_t& x)
|
inline void invert(int16_t& x)
|
||||||
{
|
{
|
||||||
char* rep = reinterpret_cast<char*>(&x);
|
char* rep = reinterpret_cast<char*>(&x);
|
||||||
char tmp;
|
char tmp;
|
||||||
@@ -63,7 +63,7 @@ namespace endian
|
|||||||
*(rep+1) = tmp;
|
*(rep+1) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(int32_t& x)
|
inline void invert(int32_t& x)
|
||||||
{
|
{
|
||||||
char* rep = reinterpret_cast<char*>(&x);
|
char* rep = reinterpret_cast<char*>(&x);
|
||||||
char tmp;
|
char tmp;
|
||||||
@@ -75,7 +75,7 @@ namespace endian
|
|||||||
*(rep+2) = tmp;
|
*(rep+2) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(int64_t& x)
|
inline void invert(int64_t& x)
|
||||||
{
|
{
|
||||||
char* rep = reinterpret_cast<char*>(&x);
|
char* rep = reinterpret_cast<char*>(&x);
|
||||||
char tmp;
|
char tmp;
|
||||||
@@ -93,7 +93,7 @@ namespace endian
|
|||||||
*(rep+4) = tmp;
|
*(rep+4) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(uint16_t& x)
|
inline void invert(uint16_t& x)
|
||||||
{
|
{
|
||||||
char* rep = reinterpret_cast<char*>(&x);
|
char* rep = reinterpret_cast<char*>(&x);
|
||||||
char tmp;
|
char tmp;
|
||||||
@@ -102,7 +102,7 @@ namespace endian
|
|||||||
*(rep+1) = tmp;
|
*(rep+1) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(uint32_t& x)
|
inline void invert(uint32_t& x)
|
||||||
{
|
{
|
||||||
char* rep = reinterpret_cast<char*>(&x);
|
char* rep = reinterpret_cast<char*>(&x);
|
||||||
char tmp;
|
char tmp;
|
||||||
@@ -114,7 +114,7 @@ namespace endian
|
|||||||
*(rep+2) = tmp;
|
*(rep+2) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(uint64_t& x)
|
inline void invert(uint64_t& x)
|
||||||
{
|
{
|
||||||
char* rep = reinterpret_cast<char*>(&x);
|
char* rep = reinterpret_cast<char*>(&x);
|
||||||
char tmp;
|
char tmp;
|
||||||
@@ -132,7 +132,7 @@ namespace endian
|
|||||||
*(rep+4) = tmp;
|
*(rep+4) = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(int16_t source, int16_t& target)
|
inline void invert(int16_t source, int16_t& target)
|
||||||
{
|
{
|
||||||
const char* s (reinterpret_cast<const char*>(&source));
|
const char* s (reinterpret_cast<const char*>(&source));
|
||||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||||
@@ -140,7 +140,7 @@ namespace endian
|
|||||||
*--t = *++s;
|
*--t = *++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(int32_t source, int32_t& target)
|
inline void invert(int32_t source, int32_t& target)
|
||||||
{
|
{
|
||||||
const char* s (reinterpret_cast<const char*>(&source));
|
const char* s (reinterpret_cast<const char*>(&source));
|
||||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||||
@@ -150,7 +150,7 @@ namespace endian
|
|||||||
*--t = *++s;
|
*--t = *++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(int64_t source, int64_t& target)
|
inline void invert(int64_t source, int64_t& target)
|
||||||
{
|
{
|
||||||
const char* s (reinterpret_cast<const char*>(&source));
|
const char* s (reinterpret_cast<const char*>(&source));
|
||||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||||
@@ -164,7 +164,7 @@ namespace endian
|
|||||||
*--t = *++s;
|
*--t = *++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(uint16_t source, uint16_t& target)
|
inline void invert(uint16_t source, uint16_t& target)
|
||||||
{
|
{
|
||||||
const char* s (reinterpret_cast<const char*>(&source));
|
const char* s (reinterpret_cast<const char*>(&source));
|
||||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||||
@@ -172,7 +172,7 @@ namespace endian
|
|||||||
*--t = *++s;
|
*--t = *++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(uint32_t source, uint32_t& target)
|
inline void invert(uint32_t source, uint32_t& target)
|
||||||
{
|
{
|
||||||
const char* s (reinterpret_cast<const char*>(&source));
|
const char* s (reinterpret_cast<const char*>(&source));
|
||||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||||
@@ -182,7 +182,7 @@ namespace endian
|
|||||||
*--t = *++s;
|
*--t = *++s;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void flip(uint64_t source, uint64_t& target)
|
inline void invert(uint64_t source, uint64_t& target)
|
||||||
{
|
{
|
||||||
const char* s (reinterpret_cast<const char*>(&source));
|
const char* s (reinterpret_cast<const char*>(&source));
|
||||||
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
char * t (reinterpret_cast<char*>(&target) + sizeof(target) - 1);
|
||||||
@@ -197,23 +197,23 @@ namespace endian
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
template <class T> inline void native_to_big(T& x) { flip(x); }
|
template <class T> inline void native_to_big(T& x) { invert(x); }
|
||||||
template <class T> inline void native_to_little(T&) {}
|
template <class T> inline void native_to_little(T&) {}
|
||||||
template <class T> inline void big_to_native(T& x) { flip(x); }
|
template <class T> inline void big_to_native(T& x) { invert(x); }
|
||||||
template <class T> inline void little_to_native(T&) {}
|
template <class T> inline void little_to_native(T&) {}
|
||||||
template <class T> inline void native_to_big(T source, T& target) { flip(source, target); }
|
template <class T> inline void native_to_big(T source, T& target) { invert(source, target); }
|
||||||
template <class T> inline void native_to_little(T source, T& target) { target = source; }
|
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) { flip(source, target); }
|
template <class T> inline void big_to_native(T source, T& target) { invert(source, target); }
|
||||||
template <class T> inline void little_to_native(T source, T& target) { target = source; }
|
template <class T> inline void little_to_native(T source, T& target) { target = source; }
|
||||||
#else
|
#else
|
||||||
template <class T> inline void native_to_big(T&) {}
|
template <class T> inline void native_to_big(T&) {}
|
||||||
template <class T> inline void native_to_little(T& x) { flip(x); }
|
template <class T> inline void native_to_little(T& x) { invert(x); }
|
||||||
template <class T> inline void big_to_native(T&) {}
|
template <class T> inline void big_to_native(T&) {}
|
||||||
template <class T> inline void little_to_native(T& x) { flip(x); }
|
template <class T> inline void little_to_native(T& x) { invert(x); }
|
||||||
template <class T> inline void native_to_big(T native, T& big) { target = source; }
|
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) { flip(source, target); }
|
template <class T> inline void native_to_little(T native, T& little) { invert(source, target); }
|
||||||
template <class T> inline void big_to_native(T big, T& native) { target = source; }
|
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) { flip(source, target); }
|
template <class T> inline void little_to_native(T little, T& native) { invert(source, target); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // namespace endian
|
} // namespace endian
|
||||||
|
@@ -32,62 +32,103 @@
|
|||||||
|
|
||||||
<h2><a name="Introduction">Introduction</a></h2>
|
<h2><a name="Introduction">Introduction</a></h2>
|
||||||
|
|
||||||
<p> </p>
|
<p>Header <a href="../../../boost/endian/conversion.hpp">boost/endian/conversion.hpp</a>
|
||||||
|
provides functions that convert built-in
|
||||||
|
integers from the native byte ordering to or from big or little endian byte
|
||||||
|
ordering.</p>
|
||||||
|
|
||||||
<h2>Header <font face="Courier New"><boost/endian/conversion></font>
|
<h2><a name="Reference">Reference</a></h2>
|
||||||
<a name="Synopsis">Synopsis</a></h2>
|
|
||||||
|
<h3>
|
||||||
|
<a name="Synopsis">Synopsis</a></h3>
|
||||||
|
|
||||||
<pre>namespace boost
|
<pre>namespace boost
|
||||||
{
|
{
|
||||||
namespace endian
|
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) endianness reversal
|
// unconditional modifying (i.e. in-place) endianness reversal
|
||||||
|
|
||||||
inline void flip(int16_t& x);
|
inline void invert(int16_t& x);
|
||||||
inline void flip(int32_t& x);
|
inline void invert(int32_t& x);
|
||||||
inline void flip(int64_t& x);
|
inline void invert(int64_t& x);
|
||||||
inline void flip(uint16_t& x);
|
inline void invert(uint16_t& x);
|
||||||
inline void flip(uint32_t& x);
|
inline void invert(uint32_t& x);
|
||||||
inline void flip(uint64_t& x);
|
inline void invert(uint64_t& x);
|
||||||
|
|
||||||
// unconditional non-modifying endianness reversing copy
|
// unconditional non-modifying endianness reversing copy
|
||||||
|
|
||||||
inline void flip(int16_t source, int16_t& target);
|
inline void invert(int16_t source, int16_t& target);
|
||||||
inline void flip(int32_t source, int32_t& target);
|
inline void invert(int32_t source, int32_t& target);
|
||||||
inline void flip(int64_t source, int64_t& target);
|
inline void invert(int64_t source, int64_t& target);
|
||||||
inline void flip(uint16_t source, uint16_t& target);
|
inline void invert(uint16_t source, uint16_t& target);
|
||||||
inline void flip(uint32_t source, uint32_t& target);
|
inline void invert(uint32_t source, uint32_t& target);
|
||||||
inline void flip(uint64_t source, uint64_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) endianness reversal
|
||||||
// no effect if native endianness and specified endianness are the same
|
|
||||||
|
|
||||||
template <class T> inline void to_big(T& x); // if different, convert native to big
|
template <class T> void native_to_big(T& x);
|
||||||
template <class T> inline void to_little(T& x); // if different, convert native to little
|
template <class T> void native_to_little(T& x);
|
||||||
template <class T> inline void from_big(T& x); // if different, convert big to native
|
template <class T> void big_to_native(T& x);
|
||||||
template <class T> inline void from_little(T& x); // if different, convert little to native
|
template <class T> void little_to_native(T& x);
|
||||||
|
|
||||||
// non-modifying copy, conditionally reversing endianness;
|
// non-modifying copy conditionally reversing endianness;
|
||||||
// copy the first argument to the second argument, converting to or from the
|
|
||||||
// specified endianness if different than native endianness
|
|
||||||
|
|
||||||
template <class T> inline void to_big(T native, T& big);
|
template <class T> void native_to_big(T source, T& target);
|
||||||
template <class T> inline void to_little(T native, T& little);
|
template <class T> void native_to_little(T source, T& target);
|
||||||
template <class T> inline void from_big(T big, T& native);
|
template <class T> void big_to_native(T source, T& target);
|
||||||
template <class T> inline void from_little(T little, T& native);
|
template <class T> void little_to_native(T source, T& target);
|
||||||
</pre>
|
|
||||||
<pre>} // namespace endian
|
} // namespace endian
|
||||||
} // namespace boost</pre>
|
} // 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>
|
||||||
|
<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>
|
||||||
|
<blockquote>
|
||||||
|
<p dir="ltr"><i>Effects:</i> Copies <code>source</code> to <code>target</code>,
|
||||||
|
reversing the byte order.</p>
|
||||||
|
</blockquote>
|
||||||
|
<pre dir="ltr">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);</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>
|
||||||
|
</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);
|
||||||
|
template <class T> void big_to_native(T source, T& target);
|
||||||
|
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>
|
||||||
|
target = source</code>.</p>
|
||||||
|
</blockquote>
|
||||||
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
|
<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 types.</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Last revised:
|
<p>Last revised:
|
||||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->27 May, 2011<!--webbot bot="Timestamp" endspan i-checksum="13974" --></p>
|
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->03 September, 2011<!--webbot bot="Timestamp" endspan i-checksum="39334" --></p>
|
||||||
<p><EFBFBD> Copyright Beman Dawes, 2011</p>
|
<p><EFBFBD> Copyright Beman Dawes, 2011</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>
|
||||||
|
|
||||||
<p> </p>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
@@ -32,7 +32,7 @@
|
|||||||
|
|
||||||
<h2><a name="Introduction">Introduction</a></h2>
|
<h2><a name="Introduction">Introduction</a></h2>
|
||||||
|
|
||||||
<p>The Boost Endian Library provides facilities to deal with endianness. See
|
<p>The Boost Endian Library provides facilities to deal with integer endianness. See
|
||||||
<a href="#Introduction-to-endianness">Introduction to endianness</a> below for
|
<a href="#Introduction-to-endianness">Introduction to endianness</a> below for
|
||||||
the basics of endianness.</p>
|
the basics of endianness.</p>
|
||||||
|
|
||||||
@@ -40,17 +40,21 @@ the basics of endianness.</p>
|
|||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
|
|
||||||
<p><b>Endian conversions for native integers -</b> The application uses the
|
<p><b>Endian conversions for native integers -</b> With this approach, the application uses the
|
||||||
built-in integer types, and calls the provided conversion functions to swap
|
built-in integer types, and calls the provided conversion functions to convert
|
||||||
bytes as needed. Both mutating and non-mutating conversions are supplied, and
|
byte ordering as needed. Both mutating and non-mutating conversions are supplied, and
|
||||||
each comes in unconditional and conditional variants. This approach is simple
|
each comes in unconditional and conditional variants. This approach is simple
|
||||||
and efficient, but is less flexible in terms of size and alignment, and can be
|
and efficient, but is less flexible in terms of size and alignment, and can be
|
||||||
hard to manage in code with many logical paths involving endianness transitions.</p>
|
hard-to-manage and error-prone in code with many logical paths involving endianness transitions.</p>
|
||||||
|
|
||||||
<p><b>Endian integer types</b></p>
|
<p><b>Endian integer types -</b> With this approach, the application uses the
|
||||||
|
provided endian classes which mimic the
|
||||||
|
built-in integer types. For example, <code>big32_t</code> or <code>little64_t</code>. </p>
|
||||||
|
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
<p>Boost Endian is header-only library.</p>
|
||||||
|
|
||||||
<h2><a name="Introduction-to-endianness">Introduction to endianness</a></h2>
|
<h2><a name="Introduction-to-endianness">Introduction to endianness</a></h2>
|
||||||
|
|
||||||
<p>Consider a C++ program that defines variables x, y, and z as 16, 32, and
|
<p>Consider a C++ program that defines variables x, y, and z as 16, 32, and
|
||||||
@@ -190,9 +194,27 @@ details for many processors and operating systems.</p>
|
|||||||
<p>External memory, such as disks, generally uses the same endianness as the
|
<p>External memory, such as disks, generally uses the same endianness as the
|
||||||
operating system. Networks traditionally use big endian ordering, so this is
|
operating system. Networks traditionally use big endian ordering, so this is
|
||||||
sometimes referred as network endianness.</p>
|
sometimes referred as network endianness.</p>
|
||||||
|
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
|
||||||
|
<p>Comments and suggestions were
|
||||||
|
received from
|
||||||
|
Benaka Moorthi,
|
||||||
|
Christopher Kohlhoff,
|
||||||
|
Cliff Green,
|
||||||
|
Gennaro Proto,
|
||||||
|
Giovanni Piero Deretta, dizzy, Jeff Flinn,
|
||||||
|
John Maddock,
|
||||||
|
Kim Barrett,
|
||||||
|
Marsh Ray,
|
||||||
|
Martin Bonner,
|
||||||
|
Matias Capeletto,
|
||||||
|
Neil Mayhew, Phil Endecott, Rene Rivera,
|
||||||
|
Roland Schwarz, Scott McMurray,
|
||||||
|
Sebastian Redl,
|
||||||
|
Tomas Puverle, Vincente Botet, and
|
||||||
|
Yuval Ronen.</p>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Last revised:
|
<p>Last revised:
|
||||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->27 May, 2011<!--webbot bot="Timestamp" endspan i-checksum="13974" --></p>
|
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->03 September, 2011<!--webbot bot="Timestamp" endspan i-checksum="39334" --></p>
|
||||||
<p><EFBFBD> Copyright Beman Dawes, 2011</p>
|
<p><EFBFBD> Copyright Beman Dawes, 2011</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>
|
||||||
|
@@ -19,127 +19,127 @@ namespace be = boost::endian;
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
void test_in_place_flip()
|
void test_in_place_invert()
|
||||||
{
|
{
|
||||||
std::cout << "test_in_place_flip...\n";
|
std::cout << "test_in_place_invert...\n";
|
||||||
|
|
||||||
boost::int64_t i64 = 0x0102030405060708LL;
|
boost::int64_t i64 = 0x0102030405060708LL;
|
||||||
be::flip(i64);
|
be::invert(i64);
|
||||||
BOOST_TEST_EQ(i64, 0x0807060504030201LL);
|
BOOST_TEST_EQ(i64, 0x0807060504030201LL);
|
||||||
be::flip(i64);
|
be::invert(i64);
|
||||||
BOOST_TEST_EQ(i64, 0x0102030405060708LL);
|
BOOST_TEST_EQ(i64, 0x0102030405060708LL);
|
||||||
|
|
||||||
i64 = 0xfefdfcfbfaf9f8f7LL;
|
i64 = 0xfefdfcfbfaf9f8f7LL;
|
||||||
be::flip(i64);
|
be::invert(i64);
|
||||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeULL));
|
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeULL));
|
||||||
be::flip(i64);
|
be::invert(i64);
|
||||||
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7ULL));
|
BOOST_TEST_EQ(i64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7ULL));
|
||||||
|
|
||||||
boost::int32_t i32 = 0x01020304;
|
boost::int32_t i32 = 0x01020304;
|
||||||
be::flip(i32);
|
be::invert(i32);
|
||||||
BOOST_TEST_EQ(i32, 0x04030201);
|
BOOST_TEST_EQ(i32, 0x04030201);
|
||||||
be::flip(i32);
|
be::invert(i32);
|
||||||
BOOST_TEST_EQ(i32, 0x01020304);
|
BOOST_TEST_EQ(i32, 0x01020304);
|
||||||
|
|
||||||
i32 = 0xfefdfcfb;
|
i32 = 0xfefdfcfb;
|
||||||
be::flip(i32);
|
be::invert(i32);
|
||||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||||
be::flip(i32);
|
be::invert(i32);
|
||||||
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));
|
BOOST_TEST_EQ(i32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||||
|
|
||||||
boost::int16_t i16 = 0x0102;
|
boost::int16_t i16 = 0x0102;
|
||||||
be::flip(i16);
|
be::invert(i16);
|
||||||
BOOST_TEST_EQ(i16, 0x0201);
|
BOOST_TEST_EQ(i16, 0x0201);
|
||||||
be::flip(i16);
|
be::invert(i16);
|
||||||
BOOST_TEST_EQ(i16, 0x0102);
|
BOOST_TEST_EQ(i16, 0x0102);
|
||||||
|
|
||||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||||
be::flip(i16);
|
be::invert(i16);
|
||||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||||
be::flip(i16);
|
be::invert(i16);
|
||||||
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
BOOST_TEST_EQ(i16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||||
|
|
||||||
boost::uint64_t ui64 = 0x0102030405060708ULL;
|
boost::uint64_t ui64 = 0x0102030405060708ULL;
|
||||||
be::flip(ui64);
|
be::invert(ui64);
|
||||||
BOOST_TEST_EQ(ui64, 0x0807060504030201ULL);
|
BOOST_TEST_EQ(ui64, 0x0807060504030201ULL);
|
||||||
be::flip(ui64);
|
be::invert(ui64);
|
||||||
BOOST_TEST_EQ(ui64, 0x0102030405060708ULL);
|
BOOST_TEST_EQ(ui64, 0x0102030405060708ULL);
|
||||||
|
|
||||||
boost::uint32_t ui32 = 0x01020304;
|
boost::uint32_t ui32 = 0x01020304;
|
||||||
be::flip(ui32);
|
be::invert(ui32);
|
||||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
|
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x04030201));
|
||||||
be::flip(ui32);
|
be::invert(ui32);
|
||||||
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));
|
BOOST_TEST_EQ(ui32, static_cast<boost::uint32_t>(0x01020304));
|
||||||
|
|
||||||
boost::uint16_t ui16 = 0x0102;
|
boost::uint16_t ui16 = 0x0102;
|
||||||
be::flip(ui16);
|
be::invert(ui16);
|
||||||
BOOST_TEST_EQ(ui16, 0x0201);
|
BOOST_TEST_EQ(ui16, 0x0201);
|
||||||
be::flip(ui16);
|
be::invert(ui16);
|
||||||
BOOST_TEST_EQ(ui16, static_cast<boost::uint16_t>(0x0102));
|
BOOST_TEST_EQ(ui16, static_cast<boost::uint16_t>(0x0102));
|
||||||
|
|
||||||
std::cout << " test_in_place_flip complete\n";
|
std::cout << " test_in_place_invert complete\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_copying_flip()
|
void test_copying_invert()
|
||||||
{
|
{
|
||||||
std::cout << "test_copying_flip...\n";
|
std::cout << "test_copying_invert...\n";
|
||||||
|
|
||||||
boost::int64_t i64 = 0x0102030405060708LL, j64, k64;
|
boost::int64_t i64 = 0x0102030405060708LL, j64, k64;
|
||||||
be::flip(i64, j64);
|
be::invert(i64, j64);
|
||||||
BOOST_TEST_EQ(j64, 0x0807060504030201LL);
|
BOOST_TEST_EQ(j64, 0x0807060504030201LL);
|
||||||
BOOST_TEST_EQ(i64, 0x0102030405060708LL);
|
BOOST_TEST_EQ(i64, 0x0102030405060708LL);
|
||||||
be::flip(j64, k64);
|
be::invert(j64, k64);
|
||||||
BOOST_TEST_EQ(k64, 0x0102030405060708LL);
|
BOOST_TEST_EQ(k64, 0x0102030405060708LL);
|
||||||
|
|
||||||
i64 = 0xfefdfcfbfaf9f8f7LL;
|
i64 = 0xfefdfcfbfaf9f8f7LL;
|
||||||
be::flip(i64, j64);
|
be::invert(i64, j64);
|
||||||
BOOST_TEST_EQ(j64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeLL));
|
BOOST_TEST_EQ(j64, static_cast<boost::int64_t>(0xf7f8f9fafbfcfdfeLL));
|
||||||
be::flip(j64, k64);
|
be::invert(j64, k64);
|
||||||
BOOST_TEST_EQ(k64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7LL));
|
BOOST_TEST_EQ(k64, static_cast<boost::int64_t>(0xfefdfcfbfaf9f8f7LL));
|
||||||
|
|
||||||
boost::int32_t i32 = 0x01020304, j32, k32;
|
boost::int32_t i32 = 0x01020304, j32, k32;
|
||||||
be::flip(i32, j32);
|
be::invert(i32, j32);
|
||||||
BOOST_TEST_EQ(j32, 0x04030201);
|
BOOST_TEST_EQ(j32, 0x04030201);
|
||||||
be::flip(j32, k32);
|
be::invert(j32, k32);
|
||||||
BOOST_TEST_EQ(k32, 0x01020304);
|
BOOST_TEST_EQ(k32, 0x01020304);
|
||||||
|
|
||||||
i32 = 0xfefdfcfb;
|
i32 = 0xfefdfcfb;
|
||||||
be::flip(i32, j32);
|
be::invert(i32, j32);
|
||||||
BOOST_TEST_EQ(j32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
BOOST_TEST_EQ(j32, static_cast<boost::int32_t>(0xfbfcfdfe));
|
||||||
be::flip(j32, k32);
|
be::invert(j32, k32);
|
||||||
BOOST_TEST_EQ(k32, static_cast<boost::int32_t>(0xfefdfcfb));
|
BOOST_TEST_EQ(k32, static_cast<boost::int32_t>(0xfefdfcfb));
|
||||||
|
|
||||||
boost::int16_t i16 = 0x0102, j16, k16;
|
boost::int16_t i16 = 0x0102, j16, k16;
|
||||||
be::flip(i16, j16);
|
be::invert(i16, j16);
|
||||||
BOOST_TEST_EQ(j16, 0x0201);
|
BOOST_TEST_EQ(j16, 0x0201);
|
||||||
be::flip(j16, k16);
|
be::invert(j16, k16);
|
||||||
BOOST_TEST_EQ(k16, 0x0102);
|
BOOST_TEST_EQ(k16, 0x0102);
|
||||||
|
|
||||||
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
i16 = static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd));
|
||||||
be::flip(i16, j16);
|
be::invert(i16, j16);
|
||||||
BOOST_TEST_EQ(j16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
BOOST_TEST_EQ(j16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfdfe)));
|
||||||
be::flip(j16, k16);
|
be::invert(j16, k16);
|
||||||
BOOST_TEST_EQ(k16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
BOOST_TEST_EQ(k16, static_cast<boost::int16_t>(static_cast<boost::uint16_t>(0xfefd)));
|
||||||
|
|
||||||
boost::uint64_t ui64 = 0x0102030405060708ULL, uj64, uk64;
|
boost::uint64_t ui64 = 0x0102030405060708ULL, uj64, uk64;
|
||||||
be::flip(ui64, uj64);
|
be::invert(ui64, uj64);
|
||||||
BOOST_TEST_EQ(uj64, 0x0807060504030201ULL);
|
BOOST_TEST_EQ(uj64, 0x0807060504030201ULL);
|
||||||
be::flip(uj64, uk64);
|
be::invert(uj64, uk64);
|
||||||
BOOST_TEST_EQ(uk64, 0x0102030405060708ULL);
|
BOOST_TEST_EQ(uk64, 0x0102030405060708ULL);
|
||||||
|
|
||||||
boost::uint32_t ui32 = 0x01020304, uj32, uk32;
|
boost::uint32_t ui32 = 0x01020304, uj32, uk32;
|
||||||
be::flip(ui32, uj32);
|
be::invert(ui32, uj32);
|
||||||
BOOST_TEST_EQ(uj32, static_cast<boost::uint32_t>(0x04030201));
|
BOOST_TEST_EQ(uj32, static_cast<boost::uint32_t>(0x04030201));
|
||||||
be::flip(uj32, uk32);
|
be::invert(uj32, uk32);
|
||||||
BOOST_TEST_EQ(uk32, static_cast<boost::uint32_t>(0x01020304));
|
BOOST_TEST_EQ(uk32, static_cast<boost::uint32_t>(0x01020304));
|
||||||
|
|
||||||
boost::uint16_t ui16 = 0x0102, uj16, uk16;
|
boost::uint16_t ui16 = 0x0102, uj16, uk16;
|
||||||
be::flip(ui16, uj16);
|
be::invert(ui16, uj16);
|
||||||
BOOST_TEST_EQ(uj16, 0x0201);
|
BOOST_TEST_EQ(uj16, 0x0201);
|
||||||
be::flip(uj16, uk16);
|
be::invert(uj16, uk16);
|
||||||
BOOST_TEST_EQ(uk16, 0x0102);
|
BOOST_TEST_EQ(uk16, 0x0102);
|
||||||
|
|
||||||
std::cout << " test_copying_flip complete\n";
|
std::cout << " test_copying_invert complete\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
const boost::int64_t ni64 = 0x0102030405060708LL;
|
const boost::int64_t ni64 = 0x0102030405060708LL;
|
||||||
@@ -196,9 +196,9 @@ namespace
|
|||||||
const boost::uint16_t lui16 = 0x0102;
|
const boost::uint16_t lui16 = 0x0102;
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
void test_in_place_conditional_flip()
|
void test_in_place_conditional_invert()
|
||||||
{
|
{
|
||||||
std::cout << "test_in_place_conditional_flip...\n";
|
std::cout << "test_in_place_conditional_invert...\n";
|
||||||
|
|
||||||
boost::int64_t i64;
|
boost::int64_t i64;
|
||||||
|
|
||||||
@@ -308,12 +308,12 @@ namespace
|
|||||||
be::little_to_native(ui16);
|
be::little_to_native(ui16);
|
||||||
BOOST_TEST_EQ(ui16, nui16);
|
BOOST_TEST_EQ(ui16, nui16);
|
||||||
|
|
||||||
std::cout << " test_in_place_conditional_flip complete\n";
|
std::cout << " test_in_place_conditional_invert complete\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_copying_conditional_flip()
|
void test_copying_conditional_invert()
|
||||||
{
|
{
|
||||||
std::cout << "test_copying_conditional_flip...\n";
|
std::cout << "test_copying_conditional_invert...\n";
|
||||||
|
|
||||||
boost::int64_t i64, ti64;
|
boost::int64_t i64, ti64;
|
||||||
|
|
||||||
@@ -423,7 +423,7 @@ namespace
|
|||||||
be::little_to_native(ui16, tui16);
|
be::little_to_native(ui16, tui16);
|
||||||
BOOST_TEST_EQ(tui16, nui16);
|
BOOST_TEST_EQ(tui16, nui16);
|
||||||
|
|
||||||
std::cout << " test_copying_conditional_flip complete\n";
|
std::cout << " test_copying_conditional_invert complete\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
@@ -431,10 +431,10 @@ namespace
|
|||||||
int cpp_main(int, char * [])
|
int cpp_main(int, char * [])
|
||||||
{
|
{
|
||||||
std::cerr << std::hex;
|
std::cerr << std::hex;
|
||||||
test_in_place_flip();
|
test_in_place_invert();
|
||||||
test_copying_flip();
|
test_copying_invert();
|
||||||
test_in_place_conditional_flip();
|
test_in_place_conditional_invert();
|
||||||
test_copying_conditional_flip();
|
test_copying_conditional_invert();
|
||||||
|
|
||||||
return ::boost::report_errors();
|
return ::boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "endian_hello_world", "endia
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "binary_stream_test", "binary_stream_test\binary_stream_test.vcxproj", "{1382D085-FF3F-4573-8709-E10D3D74D620}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "binary_stream_test", "binary_stream_test\binary_stream_test.vcxproj", "{1382D085-FF3F-4573-8709-E10D3D74D620}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "binary_stream_example", "binary_stream_example\binary_stream_example.vcxproj", "{06736C67-6305-4A9F-8D10-850FD0CE907D}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bin_manip_example", "binary_stream_example\binary_stream_example.vcxproj", "{06736C67-6305-4A9F-8D10-850FD0CE907D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "conversion_test", "conversion_test\conversion_test.vcxproj", "{9FA33B0B-2B00-49E8-A892-E049D86076A9}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "conversion_test", "conversion_test\conversion_test.vcxproj", "{9FA33B0B-2B00-49E8-A892-E049D86076A9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Reference in New Issue
Block a user