/** * Copyright (c) 2011 Ubimet * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) **/ #ifndef ENDIAN_HPP #define ENDIAN_HPP #include #include namespace detail { BOOST_SCOPED_ENUM_START(endianness) { big, little, native }; BOOST_SCOPED_ENUM_END } template struct endian; template<> struct endian { unsigned char *current; template endian(T &value) { current = reinterpret_cast(&value); #if defined(BOOST_LITTLE_ENDIAN) current += sizeof(T) - 1; #endif } template endian(const T &value) { current = const_cast( reinterpret_cast(&value)); #if defined(BOOST_LITTLE_ENDIAN) current += sizeof(T) - 1; #endif } void next() { #if defined(BOOST_BIG_ENDIAN) ++current; #elif defined(BOOST_LITTLE_ENDIAN) --current; #endif } }; template<> struct endian { unsigned char *current; template endian(T &value) { current = reinterpret_cast(&value); #if defined(BOOST_BIG_ENDIAN) current += sizeof(T) - 1; #endif } template endian(const T &value) { current = const_cast( reinterpret_cast(&value)); #if defined(BOOST_BIG_ENDIAN) current += sizeof(T) - 1; #endif } void next() { #if defined(BOOST_BIG_ENDIAN) --current; #elif defined(BOOST_LITTLE_ENDIAN) ++current; #endif } }; template<> struct endian { unsigned char *current; template endian(T &value) { current = reinterpret_cast(&value); } template endian(const T &value) { current = const_cast( reinterpret_cast(&value)); } void next() { ++current; } }; #endif // ENDIAN_HPP