#ifndef SPROUT_ENDIAN_TRAITS_HPP #define SPROUT_ENDIAN_TRAITS_HPP #include #include #include #include namespace sprout { namespace detail { template class default_big_endian_traits; template class default_big_endian_traits< T, typename std::enable_if::value>::type > { public: typedef T type; public: static SPROUT_CONSTEXPR std::size_t size() { return sizeof(type); } static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t i) { return static_cast( (t & (UCHAR_MAX << CHAR_BIT * ((size() - 1) - i))) >> CHAR_BIT * ((size() - 1) - i) ); } }; template class default_little_endian_traits; template class default_little_endian_traits< T, typename std::enable_if::value>::type > { public: typedef T type; public: static SPROUT_CONSTEXPR std::size_t size() { return sizeof(type); } static SPROUT_CONSTEXPR unsigned char get_byte(type const& t, std::size_t i) { return static_cast( (t & (UCHAR_MAX << CHAR_BIT * i)) >> CHAR_BIT * i ); } }; } // namespace detail // // big_endian_traits // template class big_endian_traits : public sprout::detail::default_big_endian_traits {}; // // little_endian_traits // template class little_endian_traits : public sprout::detail::default_little_endian_traits {}; // // endian_traits // template class endian_traits : public sprout::big_endian_traits {}; } // namespace sprout #endif // #ifndef SPROUT_ENDIAN_TRAITS_HPP