VTK  9.2.20230207
vtkByteSwap.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkByteSwap.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
27 #ifndef vtkByteSwap_h
28 #define vtkByteSwap_h
29 
30 #include "vtkCommonCoreModule.h" // For export macro
31 #include "vtkObject.h"
32 
33 VTK_ABI_NAMESPACE_BEGIN
34 class VTKCOMMONCORE_EXPORT vtkByteSwap : public vtkObject
35 {
36 public:
37  static vtkByteSwap* New();
38  vtkTypeMacro(vtkByteSwap, vtkObject);
39  void PrintSelf(ostream& os, vtkIndent indent) override;
40 
42 
47 #define VTK_BYTE_SWAP_DECL(T) \
48  static void SwapLE(T* p); \
49  static void SwapBE(T* p); \
50  static void SwapLERange(T* p, size_t num); \
51  static void SwapBERange(T* p, size_t num); \
52  static bool SwapLERangeWrite(const T* p, size_t num, FILE* file); \
53  static bool SwapBERangeWrite(const T* p, size_t num, FILE* file); \
54  static void SwapLERangeWrite(const T* p, size_t num, ostream* os); \
55  static void SwapBERangeWrite(const T* p, size_t num, ostream* os)
62  VTK_BYTE_SWAP_DECL(long long);
63  VTK_BYTE_SWAP_DECL(signed char);
64  VTK_BYTE_SWAP_DECL(unsigned char);
65  VTK_BYTE_SWAP_DECL(unsigned short);
66  VTK_BYTE_SWAP_DECL(unsigned int);
67  VTK_BYTE_SWAP_DECL(unsigned long);
68  VTK_BYTE_SWAP_DECL(unsigned long long);
69 #undef VTK_BYTE_SWAP_DECL
71 
73 
76  static void Swap2LE(void* p);
77  static void Swap4LE(void* p);
78  static void Swap8LE(void* p);
80 
82 
85  static void Swap2LERange(void* p, size_t num);
86  static void Swap4LERange(void* p, size_t num);
87  static void Swap8LERange(void* p, size_t num);
89 
91 
95  static bool SwapWrite2LERange(void const* p, size_t num, FILE* f);
96  static bool SwapWrite4LERange(void const* p, size_t num, FILE* f);
97  static bool SwapWrite8LERange(void const* p, size_t num, FILE* f);
98  static void SwapWrite2LERange(void const* p, size_t num, ostream* os);
99  static void SwapWrite4LERange(void const* p, size_t num, ostream* os);
100  static void SwapWrite8LERange(void const* p, size_t num, ostream* os);
102 
104 
107  static void Swap2BE(void* p);
108  static void Swap4BE(void* p);
109  static void Swap8BE(void* p);
111 
113 
116  static void Swap2BERange(void* p, size_t num);
117  static void Swap4BERange(void* p, size_t num);
118  static void Swap8BERange(void* p, size_t num);
120 
122 
126  static bool SwapWrite2BERange(void const* p, size_t num, FILE* f);
127  static bool SwapWrite4BERange(void const* p, size_t num, FILE* f);
128  static bool SwapWrite8BERange(void const* p, size_t num, FILE* f);
129  static void SwapWrite2BERange(void const* p, size_t num, ostream* os);
130  static void SwapWrite4BERange(void const* p, size_t num, ostream* os);
131  static void SwapWrite8BERange(void const* p, size_t num, ostream* os);
133 
138  static void SwapVoidRange(void* buffer, size_t numWords, size_t wordSize);
139 
140 protected:
142  ~vtkByteSwap() override;
143 
144 private:
145  vtkByteSwap(const vtkByteSwap&) = delete;
146  void operator=(const vtkByteSwap&) = delete;
147 };
148 
149 VTK_ABI_NAMESPACE_END
150 #endif
perform machine dependent byte swapping
Definition: vtkByteSwap.h:35
static void SwapWrite2LERange(void const *p, size_t num, ostream *os)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static bool SwapWrite4BERange(void const *p, size_t num, FILE *f)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void Swap2BERange(void *p, size_t num)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static bool SwapWrite2LERange(void const *p, size_t num, FILE *f)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
VTK_BYTE_SWAP_DECL(unsigned char)
VTK_BYTE_SWAP_DECL(float)
VTK_BYTE_SWAP_DECL(double)
static bool SwapWrite8BERange(void const *p, size_t num, FILE *f)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
VTK_BYTE_SWAP_DECL(unsigned short)
VTK_BYTE_SWAP_DECL(unsigned long long)
VTK_BYTE_SWAP_DECL(unsigned long)
static bool SwapWrite2BERange(void const *p, size_t num, FILE *f)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void SwapWrite8BERange(void const *p, size_t num, ostream *os)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void Swap8LE(void *p)
Swap 2, 4, or 8 bytes for storage as Little Endian.
VTK_BYTE_SWAP_DECL(short)
static void Swap4BERange(void *p, size_t num)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void Swap4BE(void *p)
Swap 2, 4, or 8 bytes for storage as Big Endian.
static void Swap4LE(void *p)
Swap 2, 4, or 8 bytes for storage as Little Endian.
static void Swap2LERange(void *p, size_t num)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
VTK_BYTE_SWAP_DECL(long)
static vtkByteSwap * New()
static void SwapWrite4BERange(void const *p, size_t num, ostream *os)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void Swap8BE(void *p)
Swap 2, 4, or 8 bytes for storage as Big Endian.
~vtkByteSwap() override
static void Swap2BE(void *p)
Swap 2, 4, or 8 bytes for storage as Big Endian.
static void SwapWrite4LERange(void const *p, size_t num, ostream *os)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static void SwapWrite8LERange(void const *p, size_t num, ostream *os)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static void Swap8LERange(void *p, size_t num)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static bool SwapWrite8LERange(void const *p, size_t num, FILE *f)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static void Swap8BERange(void *p, size_t num)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
VTK_BYTE_SWAP_DECL(unsigned int)
static bool SwapWrite4LERange(void const *p, size_t num, FILE *f)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
static void Swap4LERange(void *p, size_t num)
Swap a block of 2-, 4-, or 8-byte segments for storage as Little Endian.
VTK_BYTE_SWAP_DECL(int)
static void SwapWrite2BERange(void const *p, size_t num, ostream *os)
Swap a block of 2-, 4-, or 8-byte segments for storage as Big Endian.
static void SwapVoidRange(void *buffer, size_t numWords, size_t wordSize)
Swaps the bytes of a buffer.
VTK_BYTE_SWAP_DECL(char)
VTK_BYTE_SWAP_DECL(signed char)
static void Swap2LE(void *p)
Swap 2, 4, or 8 bytes for storage as Little Endian.
VTK_BYTE_SWAP_DECL(long long)
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83