From 7c879fa8d9f609ecc29c13e1c59ce309b9eeb046 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Mon, 16 Oct 2017 17:07:15 +0200 Subject: Boost-less endian conversion. --- ripser.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ripser.cpp b/ripser.cpp index b0257c8..a3d5318 100644 --- a/ripser.cpp +++ b/ripser.cpp @@ -37,10 +37,6 @@ with this program. If not, see . #include #include -#ifndef FORCE_NATIVE_ENDIANNESS -#include -#endif - #ifdef USE_GOOGLE_HASHMAP #include template class hash_map : public google::sparse_hash_map { @@ -109,18 +105,23 @@ std::vector multiplicative_inverse_vector(const coefficient_t m) return inverse; } +template inline void reverse_endianness(T & x) { + uint8_t * p = reinterpret_cast(&x); + std::reverse(p, p + sizeof(T)); +} + template T read(std::istream& s) { T result; s.read(reinterpret_cast(&result), sizeof(T)); - #ifndef FORCE_NATIVE_ENDIANNESS - boost::endian::little_to_native_inplace(result); + #ifdef BIGENDIAN + reverse_endianness(result); #endif return result; } template void write(std::ostream& s, T value) { - #ifndef FORCE_NATIVE_ENDIANNESS - boost::endian::native_to_little_inplace(value); + #ifdef BIGENDIAN + reverse_endianness(value); #endif s.write(reinterpret_cast(&value), sizeof(T)); } -- cgit v1.2.3