ITK  6.0.0
Insight Toolkit
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
35namespace itk
36{
49template <typename T>
50class ITK_TEMPLATE_EXPORT ByteSwapper : public Object
51{
52public:
53 ITK_DISALLOW_COPY_AND_MOVE(ByteSwapper);
54
60
61#ifndef ITK_FUTURE_LEGACY_REMOVE
63 using OStreamType
64 [[deprecated("ByteSwapper::OStreamType is deprecated from ITK 6. Just use `std::ostream` instead!")]] =
65 std::ostream;
66#endif
67
69 itkOverrideGetNameOfClassMacro(ByteSwapper);
70
73 static constexpr bool
75 {
76 return m_SystemIsBigEndian;
77 }
78
79 static constexpr bool
81 {
82 return SystemIsBigEndian();
83 }
84 static constexpr bool
86 {
87 return !m_SystemIsBigEndian;
88 }
89
90 static constexpr bool
92 {
93 return SystemIsLittleEndian();
94 }
95
101 static void
103
107
113 static void
115
123 static void
124 SwapWriteRangeFromSystemToBigEndian(const T * p, int num, std::ostream * fp);
132 static void
134
140 static void
142
150 static void
151 SwapWriteRangeFromSystemToLittleEndian(const T * p, int num, std::ostream * fp);
154protected:
155 ByteSwapper() = default;
156 ~ByteSwapper() override = default;
157
158private:
161 static void
163
165 static void
166 SwapWriteRange(const T * ptr, SizeValueType numberOfElements, std::ostream & outputStream);
167
168 static constexpr bool m_SystemIsBigEndian{
169#ifdef CMAKE_WORDS_BIGENDIAN
170 true
171#else
172 false
173#endif
174 };
175};
176} // end namespace itk
177
178#ifndef ITK_MANUAL_INSTANTIATION
179# include "itkByteSwapper.hxx"
180#endif
181
182#endif
Perform machine dependent byte swapping.
static void SwapBytes(T &)
static constexpr bool SystemIsBE()
static void SwapWriteRangeFromSystemToLittleEndian(const T *p, int num, std::ostream *fp)
static constexpr bool 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 SwapWriteRange(const T *ptr, SizeValueType numberOfElements, std::ostream &outputStream)
static void SwapFromSystemToLittleEndian(T *p)
static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num)
static void SwapFromSystemToBigEndian(T *p)
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition: itkIntTypes.h:86