Geogram  Version 1.9.0
A programming library of geometric algorithms
GEO::BinaryStream Class Reference

Binary stream base class. More...

#include <geogram/basic/b_stream.h>

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

Classes

struct  ItemSize
 Size selector. More...
 

Public Member Functions

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...
 

Static Public Attributes

static const int GEO_LITTLE_ENDIAN = 0
 
static const int GEO_BIG_ENDIAN = 1
 

Protected Member Functions

 BinaryStream (int stream_endian=GEO_BIG_ENDIAN)
 Base constructor. More...
 
void detect_machine_endian ()
 Detects the current architecture's endianness.
 

Protected Attributes

bool swapped_
 

Detailed Description

Binary stream base class.

A characteristic of processors named endian corresponds to the way they store numbers. A little endian processor stores less significant bytes first, and a big endian processor stores most significant bytes first.

Most Unix machines are big endian, except those having a DEC Alpha processor. Intel processors are little endian. This causes portability problems for binary files to be exchanged between machines of the two types. The classes BinaryInputStream and BinaryOutputStream make it possible to deal with this problem.

We have not used XDR because XDR assumes that the external format is always big endian, which would have prevented us to read files from PC softwares (such as 3DS binary files).

Definition at line 76 of file b_stream.h.

Constructor & Destructor Documentation

◆ BinaryStream()

GEO::BinaryStream::BinaryStream ( int  stream_endian = GEO_BIG_ENDIAN)
protected

Base constructor.

This constructor initializes the base class common to BinaryInputStream and BinaryOutputStream. It sets the stream endianness and detects the current architecture's endianness

Parameters
[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)

Member Function Documentation

◆ has_record_markers()

bool GEO::BinaryStream::has_record_markers ( ) const
inline

Checks support for record markers.

See also
set_has_record_markers().

Definition at line 116 of file b_stream.h.

◆ machine_endian()

int GEO::BinaryStream::machine_endian ( ) const
inline

Gets the current architecture's endianness.

Returns
GEO_LITTLE_ENDIAN if the architecture is little-endian, GEO_BIG_ENDIAN if the architecture is big-endian.

Definition at line 108 of file b_stream.h.

◆ set_has_record_markers()

void GEO::BinaryStream::set_has_record_markers ( bool  b)
inline

Enables/disables support for record markers.

Some FORTRAN files have their records surrounded by two integers and some not. This function enables BinaryStream to read such FORTRAN files. Default value is true.

Definition at line 127 of file b_stream.h.

◆ set_stream_endian()

void GEO::BinaryStream::set_stream_endian ( int  stream_endian)

Sets the stream endianness.

This affects how the integer and floating point values will be stored in the stream.

Parameters
[in]stream_endianthe endianness of the stream:
  • GEO_LITTLE_ENDIAN makes the stream little-endian
  • GEO_BIG_ENDIAN makes the stream big-endian

◆ stream_endian()

int GEO::BinaryStream::stream_endian ( ) const
inline

Gets the stream endianness.

Returns
GEO_LITTLE_ENDIAN if the stream is little-endian, GEO_BIG_ENDIAN if the stream is big-endian.

Definition at line 99 of file b_stream.h.

Member Data Documentation

◆ GEO_BIG_ENDIAN

const int GEO::BinaryStream::GEO_BIG_ENDIAN = 1
static

Constant to use to specify big-endian streams

Definition at line 82 of file b_stream.h.

◆ GEO_LITTLE_ENDIAN

const int GEO::BinaryStream::GEO_LITTLE_ENDIAN = 0
static

Constant to use to specify little-endian streams

Definition at line 79 of file b_stream.h.

◆ swapped_

bool GEO::BinaryStream::swapped_
protected

True if stream needs swapping

Definition at line 159 of file b_stream.h.


The documentation for this class was generated from the following file: