Binary input file.
More...
#include <geogram/basic/b_stream.h>
Binary input file.
This class enables binary files to be read, while taking into account Endian problems (see BinaryStream).
Definition at line 175 of file b_stream.h.
◆ BinaryInputStream() [1/2]
GEO::BinaryInputStream::BinaryInputStream |
( |
const std::string & |
file_name, |
|
|
int |
stream_endian = GEO_BIG_ENDIAN |
|
) |
| |
Creates a new binary input stream.
This prepares the stream to read data from file file_name
. Data is supposed to be stored with the given endianness stream_endian
.
- Parameters
-
[in] | file_name | path to the file to read |
[in] | stream_endian | the endianness of the stream:
- GEO_LITTLE_ENDIAN makes the stream little-endian
- GEO_BIG_ENDIAN makes the stream big-endian (the default)
|
◆ BinaryInputStream() [2/2]
GEO::BinaryInputStream::BinaryInputStream |
( |
std::istream & |
input, |
|
|
int |
stream_endian = GEO_BIG_ENDIAN |
|
) |
| |
Creates a new binary input stream.
This prepares the BinaryInputStream to read data from std::istream input
. Data will be stored with the given endianness stream_endian
.
- Parameters
-
[in] | input | the input stream to read from |
[in] | stream_endian | the endianness of the stream:
- GEO_LITTLE_ENDIAN makes the stream little-endian
- GEO_BIG_ENDIAN makes the stream big-endian (the default)
|
◆ ~BinaryInputStream()
GEO::BinaryInputStream::~BinaryInputStream |
( |
| ) |
|
Deletes the input stream.
This closes any associated std::istream and closes any associated file.
◆ begin_record()
void GEO::BinaryInputStream::begin_record |
( |
| ) |
|
Starts reading a data record.
FORTRAN data files are structured into records, bounded by two integers indicating the size of the record. These two functions enable these integers to be read, and to use them as a validity check. If they differ, subsequent calls to OK() return false. Note that if set_had_record_markers() has been called with false, the records are supposed to be continuously written in the file (without markers).
◆ end_record()
void GEO::BinaryInputStream::end_record |
( |
| ) |
|
Stops reading a data record.
This verifies that the record data is properly enclosed with the same marker, that is: the marker at the current stream position matches the marker found at the beginning of the record (see begin_record()).
◆ more()
bool GEO::BinaryInputStream::more |
( |
| ) |
const |
Checks if there are more bytes to read.
- Return values
-
true | if the stream is not at end-of-file |
false | otherwise |
◆ OK()
bool GEO::BinaryInputStream::OK |
( |
| ) |
const |
Gets the status of the stream.
- Return values
-
true | if the stream is valid |
false | if an error occurred |
◆ operator>>()
Reads a single element.
Reads an element of type T
from the stream and stores it in x
. Type T
must be a numeric type, other types are not supported.
- Parameters
-
[in] | x | a reference to a element of type T |
- Template Parameters
-
T | the type of the element to read. This must be a numeric type |
- Returns
- a reference to this stream
Definition at line 237 of file b_stream.h.
◆ read() [1/4]
Reads an array of elements of size 1.
- Parameters
-
[in] | data | an array of elements of size 1 |
[in] | n | the number of elements to read |
- Returns
- a reference to this stream
Definition at line 372 of file b_stream.h.
◆ read() [2/4]
Reads an array of elements of size 2.
- Parameters
-
[in] | data | an array of elements of size 2 |
[in] | n | the number of elements to read |
- Returns
- a reference to this stream
◆ read() [3/4]
Reads an array of elements of size 4.
- Parameters
-
[in] | data | an array of elements of size 4 |
[in] | n | the number of elements to read |
- Returns
- a reference to this stream
◆ read() [4/4]
Reads an array of elements of size 8.
- Parameters
-
[in] | data | an array of elements of size 8 |
[in] | n | the number of elements to read |
- Returns
- a reference to this stream
◆ read_array()
Reads an array of elements.
Reads n
elements of type T
from the stream and stores them in array pointed to by data
. The array must be large enough to receive n
elements. Type T
must be a numeric type, other types are not supported.
- Parameters
-
[in] | data | an array of at least n elements of type T . |
[in] | n | number of items to read |
- Template Parameters
-
T | the type of the elements to read |
- Returns
- a reference to this stream
Definition at line 286 of file b_stream.h.
◆ read_opaque_data() [1/2]
Reads opaque data.
Reads n
bytes from the stream and stores them in the byte array ptr
. Bytes read from the stream are stored without conversion in the array ptr
.
- Parameters
-
[in] | ptr | an array of bytes |
[in] | n | number of bytes to read |
- Returns
- a reference to this stream
Definition at line 253 of file b_stream.h.
◆ read_opaque_data() [2/2]
BinaryInputStream& GEO::BinaryInputStream::read_opaque_data |
( |
void * |
ptr, |
|
|
size_t |
size, |
|
|
size_t |
n |
|
) |
| |
|
inline |
Reads opaque data.
Reads n
elements of size
bytes from the stream and stores them in the byte array ptr
. Bytes read from the stream are stored without conversion in the array ptr
.
- Parameters
-
[in] | ptr | an array of bytes |
[in] | size | size of the elements to read |
[in] | n | number of elements to read |
- Returns
- a reference to this stream
Definition at line 268 of file b_stream.h.
◆ read_record()
Reads an array of elements in a record.
Reads n
elements of type T
enclosed in a data record from the stream and stores them in array pointed to by data
. The array must be large enough to receive n
elements. Type T
must be a numeric type, other types are not supported.
- Parameters
-
[in] | data | an array of at least n elements of type T . |
[in] | n | number of items to read |
- Returns
- a reference to this stream
Definition at line 327 of file b_stream.h.
◆ seek() [1/2]
void GEO::BinaryInputStream::seek |
( |
std::streamoff |
off, |
|
|
std::ios_base::seekdir |
dir |
|
) |
| |
|
inline |
Sets the position in input sequence.
- Parameters
-
[in] | off | offset value, relative to the dir parameter |
[in] | dir | the direction in which to seek:
- ios_base::beg - beginning of the stream
- ios_base::cur - current position in the stream
- ios_base::end - end of the stream
|
Definition at line 361 of file b_stream.h.
◆ seek() [2/2]
void GEO::BinaryInputStream::seek |
( |
std::streamoff |
pos | ) |
|
|
inline |
Sets the position in input sequence.
- Parameters
-
[in] | pos | the new absolute position in the stream |
Definition at line 349 of file b_stream.h.
◆ tell()
std::streamoff GEO::BinaryInputStream::tell |
( |
| ) |
const |
|
inline |
Gets the position in the input sequence.
- Returns
- The absolute position in the stream
Definition at line 341 of file b_stream.h.
The documentation for this class was generated from the following file: