00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TOOL_ENDIANNESS_HXX_
00023 # define TOOL_ENDIANNESS_HXX_
00024
00025 #include "endianness.hh"
00026
00027 namespace tool
00028 {
00029
00030 inline
00031 uint16_t
00032 extract_unswapped_short(const void* p)
00033 {
00034 return *static_cast<const uint16_t*> (p);
00035 }
00036
00037 inline
00038 uint16_t
00039 extract_swapped_short(const uint16_t s)
00040 {
00041 return (s >> 8) | (s << 8);
00042 }
00043
00044 inline
00045 uint16_t
00046 extract_swapped_short(const void* p)
00047 {
00048 return extract_swapped_short(extract_unswapped_short(p));
00049 }
00050
00051 inline
00052 uint16_t
00053 extract_short(const uint16_t s, bool swapped)
00054 {
00055 return swapped ? extract_swapped_short(s) : s;
00056 }
00057
00058
00059 inline
00060 uint16_t
00061 extract_short(const void* p, bool swapped)
00062 {
00063 return swapped ? extract_swapped_short(p) : extract_unswapped_short(p);
00064 }
00065
00066 inline
00067 uint16_t
00068 extract_big_endian_short(const void *p)
00069 {
00070 const uint8_t *const c = static_cast<const uint8_t*> (p);
00071
00072 return uint16_t (*c) | uint16_t (*(c + 1)) << 8;
00073 }
00074
00075 }
00076
00077 #endif // ! TOOL_ENDIANNESS_HXX_