ByteOrder.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_ByteOrder_hxx
00024 #define __ccxx_ByteOrder_hxx
00025
00026 #include <commonc++/Common.h++>
00027
00028 #ifdef CCXX_OS_POSIX
00029 #include <netinet/in.h>
00030 #endif
00031
00032 namespace ccxx {
00033
00039 class COMMONCPP_API ByteOrder
00040 {
00041 public:
00042
00044 inline static uint16_t hostToNetwork(uint16_t n) throw()
00045 { return(htons(n)); }
00046
00048 inline static uint32_t hostToNetwork(uint32_t n) throw()
00049 { return(htonl(n)); }
00050
00052 static uint64_t hostToNetwork(uint64_t n) throw();
00053
00055 inline static uint16_t networkToHost(uint16_t n) throw()
00056 { return(ntohs(n)); }
00057
00059 inline static uint32_t networkToHost(uint32_t n) throw()
00060 { return(ntohl(n)); }
00061
00063 static uint64_t networkToHost(uint64_t n) throw();
00064
00070 static bool isBigEndian() throw();
00071
00077 inline static bool isLittleEndian() throw()
00078 { return(!isBigEndian()); }
00079
00084 inline static Endianness getEndianness() throw()
00085 { return(isBigEndian() ? BigEndian : LittleEndian); }
00086
00093 template<typename T> static T & reverseBytes(T &value) throw()
00094 {
00095 _reverseBytes(reinterpret_cast<byte_t *>(&value), sizeof(T));
00096 return(value);
00097 }
00098
00099 private:
00100
00101 static void _reverseBytes(byte_t *buf, size_t length) throw();
00102
00103 ByteOrder();
00104 CCXX_COPY_DECLS(ByteOrder);
00105 };
00106
00107 };
00108
00109 #endif // __ccxx_ByteOrder_hxx
00110
00111