Pothos  0.2.1-g9f04573d
The Pothos dataflow programming software suite
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Pothos::BufferChunk Class Reference

#include <BufferChunk.hpp>

Public Member Functions

 BufferChunk (void)
 
 BufferChunk (const size_t numBytes)
 
 BufferChunk (const DType &dtype, const size_t numElems)
 
 BufferChunk (const SharedBuffer &buffer)
 
 BufferChunk (const ManagedBuffer &buffer)
 
size_t elements (void) const
 
const SharedBuffergetBuffer (void) const
 
const ManagedBuffergetManagedBuffer (void) const
 
size_t getAlias (void) const
 
size_t getEnd (void) const
 
template<typename ElementType >
ElementType as (void) const
 
bool unique (void) const
 
size_t useCount (void) const
 
pothos_explicit operator bool (void) const
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Serialization support. More...
 
void append (const BufferChunk &other)
 
BufferChunk convert (const DType &dtype, const size_t numElems=0) const
 
std::pair< BufferChunk,
BufferChunk
convertComplex (const DType &dtype, const size_t numElems=0) const
 

Static Public Member Functions

static const BufferChunknull (void)
 Get a const reference to a null/empty BufferChunk. More...
 

Public Attributes

size_t address
 
size_t length
 
DType dtype
 

Detailed Description

A BufferChunk holds a managed buffer, address, and length. BufferChunk makes it easy to manipulate pieces of a managed buffer. The caller manipulates a MangedBuffer into multiple BufferChunks; then a BufferAccumulator can piece BufferChunks back together.

Constructor & Destructor Documentation

Pothos::BufferChunk::BufferChunk ( void  )
inline

Create a null BufferChunk. The fields will be zeroed out and buffer null.

Pothos::BufferChunk::BufferChunk ( const size_t  numBytes)

Create a BufferChunk given the number of bytes. This is a convenience method to create a BufferChunk using memory from the standard memory allocator (new/delete). Memory will automatically deallocate via reference counting.

Parameters
numBytesthe number of bytes to allocate
Pothos::BufferChunk::BufferChunk ( const DType dtype,
const size_t  numElems 
)

Create a BufferChunk given data type and number of elements. This is a convenience method to create a BufferChunk from a type. using memory from the standard memory allocator (new/delete). Memory will automatically deallocate via reference counting.

Parameters
dtypethe data type of the result buffer
numElemsthe size in number of elements
Pothos::BufferChunk::BufferChunk ( const SharedBuffer buffer)

Create a BufferChunk from a SharedBuffer. The fields will be initialized to that of the shared buffer.

Pothos::BufferChunk::BufferChunk ( const ManagedBuffer buffer)

Create a BufferChunk from a ManagedBuffer. The fields will be initialized to that of the managed buffer.

Member Function Documentation

void Pothos::BufferChunk::append ( const BufferChunk other)

Append another buffer onto the back of this buffer. This call allocates a new memory slab the size of both buffers and copies the contents from each one into the new memory slab. The length and address members will be updated accordingly. When empty, append simply copies a reference to the other buffer.

Parameters
otherthe other buffer to append to the end
template<typename ElementType >
ElementType Pothos::BufferChunk::as ( void  ) const

Get a pointer to the front of the buffer casted to the desired data type.

BufferChunk Pothos::BufferChunk::convert ( const DType dtype,
const size_t  numElems = 0 
) const

Convert a buffer chunk to the specified data type. When the number of elements are 0, the entire buffer is converted.

Exceptions
BufferConvertErrorwhen the conversion is not possible
Parameters
dtypethe data type of the result buffer
numElemsthe number of elements to convert
Returns
a new buffer chunk with converted elements
std::pair<BufferChunk, BufferChunk> Pothos::BufferChunk::convertComplex ( const DType dtype,
const size_t  numElems = 0 
) const

Convert a buffer chunk of complex elements to two real buffers. When the number of elements are 0, the entire buffer is converted.

Exceptions
BufferConvertErrorwhen the conversion is not possible
Parameters
dtypethe data type of the result buffer
numElemsthe number of elements to convert
Returns
a real + complex pair of buffer chunks
size_t Pothos::BufferChunk::elements ( void  ) const
inline

How many elements are held in this buffer chunk?

Returns
the length in bytes divided by the dtype size.
size_t Pothos::BufferChunk::getAlias ( void  ) const
inline

Get the alias address of the address. Only valid when the underlying buffer is circular.

Returns
the alias address or 0 if non-circular
const Pothos::SharedBuffer & Pothos::BufferChunk::getBuffer ( void  ) const
inline

The underlying reference counted shared buffer.

size_t Pothos::BufferChunk::getEnd ( void  ) const
inline

Get the end address - front address + length. The end address is non-inclusive.

Returns
the end address
const Pothos::ManagedBuffer & Pothos::BufferChunk::getManagedBuffer ( void  ) const
inline

The underlying reference counted managed buffer.

static const BufferChunk& Pothos::BufferChunk::null ( void  )
static

Get a const reference to a null/empty BufferChunk.

Pothos::BufferChunk::operator bool ( void  ) const
inline

Is this buffer chunk valid?

Returns
true when there is underlying memory
template<class Archive >
void Pothos::BufferChunk::serialize ( Archive &  ar,
const unsigned int  version 
)

Serialization support.

bool Pothos::BufferChunk::unique ( void  ) const
inline

Is the reference to the shared buffer unique?

Returns
true if this is the only copy of the shared buffer
size_t Pothos::BufferChunk::useCount ( void  ) const
inline

The number of copies of the shared buffer. An extra copy held by the managed buffer is not counted.

Member Data Documentation

size_t Pothos::BufferChunk::address

The address of the start of the buffer.

DType Pothos::BufferChunk::dtype

The data type of the contents of this buffer.

size_t Pothos::BufferChunk::length

The number of valid bytes in the buffer.


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