ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkByteSwapper.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18/*=========================================================================
19 *
20 * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21 *
22 * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23 *
24 * For complete copyright, license and disclaimer of warranty information
25 * please refer to the NOTICE file at the top of the ITK source tree.
26 *
27 *=========================================================================*/
28#ifndef itkByteSwapper_h
29#define itkByteSwapper_h
30
31#include "itkObject.h"
32#include "itkObjectFactory.h"
33#include "itkIntTypes.h"
34
35#if __has_include(<version>)
36# include <version>
37#endif
38#if defined(__cpp_lib_endian) // ABI-neutral
39# include <bit>
40#endif
41
42namespace itk
43{
55
56template <typename T>
57class ITK_TEMPLATE_EXPORT ByteSwapper : public Object
58{
59public:
60 ITK_DISALLOW_COPY_AND_MOVE(ByteSwapper);
61
67
68#ifndef ITK_FUTURE_LEGACY_REMOVE
70 using OStreamType
71 [[deprecated("ByteSwapper::OStreamType is deprecated from ITK 6. Just use `std::ostream` instead!")]] =
72 std::ostream;
73#endif
74
76 itkOverrideGetNameOfClassMacro(ByteSwapper);
77
80 static constexpr bool
82 {
84 }
85
86 static constexpr bool
88 {
89 return SystemIsBigEndian();
90 }
91 static constexpr bool
96
97 static constexpr bool
99 {
100 return SystemIsLittleEndian();
101 }
102
108 static void
110
114
120 static void
122
130 static void
131 SwapWriteRangeFromSystemToBigEndian(const T * p, int num, std::ostream * fp);
132
138 static void
140
146 static void
148
156 static void
157 SwapWriteRangeFromSystemToLittleEndian(const T * p, int num, std::ostream * fp);
158
159protected:
160 ByteSwapper() = default;
161 ~ByteSwapper() override = default;
162
163private:
166 static void
168
170 static void
171 SwapWriteRange(const T * buffer, SizeValueType numberOfElements, std::ostream & outputStream);
172
173 static constexpr bool m_SystemIsBigEndian{
174#if defined(__cpp_lib_endian) // ABI-neutral
175 std::endian::native == std::endian::big
176#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
177 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
178#elif defined(__BIG_ENDIAN__)
179 true
180#elif defined(__LITTLE_ENDIAN__) || defined(_WIN32)
181 false
182#else
183# error "The byte order of the target architecture is unknown to this compiler."
184#endif
185 };
186};
187} // end namespace itk
188
189#ifndef ITK_MANUAL_INSTANTIATION
190# include "itkByteSwapper.hxx"
191#endif
192
193#endif
static void SwapBytes(T &)
static constexpr bool SystemIsBE()
static void SwapWriteRange(const T *buffer, SizeValueType numberOfElements, std::ostream &outputStream)
static void SwapWriteRangeFromSystemToLittleEndian(const T *p, int num, std::ostream *fp)
SmartPointer< const Self > ConstPointer
static constexpr bool SystemIsBigEndian()
static constexpr bool m_SystemIsBigEndian
static constexpr bool SystemIsLE()
static void SwapRangeFromSystemToLittleEndian(T *p, BufferSizeType num)
SizeValueType BufferSizeType
ByteSwapper()=default
~ByteSwapper() override=default
static constexpr bool SystemIsLittleEndian()
static void SwapWriteRangeFromSystemToBigEndian(const T *p, int num, std::ostream *fp)
static void SwapFromSystemToLittleEndian(T *p)
SmartPointer< Self > Pointer
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
static void SwapFromSystemToBigEndian(T *p)
Implements transparent reference counting.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:82