Binary output file.
More...
#include <geogram/basic/b_stream.h>
Binary output file.
Enables binary files to be written, while taking into account endian problems.
Definition at line 421 of file b_stream.h.
◆ BinaryOutputStream() [1/2]
GEO::BinaryOutputStream::BinaryOutputStream |
( |
const std::string & |
file_name, |
|
|
int |
stream_endian = GEO_BIG_ENDIAN |
|
) |
| |
Creates a new binary output stream.
This prepares the stream to write data to file file_name
. Data will be stored with the given endianness stream_endian
.
- Parameters
-
[in] | file_name | path to the file to write |
[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)
|
◆ BinaryOutputStream() [2/2]
GEO::BinaryOutputStream::BinaryOutputStream |
( |
std::ostream & |
output, |
|
|
int |
stream_endian = GEO_BIG_ENDIAN |
|
) |
| |
Creates a new binary output stream.
This prepares the BinaryOutputStream to write data to std::ostream output
. Data will be stored with the given endianness stream_endian
.
- Parameters
-
[in] | output | the output stream to write to |
[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)
|
◆ ~BinaryOutputStream()
GEO::BinaryOutputStream::~BinaryOutputStream |
( |
| ) |
|
Deletes the output stream.
This closes any associated std::ostream and closes any associated file.
◆ begin_record()
void GEO::BinaryOutputStream::begin_record |
( |
| ) |
|
Starts writing 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::BinaryOutputStream::end_record |
( |
| ) |
|
Stops writing a data record.
This encloses the data written between begin_record() and end_record() with a marker equal to the current position in the output stream.
◆ OK()
bool GEO::BinaryOutputStream::OK |
( |
| ) |
const |
Gets the status of the stream.
- Return values
-
true | if the stream is valid |
false | if an error occurred |
◆ operator<<()
Writes a single element.
- Parameters
-
[in] | x | an element of type T which must be a numeric type, other types are not supported. |
- Template Parameters
-
T | the type of the elements to read. |
- Returns
- a reference to this stream
Definition at line 473 of file b_stream.h.
◆ write() [1/4]
Writes an array of elements of size 1.
- Parameters
-
[in] | data | an array of elements of size 1 |
[in] | n | the number of elements to write |
- Returns
- a reference to this stream
Definition at line 579 of file b_stream.h.
◆ write() [2/4]
Writes an array of elements of size 2.
- Parameters
-
[in] | data | an array of elements of size 2 |
[in] | n | the number of elements to write |
- Returns
- a reference to this stream
◆ write() [3/4]
Writes an array of elements of size 4.
- Parameters
-
[in] | data | an array of elements of size 4 |
[in] | n | the number of elements to write |
- Returns
- a reference to this stream
◆ write() [4/4]
Writes an array of elements of size 8.
- Parameters
-
[in] | data | an array of elements of size 8 |
[in] | n | the number of elements to write |
- Returns
- a reference to this stream
◆ write_array()
Writes an array of elements.
Writes the first n
elements of the array pointed to by data
to the stream. Elements are of type T
which 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 elements to write |
- Template Parameters
-
T | the type of the elements to read. |
- Returns
- a reference to this stream
Definition at line 521 of file b_stream.h.
◆ write_opaque_data() [1/2]
BinaryOutputStream& GEO::BinaryOutputStream::write_opaque_data |
( |
const void * |
ptr, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Writes opaque data.
Writes size
bytes from the byte array ptr
.
- Parameters
-
[in] | ptr | an array of bytes |
[in] | size | number of bytes to write |
- Returns
- a reference to this stream
Definition at line 487 of file b_stream.h.
◆ write_opaque_data() [2/2]
BinaryOutputStream& GEO::BinaryOutputStream::write_opaque_data |
( |
const void * |
ptr, |
|
|
size_t |
size, |
|
|
size_t |
n |
|
) |
| |
|
inline |
Writes opaque data.
Writes n
elements of size
bytes from the byte array ptr
.
- Parameters
-
[in] | ptr | an array of bytes |
[in] | size | size of the elements to write |
[in] | n | number of elements to write |
- Returns
- a reference to this stream
Definition at line 504 of file b_stream.h.
◆ write_record()
Writes an array of elements in a record.
Writes a record containing the first n
elements of the array pointed to by data
to the stream. Elements are of type T
which 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 write |
- Template Parameters
-
T | the type of the elements to read. |
- Returns
- a reference to this stream
Definition at line 562 of file b_stream.h.
The documentation for this class was generated from the following file: