blockfactory
0.8
A framework for wrapping algorithms for dataflow programming
|
Class to access data shared by blocks, represented as signals. More...
#include <Signal.h>
Class to access data shared by blocks, represented as signals.
Analogously to the block-algorithm corrispondence, this class introduces the signal-data corrispondence. Signals are basically the connections between blocks.
Signals do not directly translate to block's input and output. Signals are plugged into block ports, and these block ports fill the signal with data.
Briefly, core::Signal is a wrapper of a generic void*
buffer.
Public Types | |
enum | DataFormat { DataFormat::NONCONTIGUOUS = 0, DataFormat::CONTIGUOUS = 1, DataFormat::CONTIGUOUS_ZEROCOPY = 2 } |
Public Member Functions | |
Signal (const DataFormat &dataFormat=DataFormat::CONTIGUOUS_ZEROCOPY, const Port::DataType &dataType=Port::DataType::DOUBLE) | |
~Signal () | |
Signal (const Signal &other) | |
Signal & | operator= (const Signal &other)=delete |
Signal (Signal &&other) | |
Signal & | operator= (Signal &&other)=delete |
bool | initializeBufferFromContiguous (const void *buffer, size_t len) |
Initialize the signal from a contiguous buffer. More... | |
bool | initializeBufferFromContiguousZeroCopy (const void *buffer, size_t len) |
Initialize the signal from a contiguous buffer without copying data. More... | |
bool | initializeBufferFromNonContiguous (const void *const *bufferPtrs, size_t len) |
Initialize the signal from a non-contiguous buffer. More... | |
bool | isValid () const |
Check if the signal is valid. More... | |
size_t | getWidth () const |
Read the width of the signal. More... | |
Port::DataType | getPortDataType () const |
Read the Port::DataType of the signal. More... | |
DataFormat | getDataFormat () const |
Read the core::Signal::DataFormat of the signal. More... | |
template<typename T > | |
T * | getBuffer () |
Get the pointer to the buffer storing signal's data. More... | |
template<typename T > | |
const T * | getBuffer () const |
Get the pointer to the buffer storing signal's data. More... | |
template<typename T > | |
T | get (const size_t i) const |
Get a single element of the signal. More... | |
bool | set (const size_t index, const double data) |
Set the value of a sigle element of the buffer. More... | |
template<typename T > | |
bool | setBuffer (const T *data, const size_t length) |
Set the pointer to the buffer storing signal's data. More... | |
|
strong |
Defines the format of signals supported by core::Signal. It specifies how the object should be constructed depending on how the engine stores data flowing between the different blocks.
Enumerator | |
---|---|
NONCONTIGUOUS |
This data format matches the default behavior of Simulink input signals. The engine provides a pointer to an array of pointers ( |
CONTIGUOUS |
A core::Signal of this data format time is constructed from a pointer to a contiguous raw buffer ( |
CONTIGUOUS_ZEROCOPY |
This data format matches the default behavior of Simulink output signals. The engine provides a pointer to a contiguous raw buffer ( |
blockfactory::core::Signal::Signal | ( | const DataFormat & | dataFormat = DataFormat::CONTIGUOUS_ZEROCOPY , |
const Port::DataType & | dataType = Port::DataType::DOUBLE |
||
) |
blockfactory::core::Signal::~Signal | ( | ) |
blockfactory::core::Signal::Signal | ( | const Signal & | other | ) |
blockfactory::core::Signal::Signal | ( | Signal && | other | ) |
template double blockfactory::core::Signal::get< double > | ( | const size_t | i | ) | const |
Get a single element of the signal.
This method returns the i-th
element of the handled buffer.
The | data type of the returned signal. It must match configured data type. |
i | The index of the element. It should not exceed the configured width. |
i-th
element of the vector if the signal is valid, or the default value of the type otherwise.template double * blockfactory::core::Signal::getBuffer< double > | ( | ) |
Get the pointer to the buffer storing signal's data.
The buffer is stored as a void pointer. In order to use the buffer it should be properly cast to the right data type. Be sure that the core::DataType matches the type of the buffer otherwise pointer arithmetics does not work.
If T
does not match the configured data type, the returned value will be a nullptr
.
The | data type of the returned buffer. |
nullptr
otherwise.nullptr
before using it. const T* blockfactory::core::Signal::getBuffer | ( | ) | const |
Get the pointer to the buffer storing signal's data.
Documented in core::Signal::getBuffer
DataFormat blockfactory::core::Signal::getDataFormat | ( | ) | const |
Read the core::Signal::DataFormat of the signal.
The default type is core::DataFormat::CONTIGUOUS_ZEROCOPY.
Port::DataType blockfactory::core::Signal::getPortDataType | ( | ) | const |
Read the Port::DataType of the signal.
The default type is Port::DataType::DOUBLE.
size_t blockfactory::core::Signal::getWidth | ( | ) | const |
bool blockfactory::core::Signal::initializeBufferFromContiguous | ( | const void * | buffer, |
size_t | len | ||
) |
Initialize the signal from a contiguous buffer.
This method allocates a new array with the same size of buffer
and copies the data. In this case, the core::Signal object will own the data.
buffer | The pointer to the original contiguous buffer. |
len | The number of buffer elements. |
bool blockfactory::core::Signal::initializeBufferFromContiguousZeroCopy | ( | const void * | buffer, |
size_t | len | ||
) |
Initialize the signal from a contiguous buffer without copying data.
This methods accepts an external contiguous buffer and holds its pointer. The data is not owned by this object.
buffer | The pointer to the original contiguous buffer. |
len | The number of buffer elements. |
bool blockfactory::core::Signal::initializeBufferFromNonContiguous | ( | const void *const * | bufferPtrs, |
size_t | len | ||
) |
Initialize the signal from a non-contiguous buffer.
This method allocates a new array with the same size of bufferPtrs
and copies the data. In this case, the core::Signal object will own the data. bufferPtrs
points to an array of pointers. Each of these pointers points to a data element.
bufferPtrs | The pointer to the original non-contiguous buffer. |
len | The number of buffer elements. |
bool blockfactory::core::Signal::isValid | ( | ) | const |
Check if the signal is valid.
Checks if the internal buffer is not nullptr
and the configured width is greater than zero.
bool blockfactory::core::Signal::set | ( | const size_t | index, |
const double | data | ||
) |
template bool blockfactory::core::Signal::setBuffer< double > | ( | const T * | data, |
const size_t | length | ||
) |
Set the pointer to the buffer storing signal's data.
This method allows changing the handled buffer. In the DataFormat::CONTIGUOUS case the data is copied inside the object. Instead, in the DataFormat::CONTIGUOUS_ZEROCOPY only the pointer to the buffer is changed.
This method is not allowed for DataFormat::NONCONTIGUOUS.
The | data type of the new buffer. |
data | The new buffer address. |
length | The size of the new buffer. |