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 
35 namespace itk
36 {
49 template <typename T>
50 class ITK_TEMPLATE_EXPORT ByteSwapper : public Object
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_MOVE(ByteSwapper);
54 
56  using Self = ByteSwapper;
57  using Superclass = Object;
60 
61 #ifndef ITK_FUTURE_LEGACY_REMOVE
62 
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
102  SwapFromSystemToBigEndian(T * p);
103 
107 
113  static void
114  SwapRangeFromSystemToBigEndian(T * p, BufferSizeType num);
115 
123  static void
124  SwapWriteRangeFromSystemToBigEndian(const T * p, int num, std::ostream * fp);
132  static void
133  SwapFromSystemToLittleEndian(T * p);
134 
140  static void
141  SwapRangeFromSystemToLittleEndian(T * p, BufferSizeType num);
142 
150  static void
151  SwapWriteRangeFromSystemToLittleEndian(const T * p, int num, std::ostream * fp);
154 protected:
155  ByteSwapper() = default;
156  ~ByteSwapper() override = default;
157 
158 private:
161  static void
162  SwapBytes(T &);
163 
165  static void
166  SwapWriteRange(const T * buffer, 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
itkObjectFactory.h
itk::ByteSwapper::SystemIsBE
static constexpr bool SystemIsBE()
Definition: itkByteSwapper.h:80
itk::ByteSwapper::SystemIsLittleEndian
static constexpr bool SystemIsLittleEndian()
Definition: itkByteSwapper.h:85
itk::SmartPointer< Self >
itk::ByteSwapper
Perform machine dependent byte swapping.
Definition: itkByteSwapper.h:50
itkIntTypes.h
itkObject.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::ByteSwapper::SystemIsBigEndian
static constexpr bool SystemIsBigEndian()
Definition: itkByteSwapper.h:74
itk::ByteSwapper::SystemIsLE
static constexpr bool SystemIsLE()
Definition: itkByteSwapper.h:91
itk::ByteSwapper::BufferSizeType
SizeValueType BufferSizeType
Definition: itkByteSwapper.h:106
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:86