//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. //============================================================================ #ifndef vtk_m_io_internal_Endian_h #define vtk_m_io_internal_Endian_h #include #include #include namespace vtkm { namespace io { namespace internal { inline bool IsLittleEndian() { static constexpr vtkm::Int16 i16 = 0x1; const vtkm::Int8* i8p = reinterpret_cast(&i16); return (*i8p == 1); } template inline void FlipEndianness(std::vector& buffer) { vtkm::UInt8* bytes = reinterpret_cast(&buffer[0]); const std::size_t tsize = sizeof(T); const std::size_t bsize = buffer.size(); for (std::size_t i = 0; i < bsize; i++, bytes += tsize) { std::reverse(bytes, bytes + tsize); } } template inline void FlipEndianness(std::vector>& buffer) { vtkm::UInt8* bytes = reinterpret_cast(&buffer[0]); const std::size_t tsize = sizeof(T); const std::size_t bsize = buffer.size(); for (std::size_t i = 0; i < bsize; i++) { for (vtkm::IdComponent j = 0; j < N; j++, bytes += tsize) { std::reverse(bytes, bytes + tsize); } } } } } } // vtkm::io::internal #endif //vtk_m_io_internal_Endian_h