Odil
A C++11 library for the DICOM standard
Toggle main menu visibility
Loading...
Searching...
No Matches
endian.h
Go to the documentation of this file.
1
/*************************************************************************
2
* odil - Copyright (C) Universite de Strasbourg
3
* Distributed under the terms of the CeCILL-B license, as published by
4
* the CEA-CNRS-INRIA. Refer to the LICENSE file or to
5
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
6
* for details.
7
************************************************************************/
8
9
#ifndef _05d00816_25d0_41d1_9768_afd39f0503da
10
#define _05d00816_25d0_41d1_9768_afd39f0503da
11
12
#include "
odil/odil.h
"
13
14
#define ODIL_SWAP \
15
auto source = reinterpret_cast<char const *>(&value); \
16
auto const end = source + sizeof(value); \
17
T result; \
18
auto destination = reinterpret_cast<char *>(&result) + sizeof(result) - 1; \
19
while(source != end) \
20
{ \
21
*destination = *source; \
22
++source; \
23
--destination; \
24
}
25
26
namespace
odil
27
{
28
29
enum class
ODIL_API
ByteOrdering
30
{
31
LittleEndian
,
32
BigEndian
33
};
34
35
ByteOrdering
ODIL_API
get_endianness
();
36
37
extern
ODIL_API
ByteOrdering
const
byte_ordering
;
38
39
template
<
typename
T>
40
T
host_to_big_endian
(T
const
& value)
41
{
42
if
(
byte_ordering
==
ByteOrdering::LittleEndian
)
43
{
44
ODIL_SWAP
45
return
result;
46
}
47
else
48
{
49
return
value;
50
}
51
}
52
53
template
<
typename
T>
54
T
host_to_little_endian
(T
const
& value)
55
{
56
if
(
byte_ordering
==
ByteOrdering::BigEndian
)
57
{
58
ODIL_SWAP
59
return
result;
60
}
61
else
62
{
63
return
value;
64
}
65
}
66
67
template
<
typename
T>
68
T
big_endian_to_host
(T
const
& value)
69
{
70
if
(
byte_ordering
==
ByteOrdering::LittleEndian
)
71
{
72
ODIL_SWAP
73
return
result;
74
}
75
else
76
{
77
return
value;
78
}
79
}
80
81
template
<
typename
T>
82
T
little_endian_to_host
(T
const
& value)
83
{
84
if
(
byte_ordering
==
ByteOrdering::BigEndian
)
85
{
86
ODIL_SWAP
87
return
result;
88
}
89
else
90
{
91
return
value;
92
}
93
}
94
95
}
96
97
#undef ODIL_SWAP
98
99
#endif
// _05d00816_25d0_41d1_9768_afd39f0503da
ODIL_SWAP
#define ODIL_SWAP
Definition
endian.h:14
odil
Definition
Association.h:25
odil::byte_ordering
ByteOrdering const byte_ordering
odil::host_to_little_endian
T host_to_little_endian(T const &value)
Definition
endian.h:54
odil::big_endian_to_host
T big_endian_to_host(T const &value)
Definition
endian.h:68
odil::get_endianness
ByteOrdering get_endianness()
odil::ByteOrdering
ByteOrdering
Definition
endian.h:30
odil::ByteOrdering::BigEndian
@ BigEndian
Definition
endian.h:32
odil::ByteOrdering::LittleEndian
@ LittleEndian
Definition
endian.h:31
odil::host_to_big_endian
T host_to_big_endian(T const &value)
Definition
endian.h:40
odil::little_endian_to_host
T little_endian_to_host(T const &value)
Definition
endian.h:82
odil.h
ODIL_API
#define ODIL_API
Definition
odil.h:28
src
odil
endian.h
Generated by
1.17.0