Index: home/support/detail/integer/endian.hpp =================================================================== --- home/support/detail/integer/endian.hpp (revision 72619) +++ home/support/detail/integer/endian.hpp (working copy) @@ -122,6 +122,44 @@ (static_cast(bytes) + n_bytes); } + template <> + inline + float load_big_endian(const void* bytes) + { + const unsigned char *b = reinterpret_cast( + bytes); + b += 3; + + float value; + unsigned char *v = reinterpret_cast(&value); + + for(std::size_t i = 0; i < 4; ++i) + { + *v++ = *b--; + } + + return value; + } + + template <> + inline + double load_big_endian(const void* bytes) + { + const unsigned char *b = reinterpret_cast( + bytes); + b += 7; + + double value; + unsigned char *v = reinterpret_cast(&value); + + for(std::size_t i = 0; i < 8; ++i) + { + *v++ = *b--; + } + + return value; + } + template inline T load_little_endian(const void* bytes) @@ -130,6 +168,42 @@ (static_cast(bytes)); } + template <> + inline + float load_little_endian(const void* bytes) + { + const unsigned char *b = reinterpret_cast( + bytes); + + float value; + unsigned char *v = reinterpret_cast(&value); + + for(std::size_t i = 0; i < 4; ++i) + { + *v++ = *b++; + } + + return value; + } + + template <> + inline + double load_little_endian(const void* bytes) + { + const unsigned char *b = reinterpret_cast( + bytes); + + double value; + unsigned char *v = reinterpret_cast(&value); + + for(std::size_t i = 0; i < 8; ++i) + { + *v++ = *b++; + } + + return value; + } + template inline void store_big_endian(void* bytes, T value) @@ -138,6 +212,38 @@ (static_cast(bytes) + n_bytes, value); } + template <> + inline + void store_big_endian(void* bytes, float value) + { + unsigned char *b = reinterpret_cast(bytes); + b += 3; + + const unsigned char *v = reinterpret_cast( + &value); + + for(std::size_t i = 0; i < 4; ++i) + { + *b-- = *v++; + } + } + + template <> + inline + void store_big_endian(void* bytes, double value) + { + unsigned char *b = reinterpret_cast(bytes); + b += 7; + + const unsigned char *v = reinterpret_cast( + &value); + + for(std::size_t i = 0; i < 8; ++i) + { + *b-- = *v++; + } + } + template inline void store_little_endian(void* bytes, T value) @@ -146,6 +252,36 @@ (static_cast(bytes), value); } + template <> + inline + void store_little_endian(void* bytes, float value) + { + unsigned char *b = reinterpret_cast(bytes); + + const unsigned char *v = reinterpret_cast( + &value); + + for(std::size_t i = 0; i < 4; ++i) + { + *b++ = *v++; + } + } + + template <> + inline + void store_little_endian(void* bytes, double value) + { + unsigned char *b = reinterpret_cast(bytes); + + const unsigned char *v = reinterpret_cast( + &value); + + for(std::size_t i = 0; i < 8; ++i) + { + *b++ = *v++; + } + } + } // namespace detail namespace integer