From ccb6c3490f85a5eb5fee79c8724f8f42b519b003 Mon Sep 17 00:00:00 2001 From: Pietro Incardona <incardon@mpi-cbg.de> Date: Tue, 21 Feb 2017 15:08:39 +0100 Subject: [PATCH] Adding missing file --- src/VTKWriter/byteswap_portable.hpp | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/VTKWriter/byteswap_portable.hpp diff --git a/src/VTKWriter/byteswap_portable.hpp b/src/VTKWriter/byteswap_portable.hpp new file mode 100644 index 0000000..70d05c9 --- /dev/null +++ b/src/VTKWriter/byteswap_portable.hpp @@ -0,0 +1,41 @@ +/* + * byteswap_portable.hpp + * + * Created on: Feb 20, 2017 + * Author: i-bird + */ + +#ifndef OPENFPM_IO_SRC_VTKWRITER_BYTESWAP_PORTABLE_HPP_ +#define OPENFPM_IO_SRC_VTKWRITER_BYTESWAP_PORTABLE_HPP_ + +#include <climits> + +/*! \brief This function swap byte from little endian to big endian format + * + * \warning in the case of big-endian machine this function should do nothing. + * Unfortunately this is not the case because I never had the bad luck + * of getting one + * + * \param T value to convert + * + */ +template <typename T> +T swap_endian_lt(T u) +{ + static_assert (CHAR_BIT == 8, "CHAR_BIT != 8"); + + union + { + T u; + unsigned char u8[sizeof(T)]; + } source, dest; + + source.u = u; + + for (size_t k = 0; k < sizeof(T); k++) + dest.u8[k] = source.u8[sizeof(T) - k - 1]; + + return dest.u; +} + +#endif /* OPENFPM_IO_SRC_VTKWRITER_BYTESWAP_PORTABLE_HPP_ */ -- GitLab