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
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef PCL_IO_PLY_BYTE_ORDER_H
00041 #define PCL_IO_PLY_BYTE_ORDER_H
00042
00043 namespace pcl
00044 {
00045 namespace io
00046 {
00047 namespace ply
00048 {
00055 #if defined (PLY_BIG_ENDIAN) || defined (PLY_LITTLE_ENDIAN)
00056 # error
00057 #endif
00058
00059 #if (defined (__powerpc) || defined (__powerpc__) || defined (__POWERPC__) || defined (__ppc__) || defined (_M_PPC) || defined (__ARCH_PPC))
00060 # define PLY_BIG_ENDIAN
00061 #elif (defined (i386) || defined (__i386__) || defined (__i386) || defined (_M_IX86) || defined (_X86_) || defined (__THW_INTEL__) || defined (__I86__) || defined (__INTEL__)) \
00062 || (defined (__amd64__) || defined (__amd64) || defined (__x86_64__) || defined (__x86_64) || defined (_M_X64) || defined (ANDROID))
00063 # define PLY_LITTLE_ENDIAN
00064 #else
00065 # error
00066 #endif
00067
00068 enum byte_order
00069 {
00070 little_endian_byte_order,
00071 big_endian_byte_order,
00072 #if defined (PLY_BIG_ENDIAN)
00073 host_byte_order = big_endian_byte_order,
00074 #elif defined (PLY_LITTLE_ENDIAN)
00075 host_byte_order = little_endian_byte_order,
00076 #else
00077 # error
00078 #endif
00079 network_byte_order = big_endian_byte_order
00080 };
00081
00082 #undef PLY_BIG_ENDIAN
00083 #undef PLY_LITTLE_ENDIAN
00084
00085 template <std::size_t N>
00086 void swap_byte_order (char* bytes);
00087
00088 template <>
00089 inline void swap_byte_order<1> (char*) {}
00090
00091 template <>
00092 inline void swap_byte_order<2> (char* bytes)
00093 {
00094 std::swap (bytes[0], bytes[1]);
00095 }
00096
00097 template <>
00098 inline void swap_byte_order<4> (char* bytes)
00099 {
00100 std::swap (bytes[0], bytes[3]);
00101 std::swap (bytes[1], bytes[2]);
00102 }
00103
00104 template <>
00105 inline void swap_byte_order<8> (char* bytes)
00106 {
00107 std::swap (bytes[0], bytes[7]);
00108 std::swap (bytes[1], bytes[6]);
00109 std::swap (bytes[2], bytes[5]);
00110 std::swap (bytes[3], bytes[4]);
00111 }
00112
00113 template <typename T>
00114 void swap_byte_order (T& value)
00115 {
00116 swap_byte_order<sizeof (T)> (reinterpret_cast<char*> (&value));
00117 }
00118
00119 }
00120 }
00121 }
00122
00123 #endif // PLY_BYTE_ORDER_H