Add endian_flip.hpp, with tests. Upgrade VC++ to 2010

git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@65051 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
bemandawes committed 2010-08-27 14:09:04 +00:00
1 parent c60b7d2171
commit 1713348f8d
23 files changed
+1041 -1587

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
// endian_flip.hpp -------------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_ENDIAN_FLIP_HPP
#define BOOST_ENDIAN_FLIP_HPP
#include <boost/integer.hpp>
namespace boost
{
namespace integer
{
void endian_flip(int16_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
tmp = *rep;
*rep = *(rep+1);
*(rep+1) = tmp;
}
void endian_flip(int32_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
tmp = *rep;
*rep = *(rep+3);
*(rep+3) = tmp;
tmp = *(rep+1);
*(rep+1) = *(rep+2);
*(rep+2) = tmp;
}
void endian_flip(int64_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
tmp = *rep;
*rep = *(rep+7);
*(rep+7) = tmp;
tmp = *(rep+1);
*(rep+1) = *(rep+6);
*(rep+6) = tmp;
tmp = *(rep+2);
*(rep+2) = *(rep+5);
*(rep+5) = tmp;
tmp = *(rep+3);
*(rep+3) = *(rep+4);
*(rep+4) = tmp;
}
void endian_flip(uint16_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
tmp = *rep;
*rep = *(rep+1);
*(rep+1) = tmp;
}
void endian_flip(uint32_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
tmp = *rep;
*rep = *(rep+3);
*(rep+3) = tmp;
tmp = *(rep+1);
*(rep+1) = *(rep+2);
*(rep+2) = tmp;
}
void endian_flip(uint64_t& x)
{
char* rep = reinterpret_cast<char*>(&x);
char tmp;
tmp = *rep;
*rep = *(rep+7);
*(rep+7) = tmp;
tmp = *(rep+1);
*(rep+1) = *(rep+6);
*(rep+6) = tmp;
tmp = *(rep+2);
*(rep+2) = *(rep+5);
*(rep+5) = tmp;
tmp = *(rep+3);
*(rep+3) = *(rep+4);
*(rep+4) = tmp;
}
} // namespace integer
} // namespace boost
#endif // BOOST_ENDIAN_FLIP_HPP