MrSID Decode SDK for LiDAR Reference Manual
1.1.4.4709
|
00001 /* ////////////////////////////////////////////////////////////////////////// 00002 // // 00003 // This code is Copyright (c) 2008-2010 LizardTech, Inc, 1008 Western // 00004 // Avenue, Suite 200, Seattle, WA 98104. Unauthorized use or distribution // 00005 // prohibited. Access to and use of this code is permitted only under // 00006 // license from LizardTech, Inc. Portions of the code are protected by // 00007 // US and foreign patents and other filings. All Rights Reserved. // 00008 // // 00010 /* PUBLIC */ 00011 00012 #ifndef __LIDAR_ENDIAN_H__ 00013 #define __LIDAR_ENDIAN_H__ 00014 00015 #include "lidar/Base.h" 00016 00017 LT_BEGIN_LIDAR_NAMESPACE 00018 00020 #define HOST_IS_BIG_ENDIAN (Endian().isHostBigEndian()) 00021 00022 #define HOST_IS_LITTLE_ENDIAN (Endian().isHostLittleEndian()) 00023 00030 class Endian 00031 { 00032 public: 00033 Endian(void) : word(1) {} 00034 00041 bool isHostBigEndian(void) const { return byte[sizeof(int) - 1] == 1; } 00048 bool isHostLittleEndian(void) const { return byte[0] == 1; } 00049 00050 00059 template<size_t size> static void swap(void *buffer) 00060 { 00061 unsigned char *head = static_cast<unsigned char *>(buffer); 00062 unsigned char *tail = head + size - 1; 00063 while(head < tail) 00064 { 00065 unsigned char temp = *head; 00066 *head++ = *tail; 00067 *tail-- = temp; 00068 } 00069 } 00070 00079 static void swap(void *buffer, size_t size) 00080 { 00081 unsigned char *head = static_cast<unsigned char *>(buffer); 00082 unsigned char *tail = head + size - 1; 00083 while(head < tail) 00084 { 00085 unsigned char temp = *head; 00086 *head++ = *tail; 00087 *tail-- = temp; 00088 } 00089 } 00090 00091 protected: 00092 const union { int word; char byte[sizeof(int)]; }; 00093 }; 00094 00095 00096 LT_END_LIDAR_NAMESPACE 00097 #endif // __LIDAR_ENDIAN_H__