Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef ENDIAN_FUNC_HPP
00013 #define ENDIAN_FUNC_HPP
00014
00015 #include "endian_type.hpp"
00016 #include "bitmath_func.hpp"
00017
00018
00019 #if TTD_ENDIAN == TTD_BIG_ENDIAN
00020 #define FROM_BE16(x) (x)
00021 #define FROM_BE32(x) (x)
00022 #define TO_BE16(x) (x)
00023 #define TO_BE32(x) (x)
00024 #define TO_BE32X(x) (x)
00025 #define FROM_LE16(x) BSWAP16(x)
00026 #define FROM_LE32(x) BSWAP32(x)
00027 #define TO_LE16(x) BSWAP16(x)
00028 #define TO_LE32(x) BSWAP32(x)
00029 #define TO_LE32X(x) BSWAP32(x)
00030 #else
00031 #define FROM_BE16(x) BSWAP16(x)
00032 #define FROM_BE32(x) BSWAP32(x)
00033 #define TO_BE16(x) BSWAP16(x)
00034 #define TO_BE32(x) BSWAP32(x)
00035 #define TO_BE32X(x) BSWAP32(x)
00036 #define FROM_LE16(x) (x)
00037 #define FROM_LE32(x) (x)
00038 #define TO_LE16(x) (x)
00039 #define TO_LE32(x) (x)
00040 #define TO_LE32X(x) (x)
00041 #endif
00042
00043 static inline uint16 ReadLE16Aligned(const void *x)
00044 {
00045 return FROM_LE16(*(const uint16*)x);
00046 }
00047
00048 static inline uint16 ReadLE16Unaligned(const void *x)
00049 {
00050 #if OTTD_ALIGNMENT == 1
00051 return ((const byte*)x)[0] | ((const byte*)x)[1] << 8;
00052 #else
00053 return FROM_LE16(*(const uint16*)x);
00054 #endif
00055 }
00056
00057 #endif