Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
DataBuffer Class Reference

Specialization of the Buffer class that is designed for storing untyped data arrays. More...

#include <DataBuffer.hxx>

Inheritance diagram for DataBuffer:
Buffer< uint8_t[]> BufferBase QMember

Public Member Functions

void set_size (uint16_t s)
 Overrides the size of the data buffer.
 
void set_next (DataBuffer *n)
 Sets the linking pointer of the DataBuffer to a target buffer.
 
DataBuffernext ()
 
uint8_t * data ()
 
DataBufferref ()
 
DataBufferref_all (unsigned total_size, DataBuffer **tail=nullptr, unsigned *tail_size=nullptr)
 Acquires one reference to all blocks of this buffer.
 
void unref_all (unsigned total_size)
 Releases one reference to all blocks of this buffer.
 
DataBufferget_read_pointer (unsigned skip, uint8_t **ptr, unsigned *available)
 Helper function to read out data from a linked data buffer.
 
- Public Member Functions inherited from Buffer< uint8_t[]>
Buffer< uint8_t > * ref ()
 Add another reference to the buffer.
 
void unref ()
 Decrement count.
 
uint8_t * data ()
 get a pointer to the start of the data.
 
- Public Member Functions inherited from BufferBase
uint16_t references ()
 
void set_done (BarrierNotifiable *done)
 Specifies that a given BarrierNotifiable must be called when the Buffer is deallocated (unreffed to zero, meaning that all owners have freed it).
 
BarrierNotifiablenew_child ()
 Creates a new child notifiable of the current done notifiable.
 
size_t size ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Member Functions

 DataBuffer (DataBufferPool *p)
 

Friends

class DataBufferPool
 

Additional Inherited Members

- Public Types inherited from Buffer< uint8_t[]>
typedef uint8_t value_type
 The type of payload this buffer contains.
 
- Protected Member Functions inherited from BufferBase
Poolpool ()
 Get a pointer to the pool that this buffer belongs to.
 
 BufferBase (size_t size, Pool *pool)
 Constructor.
 
 ~BufferBase ()
 Destructor.
 
 DISALLOW_COPY_AND_ASSIGN (BufferBase)
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from BufferBase
Poolpool_
 Reference to the pool from whence this buffer came.
 
BarrierNotifiabledone_
 Notifiable to call when the buffer has finished processing everywhere.
 
uint16_t size_
 size of data in bytes
 
std::atomic_uint_least16_t count_
 number of references in use
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

Specialization of the Buffer class that is designed for storing untyped data arrays.

Adds the ability to treat the next pointers as links to consecutive data bytes, ref'ing and unref'ing a sequence of buffers in one go.

Definition at line 58 of file DataBuffer.hxx.

Constructor & Destructor Documentation

◆ DataBuffer()

DataBuffer::DataBuffer ( DataBufferPool p)
inlineprivate

Definition at line 194 of file DataBuffer.hxx.

Member Function Documentation

◆ data()

uint8_t * DataBuffer::data ( )
inline
Returns
the payload pointer, cast to a convenient type.

Definition at line 84 of file DataBuffer.hxx.

◆ get_read_pointer()

DataBuffer * DataBuffer::get_read_pointer ( unsigned  skip,
uint8_t **  ptr,
unsigned *  available 
)
inline

Helper function to read out data from a linked data buffer.

Parameters
skipthis is how many bytes from the beginning of the buffer will be skipped.
ptrwill be set to the pointer to the first non-skipped byte.
availablewill contain the number of available consecutive bytes to read from that point on.
Returns
the data buffer where to continue reading (with skip = 0), might be nullptr.

Definition at line 165 of file DataBuffer.hxx.

◆ next()

DataBuffer * DataBuffer::next ( )
inline
Returns
the pointer to the next chunk of buffer.

Definition at line 78 of file DataBuffer.hxx.

◆ ref()

DataBuffer * DataBuffer::ref ( )
inline
Returns
a new reference to *this.

Definition at line 90 of file DataBuffer.hxx.

◆ ref_all()

DataBuffer * DataBuffer::ref_all ( unsigned  total_size,
DataBuffer **  tail = nullptr,
unsigned *  tail_size = nullptr 
)
inline

Acquires one reference to all blocks of this buffer.

Parameters
total_sizethe number of bytes starting from the beginning of *this.
tailif non-null, will save the pointer to the tail buffer there.
tail_sizeif non-null, will save the number of bytes that are in the tail buffer.
Returns
the first of the referenced buffers.

Definition at line 102 of file DataBuffer.hxx.

◆ set_next()

void DataBuffer::set_next ( DataBuffer n)
inline

Sets the linking pointer of the DataBuffer to a target buffer.

Parameters
nnext buffer to link to.

Definition at line 72 of file DataBuffer.hxx.

◆ set_size()

void DataBuffer::set_size ( uint16_t  s)
inline

Overrides the size of the data buffer.

The semantic meaning of the size() of DataBuffer is the number of bytes that are filled in inside data().

Parameters
snew value of size.

Definition at line 65 of file DataBuffer.hxx.

◆ unref_all()

void DataBuffer::unref_all ( unsigned  total_size)
inline

Releases one reference to all blocks of this buffer.

This includes one reference to the last block which may be a partially filled buffer. Calling with zero length will call release on the head block.

Parameters
total_sizethe number of bytes starting from the beginning of *this.

Definition at line 136 of file DataBuffer.hxx.

Friends And Related Symbol Documentation

◆ DataBufferPool

friend class DataBufferPool
friend

Definition at line 192 of file DataBuffer.hxx.


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