Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
GEO::BinaryOutputStream Class Reference

Binary output file. More...

#include <geogram/basic/b_stream.h>

Inheritance diagram for GEO::BinaryOutputStream:
GEO::BinaryStream

Public Member Functions

 BinaryOutputStream (const std::string &file_name, int stream_endian=GEO_BIG_ENDIAN)
 Creates a new binary output stream. More...
 
 BinaryOutputStream (std::ostream &output, int stream_endian=GEO_BIG_ENDIAN)
 Creates a new binary output stream. More...
 
 ~BinaryOutputStream ()
 Deletes the output stream. More...
 
bool OK () const
 Gets the status of the stream. More...
 
template<class T >
BinaryOutputStreamoperator<< (T x)
 Writes a single element. More...
 
BinaryOutputStreamwrite_opaque_data (const void *ptr, size_t size)
 Writes opaque data. More...
 
BinaryOutputStreamwrite_opaque_data (const void *ptr, size_t size, size_t n)
 Writes opaque data. More...
 
template<class T >
BinaryOutputStreamwrite_array (const T *data, size_t n)
 Writes an array of elements. More...
 
void begin_record ()
 Starts writing a data record. More...
 
void end_record ()
 Stops writing a data record. More...
 
template<class T >
BinaryOutputStreamwrite_record (const T *data, size_t n)
 Writes an array of elements in a record. More...
 
- Public Member Functions inherited from GEO::BinaryStream
void set_stream_endian (int stream_endian)
 Sets the stream endianness. More...
 
int stream_endian () const
 Gets the stream endianness. More...
 
int machine_endian () const
 Gets the current architecture's endianness. More...
 
bool has_record_markers () const
 Checks support for record markers. More...
 
void set_has_record_markers (bool b)
 Enables/disables support for record markers. More...
 

Protected Member Functions

BinaryOutputStreamwrite (const char *data, size_t n, ItemSize< 1 >)
 Writes an array of elements of size 1. More...
 
BinaryOutputStreamwrite (const char *data, size_t n, ItemSize< 2 >)
 Writes an array of elements of size 2. More...
 
BinaryOutputStreamwrite (const char *data, size_t n, ItemSize< 4 >)
 Writes an array of elements of size 4. More...
 
BinaryOutputStreamwrite (const char *data, size_t n, ItemSize< 8 >)
 Writes an array of elements of size 8. More...
 
- Protected Member Functions inherited from GEO::BinaryStream
 BinaryStream (int stream_endian=GEO_BIG_ENDIAN)
 Base constructor. More...
 
void detect_machine_endian ()
 Detects the current architecture's endianness.
 

Additional Inherited Members

- Static Public Attributes inherited from GEO::BinaryStream
static const int GEO_LITTLE_ENDIAN = 0
 
static const int GEO_BIG_ENDIAN = 1
 
- Protected Attributes inherited from GEO::BinaryStream
bool swapped_
 

Detailed Description

Binary output file.

Enables binary files to be written, while taking into account endian problems.

Definition at line 421 of file b_stream.h.

Constructor & Destructor Documentation

◆ 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_namepath to the file to write
[in]stream_endianthe 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]outputthe output stream to write to
[in]stream_endianthe 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.

Member Function Documentation

◆ 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
trueif the stream is valid
falseif an error occurred

◆ operator<<()

template<class T >
BinaryOutputStream& GEO::BinaryOutputStream::operator<< ( x)
inline

Writes a single element.

Parameters
[in]xan element of type T which must be a numeric type, other types are not supported.
Template Parameters
Tthe type of the elements to read.
Returns
a reference to this stream

Definition at line 473 of file b_stream.h.

◆ write() [1/4]

BinaryOutputStream& GEO::BinaryOutputStream::write ( const char *  data,
size_t  n,
ItemSize< 1 >   
)
inlineprotected

Writes an array of elements of size 1.

Parameters
[in]dataan array of elements of size 1
[in]nthe number of elements to write
Returns
a reference to this stream

Definition at line 579 of file b_stream.h.

◆ write() [2/4]

BinaryOutputStream& GEO::BinaryOutputStream::write ( const char *  data,
size_t  n,
ItemSize< 2 >   
)
protected

Writes an array of elements of size 2.

Parameters
[in]dataan array of elements of size 2
[in]nthe number of elements to write
Returns
a reference to this stream

◆ write() [3/4]

BinaryOutputStream& GEO::BinaryOutputStream::write ( const char *  data,
size_t  n,
ItemSize< 4 >   
)
protected

Writes an array of elements of size 4.

Parameters
[in]dataan array of elements of size 4
[in]nthe number of elements to write
Returns
a reference to this stream

◆ write() [4/4]

BinaryOutputStream& GEO::BinaryOutputStream::write ( const char *  data,
size_t  n,
ItemSize< 8 >   
)
protected

Writes an array of elements of size 8.

Parameters
[in]dataan array of elements of size 8
[in]nthe number of elements to write
Returns
a reference to this stream

◆ write_array()

template<class T >
BinaryOutputStream& GEO::BinaryOutputStream::write_array ( const T *  data,
size_t  n 
)
inline

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]dataan array of at least n elements of type T.
[in]nnumber of elements to write
Template Parameters
Tthe 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]ptran array of bytes
[in]sizenumber 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]ptran array of bytes
[in]sizesize of the elements to write
[in]nnumber of elements to write
Returns
a reference to this stream

Definition at line 504 of file b_stream.h.

◆ write_record()

template<class T >
BinaryOutputStream& GEO::BinaryOutputStream::write_record ( const T *  data,
size_t  n 
)
inline

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]dataan array of at least n elements of type T.
[in]nnumber of items to write
Template Parameters
Tthe 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: