-
Notifications
You must be signed in to change notification settings - Fork 128
Auto release objects
These objects are returned from some port calls with the intent of providing zero copy for larger allocations that would otherwise have to be copied from the port. They also provide iterator abstractions for items returned.
IMPORTANT - when these objects pass out of scope or destruct, they perform an action. The pop/peek_range variants remote the elements from the target port and free them. The allocate variant automatically pushes data to the destination port. These are conveniences that could also be replicated by calling functions directly.
These operators vary by autorelease specialization
/**
* *operator - dereference this auto-release objec to
* get the actual value (by reference).
* @return T&
*/
const T& operator *() const noexcept
{
return( item );
} autopair< T > operator []( const std::size_t index )This returns an autopair object that contains
template < class T > struct autopair
{
autopair( T &ele, Buffer::Signal &sig ) : ele( ele ),
sig( sig )
{}
T &ele;
Buffer::Signal &sig;
};So that the programmer can access each element directly while having less ability to corrupt or accidentally free the underlying memory.
/**
* getindex - returns index for foreach constructs,
* future versions will deprecate this for all types
* but that one.
*/
std::size_t getindex() noexcept
{
return( signal[ 0 ] .getindex() );
}
/**
* size - returns the size of the given autorelease object
*/
std::size_t size() noexcept
{
return( n_items );
}