ug4
ug::BinaryBuffer Class Reference

A Buffer for binary data. More...

#include <binary_buffer.h>

Public Member Functions

 BinaryBuffer ()
 
 BinaryBuffer (size_t bufSize)
 creates a binary buffer and reserves bufSize bytes. More...
 
char * buffer ()
 returns the raw buffer pointer or NULL if the buffer is empty (capacity() == 0) More...
 
size_t capacity () const
 returns the capacity (reserved memory) of the buffer More...
 
void clear ()
 clears the buffer More...
 
bool eof ()
 returns true if the read-position reached the write-position More...
 
void read (char *buf, size_t size)
 reads data of the given size (in bytes) More...
 
size_t read_pos () const
 returns the current read-pos (in bytes) More...
 
void reserve (size_t newSize)
 resizes the associated buffer to the given size. More...
 
void set_read_pos (size_t pos)
 sets the read position (in bytes). More...
 
void set_write_pos (size_t pos)
 sets the write position. More...
 
void write (const char *buf, size_t size)
 writes data of the given size (in bytes) More...
 
size_t write_pos () const
 returns the current write-pos (in bytes) More...
 

Private Attributes

std::vector< char > m_data
 
size_t m_readPos
 
size_t m_writePos
 

Detailed Description

A Buffer for binary data.

The BinaryBuffer allows read and write access, which mimics the behavior of std::iostream. However, in contrary to ug::BinaryStream, this class is not a specialization of std::iostream. This is crucial to achieve maximal performance.

Furthermore BinaryBuffer gives access to its internal buffer, which can be handy in some situations. However, this feature has to be used with extreme care!

Constructor & Destructor Documentation

◆ BinaryBuffer() [1/2]

ug::BinaryBuffer::BinaryBuffer ( )

◆ BinaryBuffer() [2/2]

ug::BinaryBuffer::BinaryBuffer ( size_t  bufSize)

creates a binary buffer and reserves bufSize bytes.

Member Function Documentation

◆ buffer()

◆ capacity()

size_t ug::BinaryBuffer::capacity ( ) const
inline

returns the capacity (reserved memory) of the buffer

References m_data.

◆ clear()

void ug::BinaryBuffer::clear ( )

clears the buffer

This method does not free associated memory. It only resets the read and write positions. To free the memory you may create a new instance of ug::BinaryBuffer and assign it by value to your current instance.

References m_readPos, and m_writePos.

Referenced by pcl::ProcessCommunicator::distribute_data(), pcl::MinimalKeyValuePairAcrossAllProcs(), pcl::ReadCombinedParallelFile(), and pcl::InterfaceCommunicator< TLayout >::wait().

◆ eof()

◆ read()

◆ read_pos()

size_t ug::BinaryBuffer::read_pos ( ) const
inline

returns the current read-pos (in bytes)

References m_readPos.

Referenced by ug::ComPol_MatCreateOverlap< TMatrix >::post_process().

◆ reserve()

void ug::BinaryBuffer::reserve ( size_t  newSize)

◆ set_read_pos()

void ug::BinaryBuffer::set_read_pos ( size_t  pos)

sets the read position (in bytes).

References m_readPos.

Referenced by ug::ReceiveMatrix().

◆ set_write_pos()

◆ write()

◆ write_pos()

Member Data Documentation

◆ m_data

std::vector<char> ug::BinaryBuffer::m_data
private

Referenced by buffer(), capacity(), read(), reserve(), and write().

◆ m_readPos

size_t ug::BinaryBuffer::m_readPos
private

Referenced by clear(), eof(), read(), read_pos(), and set_read_pos().

◆ m_writePos

size_t ug::BinaryBuffer::m_writePos
private

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