MrSID Decode SDK for LiDAR Reference Manual
1.1.3.4427
Main Page
Classes
Files
File List
File Members
Endian.h
Go to the documentation of this file.
1
/* //////////////////////////////////////////////////////////////////////////
2
// //
3
// This code is Copyright (c) 2008-2010 LizardTech, Inc, 1008 Western //
4
// Avenue, Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
5
// prohibited. Access to and use of this code is permitted only under //
6
// license from LizardTech, Inc. Portions of the code are protected by //
7
// US and foreign patents and other filings. All Rights Reserved. //
8
// //
10
/* PUBLIC */
11
12
#ifndef __LIDAR_ENDIAN_H__
13
#define __LIDAR_ENDIAN_H__
14
15
#include "
lidar/Base.h
"
16
17
LT_BEGIN_LIDAR_NAMESPACE
18
20
#define HOST_IS_BIG_ENDIAN (Endian().isHostBigEndian())
21
22
#define HOST_IS_LITTLE_ENDIAN (Endian().isHostLittleEndian())
23
30
class
Endian
31
{
32
public
:
33
Endian
(
void
) :
word
(1) {}
34
41
bool
isHostBigEndian
(
void
)
const
{
return
byte
[
sizeof
(int) - 1] == 1; }
48
bool
isHostLittleEndian
(
void
)
const
{
return
byte
[0] == 1; }
49
50
59
template
<
size_t
size>
static
void
swap
(
void
*buffer)
60
{
61
unsigned
char
*head =
static_cast<
unsigned
char
*
>
(buffer);
62
unsigned
char
*tail = head + size - 1;
63
while
(head < tail)
64
{
65
unsigned
char
temp = *head;
66
*head++ = *tail;
67
*tail-- = temp;
68
}
69
}
70
79
static
void
swap
(
void
*buffer,
size_t
size)
80
{
81
unsigned
char
*head =
static_cast<
unsigned
char
*
>
(buffer);
82
unsigned
char
*tail = head + size - 1;
83
while
(head < tail)
84
{
85
unsigned
char
temp = *head;
86
*head++ = *tail;
87
*tail-- = temp;
88
}
89
}
90
91
protected
:
92
const
union
{
int
word
;
char
byte
[
sizeof
(int)]; };
93
};
94
95
96
LT_END_LIDAR_NAMESPACE
97
#endif // __LIDAR_ENDIAN_H__
LizardTech