Isis 3 Developer Reference
Endian.h
Go to the documentation of this file.
1 
24 #ifndef Endian_h
25 #define Endian_h
26 
27 #include <QString>
28 
29 namespace Isis {
59  enum ByteOrder {
61  Lsb,
63  };
64 
65  inline QString ByteOrderName(Isis::ByteOrder byteOrder) {
66  if(byteOrder == Isis::NoByteOrder) return "None";
67  if(byteOrder == Isis::Lsb) return "Lsb";
68  if(byteOrder == Isis::Msb) return "Msb";
69  return "Error";
70  }
71 
72  inline Isis::ByteOrder ByteOrderEnumeration(const QString &order) {
73  QString temp = order.toUpper();
74  if(temp == "LSB") return Isis::Lsb;
75  if(temp == "MSB") return Isis::Msb;
76  return Isis::NoByteOrder;
77  }
78 
84  inline bool IsLsb() {
85  union {
86  short a;
87  char b[2];
88  } test;
89 
90  test.a = 1;
91  if(test.b[0] == 0) return false;
92  return true;
93  }
94 
100  inline bool IsMsb() {
101  return !Isis::IsLsb();
102  }
103 
111  inline bool IsLittleEndian() {
112  return IsLsb();
113  }
114 
122  inline bool IsBigEndian() {
123  return !Isis::IsLsb();
124  }
125 }
126 
127 #endif
128 
Isis::ByteOrder ByteOrderEnumeration(const QString &order)
Definition: Endian.h:72
bool IsLittleEndian()
Definition: Endian.h:111
ByteOrder
Tests the current architecture for byte order.
Definition: Endian.h:59
Definition: Endian.h:62
Definition: Endian.h:60
bool IsBigEndian()
Definition: Endian.h:122
bool IsLsb()
Return true if this host is an LSB first machine and false if it is not.
Definition: Endian.h:84
Definition: Endian.h:61
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
bool IsMsb()
Return true if this host is an MSB first machine and false if it is not.
Definition: Endian.h:100
QString ByteOrderName(Isis::ByteOrder byteOrder)
Definition: Endian.h:65