VTK
9.5.20251208
IO
Avmesh
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
11
class
BinaryFile
12
{
13
public
:
14
BinaryFile
(
const
char
* fname);
15
~BinaryFile
();
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>
34
T
ReadOne
()
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
53
private
:
54
std::ifstream InFile;
55
bool
NeedSwap;
56
};
57
58
#endif
// BinaryFile_h
BinaryFile::SwapInt
static int SwapInt(int x)
BinaryFile::ReadDouble
double ReadDouble()
BinaryFile::ReadArray
void ReadArray(T *array, size_t nitems)
Definition
BinaryFile.h:20
BinaryFile::ReadStdString
std::string ReadStdString()
BinaryFile::~BinaryFile
~BinaryFile()
BinaryFile::ReadInt
int ReadInt()
BinaryFile::good
bool good() const
BinaryFile::SetSwap
void SetSwap(bool val)
BinaryFile::ReadOne
T ReadOne()
Definition
BinaryFile.h:34
BinaryFile::BinaryFile
BinaryFile(const char *fname)
BinaryFile::ReadCString
void ReadCString(char *s, size_t n=128)
vtkByteSwap.h
Generated on Mon Dec 8 2025 10:37:07 for VTK by
1.13.2