TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
nda::mem::handle_shared< T, AdrSp >

#include <nda/mem/handle.hpp>

Detailed Description

template<typename T, AddressSpace AdrSp>
struct nda::mem::handle_shared< T, AdrSp >

A handle for a memory block on the heap with shared ownership.

Template Parameters
TValue type of the data.
AdrSpnda::mem::AddressSpace in which the memory is allocated.

Definition at line 741 of file handle.hpp.

Public Types

using value_type = T
 Value type of the data.
 

Public Member Functions

 handle_shared ()=default
 Default constructor leaves the handle in a null state (nullptr and size 0).
 
template<Allocator A>
requires (A::address_space == address_space)
 handle_shared (handle_heap< T, A > const &h) noexcept
 Construct a shared handle from an nda::mem::handle_heap.
 
 handle_shared (T *data, size_t size, void *foreign_handle, void(*foreign_decref)(void *)) noexcept
 Construct a handle from a shared object from a foreign library.
 
T * data () const noexcept
 Get a pointer to the stored data.
 
bool is_null () const noexcept
 Check if the handle is in a null state.
 
T const & operator[] (long i) const noexcept
 Subscript operator to access the data.
 
T & operator[] (long i) noexcept
 Subscript operator to access the data.
 
long refcount () const noexcept
 Get the reference count of the shared object.
 
long size () const noexcept
 Get the size of the handle.
 

Static Public Attributes

static constexpr auto address_space = AdrSp
 nda::mem::AddressSpace in which the memory is allocated.
 

Constructor & Destructor Documentation

◆ handle_shared() [1/2]

template<typename T, AddressSpace AdrSp>
nda::mem::handle_shared< T, AdrSp >::handle_shared ( T * data,
size_t size,
void * foreign_handle,
void(* foreign_decref )(void *) )
inlinenoexcept

Construct a handle from a shared object from a foreign library.

Parameters
dataPointer to the start of the shared data.
sizeSize of the data (number of elements).
foreign_handlePointer to the shared object.
foreign_decrefFunction to decrease the reference count of the shared object.

Definition at line 775 of file handle.hpp.

◆ handle_shared() [2/2]

template<typename T, AddressSpace AdrSp>
template<Allocator A>
requires (A::address_space == address_space)
nda::mem::handle_shared< T, AdrSp >::handle_shared ( handle_heap< T, A > const & h)
inlinenoexcept

Construct a shared handle from an nda::mem::handle_heap.

Template Parameters
Anda::mem::Allocator type of the source handle.
Parameters
hSource handle.

Definition at line 785 of file handle.hpp.

Member Function Documentation

◆ data()

template<typename T, AddressSpace AdrSp>
T * nda::mem::handle_shared< T, AdrSp >::data ( ) const
inlinenodiscardnoexcept

Get a pointer to the stored data.

Returns
Pointer to the start of the handled memory.

Definition at line 829 of file handle.hpp.

◆ is_null()

template<typename T, AddressSpace AdrSp>
bool nda::mem::handle_shared< T, AdrSp >::is_null ( ) const
inlinenodiscardnoexcept

Check if the handle is in a null state.

Returns
True if the data is a nullptr (and the size is 0).

Definition at line 811 of file handle.hpp.

◆ operator[]() [1/2]

template<typename T, AddressSpace AdrSp>
T const & nda::mem::handle_shared< T, AdrSp >::operator[] ( long i) const
inlinenodiscardnoexcept

Subscript operator to access the data.

Parameters
iIndex of the element to access.
Returns
Const reference to the element at the given index.

Definition at line 805 of file handle.hpp.

◆ operator[]() [2/2]

template<typename T, AddressSpace AdrSp>
T & nda::mem::handle_shared< T, AdrSp >::operator[] ( long i)
inlinenodiscardnoexcept

Subscript operator to access the data.

Parameters
iIndex of the element to access.
Returns
Reference to the element at the given index.

Definition at line 797 of file handle.hpp.

◆ refcount()

template<typename T, AddressSpace AdrSp>
long nda::mem::handle_shared< T, AdrSp >::refcount ( ) const
inlinenodiscardnoexcept

Get the reference count of the shared object.

Returns
Reference count of the shared pointer.

Definition at line 823 of file handle.hpp.

◆ size()

template<typename T, AddressSpace AdrSp>
long nda::mem::handle_shared< T, AdrSp >::size ( ) const
inlinenodiscardnoexcept

Get the size of the handle.

Returns
Number of elements of type T in the handled memory.

Definition at line 835 of file handle.hpp.


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