diff --git a/datraw/datraw/endianness.h b/datraw/datraw/endianness.h index fd894fd..b9dfe0f 100644 --- a/datraw/datraw/endianness.h +++ b/datraw/datraw/endianness.h @@ -1,28 +1,35 @@ // -// Copyright © 2017 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. +// Copyright © 2017 - 2023 Visualisierungsinstitut der Universität Stuttgart. Alle Rechte vorbehalten. // // Christoph Müller #pragma once +#include + namespace datraw { /// /// Represents endianness of a data set or system. /// - enum class endianness { + enum class endianness : std::uint32_t { /// /// The least significant byte is stored first, like on Intel x86 or /// AMD64 architectures. /// - little = 1, + little = 0x03020100, /// /// The most significant byte is stored first, like on Sun Spark. /// - big + big = 0x00010203, + + /// + /// The native endian of the system the code is running on. + /// + system = '\0\1\2\3' }; } diff --git a/datraw/datraw/info.h b/datraw/datraw/info.h index f8b9423..671df59 100644 --- a/datraw/datraw/info.h +++ b/datraw/datraw/info.h @@ -704,7 +704,13 @@ namespace datraw { /// /// Answer the endianness of the system we are running on. /// - static datraw::endianness sys_endianness(void); + /// + /// This method is provided for backwards compatibility. New code should + /// use . + /// + static constexpr datraw::endianness sys_endianness(void) noexcept { + return endianness::system; + } /// /// Split a range of characters at positions designated by diff --git a/datraw/datraw/info.inl b/datraw/datraw/info.inl index f479a78..f81572a 100644 --- a/datraw/datraw/info.inl +++ b/datraw/datraw/info.inl @@ -832,25 +832,6 @@ template I datraw::info::skip_spaces(I it, I end) { } -/* - * datraw::info::sys_endianness - */ -template -datraw::endianness datraw::info::sys_endianness(void) { - static const union { - std::uint32_t u; - std::uint8_t b[4]; - } BYTES = { 0x01020304 }; - - switch (BYTES.b[0]) { - case 0x01: return endianness::big; - case 0x04: return endianness::little; - default: throw std::runtime_error("Unknown endianness. This should " - "never happen!"); - } -} - - /* * datraw::info::tokenise */