Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

endian.hpp

Go to the documentation of this file.
00001 #ifndef ENDIAN_HPP
00002 #define ENDIAN_HPP
00003 
00004 
00005 // check for GNU autoconf definitions
00006 #ifdef WORDS_BIGENDIAN
00007 #  define BIG_ENDIAN
00008 #else
00009 #  ifndef LITTLE_ENDIAN
00010 #    define LITTLE_ENDIAN
00011 #  endif
00012 #endif
00013 
00014 
00015 #include "config.h"
00016 
00017 
00018 // these aren't implemented in the nicest ways...
00019 template<typename T>
00020 void Swap(T& a, T& b) {
00021   T c = a;
00022   a = b;
00023   b = c;
00024 }
00025 
00026 
00027 inline adr_u32 SwapEndianness32(adr_u32 value) {
00028   adr_u8* u8 = (adr_u8*)&value;
00029   Swap(u8[0], u8[3]);
00030   Swap(u8[1], u8[2]);
00031   return value;
00032 }
00033 
00034 
00035 #ifdef LITTLE_ENDIAN
00036 
00037 
00038   inline adr_u32 LittleToHost32(adr_u32 value) {
00039     return value;
00040   }
00041 
00042   inline adr_u32 BigToHost32(adr_u32 value) {
00043     return SwapEndianness32(value);
00044   }
00045 
00046 
00047 #elif defined(BIG_ENDIAN)
00048 
00049 
00050   inline adr_u32 LittleToHost32(adr_u32 value) {
00051     return SwapEndianness32(value);
00052   }
00053 
00054   inline adr_u32 BigToHost32(adr_u32 value) {
00055     return value;
00056   }
00057 
00058 
00059 #else
00060 
00061   #error Define LITTLE_ENDIAN or BIG_ENDIAN!
00062 
00063 #endif
00064 
00065 
00066 #endif

Generated at Mon Jun 10 02:55:12 2002 for audiere by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001