File endianness.h
File List > code_source > templat > include > TempLat > util > endianness.h
Go to the documentation of this file
#ifndef TEMPLAT_UTIL_ENDIANNESS_H
#define TEMPLAT_UTIL_ENDIANNESS_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Wessel Valkenburg, Year: 2019
#include <cstdint>
namespace TempLat
{
class Endianness
{
public:
// Put public methods here. These should change very little over time.
Endianness() : mIsLittleEndian(true)
{
/* see https://stackoverflow.com/a/1001326/2295722 and the comment about int16_t */
int16_t temp = 0x1234;
char *tempChar = (char *)&temp;
mIsLittleEndian = *tempChar == 0x34;
mIsBigEndian = *tempChar == 0x12;
}
const bool &isLittle() const { return mIsLittleEndian; }
const bool &isBig() const { return mIsBigEndian; }
private:
/* Put all member variables and private methods here. These may change arbitrarily. */
bool mIsLittleEndian, mIsBigEndian;
};
} // namespace TempLat
#endif