ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkByteSwapper.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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_ASSIGN(ByteSwapper);
54 
56  using Self = ByteSwapper;
57  using Superclass = Object;
60 
62  using OStreamType = std::ostream;
63 
65  itkTypeMacro(ByteSwapper, Object);
66 
68  static bool SystemIsBigEndian();
69 
70  static bool SystemIsBE() { return SystemIsBigEndian(); }
71  static bool SystemIsLittleEndian();
72 
73  static bool SystemIsLE() { return SystemIsLittleEndian(); }
74 
80  static void SwapFromSystemToBigEndian(T *p);
81 
85 
91  static void SwapRangeFromSystemToBigEndian(T *p, BufferSizeType num);
92 
100  static void SwapWriteRangeFromSystemToBigEndian(T *p, int num,
101  OStreamType *fp);
103 
109  static void SwapFromSystemToLittleEndian(T *p);
110 
116  static void SwapRangeFromSystemToLittleEndian(T *p, BufferSizeType num);
117 
125  static void SwapWriteRangeFromSystemToLittleEndian(T *p, int num,
126  OStreamType *fp);
128 
129 protected:
130  ByteSwapper() = default;
131  ~ByteSwapper() override = default;
132 
134  static void Swap2(void *p);
135 
138  static void Swap2Range(void *p, BufferSizeType num);
139 
142  static void SwapWrite2Range(void *p, BufferSizeType num, OStreamType *fp);
143 
145  static void Swap4(void *p);
146 
149  static void Swap4Range(void *p, BufferSizeType num);
150 
153  static void SwapWrite4Range(void *p, BufferSizeType num, OStreamType *fp);
154 
156  static void Swap8(void *p);
157 
160  static void Swap8Range(void *p, BufferSizeType num);
161 
164  static void SwapWrite8Range(void *p, BufferSizeType num, OStreamType *fp);
165 };
166 } // end namespace itk
167 
168 #ifndef ITK_MANUAL_INSTANTIATION
169 #include "itkByteSwapper.hxx"
170 #endif
171 
172 #endif
static bool SystemIsBE()
unsigned long SizeValueType
Definition: itkIntTypes.h:83
static bool SystemIsLE()
SizeValueType BufferSizeType
Base class for most ITK classes.
Definition: itkObject.h:60
Perform machine dependent byte swapping.
std::ostream OStreamType