Isis 3 Programmer Reference
Endian.h
1 #ifndef Endian_h
2 #define Endian_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 #include <QString>
11 
12 namespace Isis {
42  enum ByteOrder {
43  NoByteOrder = 0,
44  Lsb,
45  Msb
46  };
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 
Isis::IsLsb
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition: Endian.h:67
Isis::ByteOrder
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:42
Isis::IsMsb
bool IsMsb()
Return true if this host is an MSB first machine and false if it is not.
Definition: Endian.h:83
Isis::IsLittleEndian
bool IsLittleEndian()
Definition: Endian.h:94
Isis::IsBigEndian
bool IsBigEndian()
Definition: Endian.h:105
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16