USGS

Isis 3.0 Developer's Reference (API)

Home

Endian.h

Go to the documentation of this file.
00001 
00024 #if !defined(Endian_h)
00025 #define Endian_h
00026 
00027 #include "iString.h"
00028 
00029 namespace Isis {
00059   enum ByteOrder {
00060     NoByteOrder = 0,
00061     Lsb,
00062     Msb
00063   };
00064 
00065   inline std::string ByteOrderName(Isis::ByteOrder byteOrder) {
00066     if(byteOrder == Isis::NoByteOrder) return "None";
00067     if(byteOrder == Isis::Lsb) return "Lsb";
00068     if(byteOrder == Isis::Msb) return "Msb";
00069     return "Error";
00070   }
00071 
00072   inline Isis::ByteOrder ByteOrderEnumeration(const std::string &order) {
00073     Isis::iString temp(order);
00074     temp = temp.UpCase();
00075     if(temp == "LSB") return Isis::Lsb;
00076     if(temp == "MSB") return Isis::Msb;
00077     return Isis::NoByteOrder;
00078   }
00079 
00085   inline bool IsLsb() {
00086     union {
00087       short a;
00088       char b[2];
00089     } test;
00090 
00091     test.a = 1;
00092     if(test.b[0] == 0) return false;
00093     return true;
00094   }
00095 
00101   inline bool IsMsb() {
00102     return !Isis::IsLsb();
00103   }
00104 
00112   inline bool IsLittleEndian() {
00113     return IsLsb();
00114   }
00115 
00123   inline bool IsBigEndian() {
00124     return !Isis::IsLsb();
00125   }
00126 }
00127 
00128 #endif
00129