diff options
author | Gard Spreemann <gspreemann@gmail.com> | 2017-10-16 17:07:15 +0200 |
---|---|---|
committer | Gard Spreemann <gspreemann@gmail.com> | 2017-10-16 17:07:15 +0200 |
commit | 7c879fa8d9f609ecc29c13e1c59ce309b9eeb046 (patch) | |
tree | b38d01d348eace7265f2f412c1295ac9487c3672 | |
parent | e91f1b9d6987dda58498b8386eba191436b6f6d2 (diff) |
Boost-less endian conversion.gspr/flexible-output
-rw-r--r-- | ripser.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
@@ -37,10 +37,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <sstream> #include <unordered_map> -#ifndef FORCE_NATIVE_ENDIANNESS -#include <boost/endian/conversion.hpp> -#endif - #ifdef USE_GOOGLE_HASHMAP #include <sparsehash/sparse_hash_map> template <class Key, class T> class hash_map : public google::sparse_hash_map<Key, T> { @@ -109,18 +105,23 @@ std::vector<coefficient_t> multiplicative_inverse_vector(const coefficient_t m) return inverse; } +template <typename T> inline void reverse_endianness(T & x) { + uint8_t * p = reinterpret_cast<uint8_t *>(&x); + std::reverse(p, p + sizeof(T)); +} + template <typename T> T read(std::istream& s) { T result; s.read(reinterpret_cast<char*>(&result), sizeof(T)); - #ifndef FORCE_NATIVE_ENDIANNESS - boost::endian::little_to_native_inplace(result); + #ifdef BIGENDIAN + reverse_endianness(result); #endif return result; } template <typename T> 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<char*>(&value), sizeof(T)); } |