MrSID Decode SDK for LiDAR Reference Manual 1.1.5.5244
Endian.h
Go to the documentation of this file.
1//
2// This code is property of Celartem, Inc dba Extensis.
3// Copyright (c) 1995-2023. All rights reserved.
4// Use permitted only under license from Extensis.
5//
6/* PUBLIC */
7
8#ifndef __LIDAR_ENDIAN_H__
9#define __LIDAR_ENDIAN_H__
10
11#include "lidar/Base.h"
12
13LT_BEGIN_LIDAR_NAMESPACE
14
16#define HOST_IS_BIG_ENDIAN (Endian().isHostBigEndian())
18#define HOST_IS_LITTLE_ENDIAN (Endian().isHostLittleEndian())
19
26class Endian
27{
28public:
29 Endian(void) : word(1) {}
30
37 bool isHostBigEndian(void) const { return byte[sizeof(int) - 1] == 1; }
44 bool isHostLittleEndian(void) const { return byte[0] == 1; }
45
46
55 template<size_t size> static void swap(void *buffer)
56 {
57 unsigned char *head = static_cast<unsigned char *>(buffer);
58 unsigned char *tail = head + size - 1;
59 while(head < tail)
60 {
61 unsigned char temp = *head;
62 *head++ = *tail;
63 *tail-- = temp;
64 }
65 }
66
75 static void swap(void *buffer, size_t size)
76 {
77 unsigned char *head = static_cast<unsigned char *>(buffer);
78 unsigned char *tail = head + size - 1;
79 while(head < tail)
80 {
81 unsigned char temp = *head;
82 *head++ = *tail;
83 *tail-- = temp;
84 }
85 }
86
87protected:
88 const union { int word; char byte[sizeof(int)]; };
89};
90
91
92LT_END_LIDAR_NAMESPACE
93#endif // __LIDAR_ENDIAN_H__
Endian is a helper class that figures out the host's byte order.
Definition: Endian.h:27
bool isHostLittleEndian(void) const
Determine if the host is little endian.
Definition: Endian.h:44
Endian(void)
Definition: Endian.h:29
bool isHostBigEndian(void) const
Determine if the host is big endian.
Definition: Endian.h:37
static void swap(void *buffer, size_t size)
Swap byte order.
Definition: Endian.h:75
static void swap(void *buffer)
Swap byte order.
Definition: Endian.h:55
int word
Definition: Endian.h:88

Extensis