VTK  9.3.20240721
vtkByteSwap.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
15#ifndef vtkByteSwap_h
16#define vtkByteSwap_h
17
18#include "vtkCommonCoreModule.h" // For export macro
19#include "vtkObject.h"
20
21VTK_ABI_NAMESPACE_BEGIN
22class VTKCOMMONCORE_EXPORT vtkByteSwap : public vtkObject
23{
24public:
25 static vtkByteSwap* New();
26 vtkTypeMacro(vtkByteSwap, vtkObject);
27 void PrintSelf(ostream& os, vtkIndent indent) override;
28
30
35#define VTK_BYTE_SWAP_DECL(T) \
36 static void SwapLE(T* p); \
37 static void SwapBE(T* p); \
38 static void SwapLERange(T* p, size_t num); \
39 static void SwapBERange(T* p, size_t num); \
40 static bool SwapLERangeWrite(const T* p, size_t num, FILE* file); \
41 static bool SwapBERangeWrite(const T* p, size_t num, FILE* file); \
42 static void SwapLERangeWrite(const T* p, size_t num, ostream* os); \
43 static void SwapBERangeWrite(const T* p, size_t num, ostream* os)
51 VTK_BYTE_SWAP_DECL(signed char);
52 VTK_BYTE_SWAP_DECL(unsigned char);
53 VTK_BYTE_SWAP_DECL(unsigned short);
54 VTK_BYTE_SWAP_DECL(unsigned int);
55 VTK_BYTE_SWAP_DECL(unsigned long);
56 VTK_BYTE_SWAP_DECL(unsigned long long);
57#undef VTK_BYTE_SWAP_DECL
59
61
64 static void Swap2LE(void* p);
65 static void Swap4LE(void* p);
66 static void Swap8LE(void* p);
68
70
73 static void Swap2LERange(void* p, size_t num);
74 static void Swap4LERange(void* p, size_t num);
75 static void Swap8LERange(void* p, size_t num);
77
79
83 static bool SwapWrite2LERange(void const* p, size_t num, FILE* f);
84 static bool SwapWrite4LERange(void const* p, size_t num, FILE* f);
85 static bool SwapWrite8LERange(void const* p, size_t num, FILE* f);
86 static void SwapWrite2LERange(void const* p, size_t num, ostream* os);
87 static void SwapWrite4LERange(void const* p, size_t num, ostream* os);
88 static void SwapWrite8LERange(void const* p, size_t num, ostream* os);
90
92
95 static void Swap2BE(void* p);
96 static void Swap4BE(void* p);
97 static void Swap8BE(void* p);
99
101
104 static void Swap2BERange(void* p, size_t num);
105 static void Swap4BERange(void* p, size_t num);
106 static void Swap8BERange(void* p, size_t num);
108
110
114 static bool SwapWrite2BERange(void const* p, size_t num, FILE* f);
115 static bool SwapWrite4BERange(void const* p, size_t num, FILE* f);
116 static bool SwapWrite8BERange(void const* p, size_t num, FILE* f);
117 static void SwapWrite2BERange(void const* p, size_t num, ostream* os);
118 static void SwapWrite4BERange(void const* p, size_t num, ostream* os);
119 static void SwapWrite8BERange(void const* p, size_t num, ostream* os);
121
126 static void SwapVoidRange(void* buffer, size_t numWords, size_t wordSize);
127
128protected:
130 ~vtkByteSwap() override;
131
132private:
133 vtkByteSwap(const vtkByteSwap&) = delete;
134 void operator=(const vtkByteSwap&) = delete;
135};
136
137VTK_ABI_NAMESPACE_END
138#endif
perform machine dependent byte swapping
Definition vtkByteSwap.h:23
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 vtkByteSwap * New()
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 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:108
abstract base class for most VTK objects
Definition vtkObject.h:162