Lagrange
SharedSpan< T > Class Template Reference

Shared span with ownership tracking. More...

#include <lagrange/utils/SharedSpan.h>

Public Types

using element_type = T
 
using value_type = std::remove_cv_t< T >
 

Public Member Functions

 SharedSpan ()
 Default constructor for empty buffer.
 
 SharedSpan (std::shared_ptr< T > data, size_t size)
 Constructing a SharedSpan object from a shared buffer. More...
 
span< T > ref ()
 
span< const T > get () const
 
std::shared_ptr< const T > owner () const
 
size_t size () const
 

Protected Attributes

std::shared_ptr< T > m_data
 
size_t m_size = 0
 

Detailed Description

template<typename T>
class lagrange::SharedSpan< T >

Shared span with ownership tracking.

Sometimes the buffer referred by a span is already using certain kind of memory ownership sharing schemes (e.g. shared_ptr or PyObject). The SharedSpan class can be used to keep the buffer alive by taking a shared of the ownership of the buffer.

Template Parameters
TValue type.
See also
make_shared_span

Constructor & Destructor Documentation

◆ SharedSpan()

SharedSpan ( std::shared_ptr< T >  data,
size_t  size 
)
inline

Constructing a SharedSpan object from a shared buffer.

Parameters
dataThe owner of the shared buffer.
sizeThe size of the shared buffer.

Member Function Documentation

◆ ref()

span< T > ref ( )
inline
Returns
A writable span of the shared buffer.

◆ get()

span< const T > get ( ) const
inline
Returns
A readonly span of the shared buffer.

◆ owner()

std::shared_ptr< const T > owner ( ) const
inline
Returns
The memory owner of the shared buffer.

◆ size()

size_t size ( ) const
inline
Returns
The buffer size.

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