Loading [MathJax]/extensions/tex2jax.js
VTK  9.4.20250415
BinaryFile.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
3
4#ifndef BinaryFile_h
5#define BinaryFile_h
6
7#include "vtkByteSwap.h"
8#include <fstream>
9#include <string>
10
12{
13public:
14 BinaryFile(const char* fname);
16
17 bool good() const;
18
19 template <typename T>
20 void ReadArray(T* array, size_t nitems)
21 {
22 this->InFile.read((char*)array, nitems * sizeof(T));
23 if (this->NeedSwap)
24 {
25#ifdef VTK_WORDS_BIGENDIAN
26 vtkByteSwap::SwapBERange(array, nitems);
27#else
28 vtkByteSwap::SwapLERange(array, nitems);
29#endif
30 }
31 }
32
33 template <typename T>
35 {
36 T x;
37 this->ReadArray(&x, 1);
38 return x;
39 }
40
41 int ReadInt();
42
43 double ReadDouble();
44
45 void ReadCString(char* s, size_t n = 128);
46
47 std::string ReadStdString();
48
49 static int SwapInt(int x);
50
51 void SetSwap(bool val);
52
53private:
54 std::ifstream InFile;
55 bool NeedSwap;
56};
57
58#endif // BinaryFile_h
static int SwapInt(int x)
double ReadDouble()
void ReadArray(T *array, size_t nitems)
Definition BinaryFile.h:20
std::string ReadStdString()
int ReadInt()
bool good() const
void SetSwap(bool val)
BinaryFile(const char *fname)
void ReadCString(char *s, size_t n=128)