Isis Developer Reference
Endian.h
Go to the documentation of this file.
1#ifndef Endian_h
2#define Endian_h
8/* SPDX-License-Identifier: CC0-1.0 */
9
10#include <QString>
11
12namespace Isis {
47
48 inline QString ByteOrderName(Isis::ByteOrder byteOrder) {
49 if(byteOrder == Isis::NoByteOrder) return "None";
50 if(byteOrder == Isis::Lsb) return "Lsb";
51 if(byteOrder == Isis::Msb) return "Msb";
52 return "Error";
53 }
54
55 inline Isis::ByteOrder ByteOrderEnumeration(const QString &order) {
56 QString temp = order.toUpper();
57 if(temp == "LSB") return Isis::Lsb;
58 if(temp == "MSB") return Isis::Msb;
59 return Isis::NoByteOrder;
60 }
61
67 inline bool IsLsb() {
68 union {
69 short a;
70 char b[2];
71 } test;
72
73 test.a = 1;
74 if(test.b[0] == 0) return false;
75 return true;
76 }
77
83 inline bool IsMsb() {
84 return !Isis::IsLsb();
85 }
86
94 inline bool IsLittleEndian() {
95 return IsLsb();
96 }
97
105 inline bool IsBigEndian() {
106 return !Isis::IsLsb();
107 }
108}
109
110#endif
111
ByteOrder
Tests the current architecture for byte order.
Definition Endian.h:42
@ NoByteOrder
Definition Endian.h:43
@ Msb
Definition Endian.h:45
@ Lsb
Definition Endian.h:44
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition Endian.h:67
Isis::ByteOrder ByteOrderEnumeration(const QString &order)
Definition Endian.h:55
bool IsLittleEndian()
Definition Endian.h:94
QString ByteOrderName(Isis::ByteOrder byteOrder)
Definition Endian.h:48
bool IsBigEndian()
Definition Endian.h:105
bool IsMsb()
Return true if this host is an MSB first machine and false if it is not.
Definition Endian.h:83