LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
LLU::MContainerBase< Type > Class Template Referenceabstract

Description

template<MArgumentType Type>
class LLU::MContainerBase< Type >

Template of the base class for all generic containers.

MContainerBase stores the raw LibraryLink container and defines a common interface for all generic containers.

Template Parameters
Type- container type

#include <Base.hpp>

Public Types

using Container = Argument::CType< Type >
 The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container". More...
 

Public Member Functions

 MContainerBase ()=default
 Default constructor, creates an empty wrapper. More...
 
 MContainerBase (Container c, Ownership owner)
 Create MContainerBase from a raw container and its owner. More...
 
 MContainerBase (const MContainerBase &mc)=delete
 Container wrappers are non-copyable, they act somewhat like unique_ptr around the raw container. More...
 
 MContainerBase (MContainerBase &&mc) noexcept
 Move-constructor steals the raw container keeping the ownership info. More...
 
MContainerBaseoperator= (const MContainerBase &mc)=delete
 Copy-assignment is deleted, same as copy-constructor. More...
 
MContainerBaseoperator= (MContainerBase &&mc) noexcept
 Move-assignment operator disposes of the current raw container and steals the new one keeping its ownership intact. More...
 
virtual ~MContainerBase () noexcept
 Destructor takes appropriate action depending on the ownership info. More...
 
Container getContainer () const noexcept
 Get internal container. More...
 
Container abandonContainer () const noexcept
 Give a handle to internal container and stop owning it. More...
 
mint shareCount () const noexcept
 Return share count of internal container, if present and 0 otherwise. More...
 
void pass (MArgument &res) const
 Pass the internal container as result of a LibraryLink function. More...
 
Ownership getOwner () const noexcept
 Get ownership information. More...
 

Protected Member Functions

Container cloneContainer () const
 Clone the raw container, if it's present. More...
 
void disown () const noexcept
 Disown internal container if present. More...
 
void free () const noexcept
 Free internal container if present. More...
 
void reset (Container newCont, Ownership newOwnerMode=Ownership::Library) noexcept
 Set a new internal container safely disposing of the old one. More...
 

Type aliases documentation

◆ Container

template<MArgumentType Type>
using LLU::MContainerBase< Type >::Container = Argument::CType<Type>

The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container".

Constructor & Destructor Documentation

◆ MContainerBase() [1/4]

template<MArgumentType Type>
LLU::MContainerBase< Type >::MContainerBase ( )
default

Default constructor, creates an empty wrapper.

◆ MContainerBase() [2/4]

template<MArgumentType Type>
LLU::MContainerBase< Type >::MContainerBase ( Container  c,
Ownership  owner 
)
inline

Create MContainerBase from a raw container and its owner.

Parameters
c- raw LibraryLink container (MTensor, MNumericArray, etc.), passing a nullptr will trigger an exception
owner- who manages the raw container's memory

◆ MContainerBase() [3/4]

template<MArgumentType Type>
LLU::MContainerBase< Type >::MContainerBase ( const MContainerBase< Type > &  mc)
delete

Container wrappers are non-copyable, they act somewhat like unique_ptr around the raw container.

◆ MContainerBase() [4/4]

template<MArgumentType Type>
LLU::MContainerBase< Type >::MContainerBase ( MContainerBase< Type > &&  mc)
inlinenoexcept

Move-constructor steals the raw container keeping the ownership info.

Parameters
mc- MContainerBase to be moved-from, it's internal container becomes nullptr

◆ ~MContainerBase()

template<MArgumentType Type>
virtual LLU::MContainerBase< Type >::~MContainerBase ( )
inlinevirtualnoexcept

Destructor takes appropriate action depending on the ownership info.

Member Function Documentation

◆ abandonContainer()

template<MArgumentType Type>
Container LLU::MContainerBase< Type >::abandonContainer ( ) const
inlinenoexcept

Give a handle to internal container and stop owning it.

Should be used with caution as it may potentially result with resource leak.

Returns
a handle to the internal container

◆ cloneContainer()

template<MArgumentType Type>
Container LLU::MContainerBase< Type >::cloneContainer ( ) const
inlineprotected

Clone the raw container, if it's present.

Returns
cloned container or nullptr if there is no internal container

◆ disown()

template<MArgumentType Type>
void LLU::MContainerBase< Type >::disown ( ) const
inlineprotectednoexcept

Disown internal container if present.

◆ free()

template<MArgumentType Type>
void LLU::MContainerBase< Type >::free ( ) const
inlineprotectednoexcept

Free internal container if present.

◆ getContainer()

template<MArgumentType Type>
Container LLU::MContainerBase< Type >::getContainer ( ) const
inlinenoexcept

Get internal container.

Returns
a handle to the internal container

◆ getOwner()

template<MArgumentType Type>
Ownership LLU::MContainerBase< Type >::getOwner ( ) const
inlinenoexcept

Get ownership information.

Returns
the owner of the internal container

◆ operator=() [1/2]

template<MArgumentType Type>
MContainerBase& LLU::MContainerBase< Type >::operator= ( const MContainerBase< Type > &  mc)
delete

Copy-assignment is deleted, same as copy-constructor.

◆ operator=() [2/2]

template<MArgumentType Type>
MContainerBase& LLU::MContainerBase< Type >::operator= ( MContainerBase< Type > &&  mc)
inlinenoexcept

Move-assignment operator disposes of the current raw container and steals the new one keeping its ownership intact.

Parameters
mc- MContainerBase to be moved-from, it's internal container becomes nullptr
Returns
reference to this object

◆ pass()

template<MArgumentType Type>
void LLU::MContainerBase< Type >::pass ( MArgument &  res) const
inline

Pass the internal container as result of a LibraryLink function.

Parameters
res- MArgument which will hold internal container of this MContainerBase

◆ reset()

template<MArgumentType Type>
void LLU::MContainerBase< Type >::reset ( Container  newCont,
Ownership  newOwnerMode = Ownership::Library 
)
inlineprotectednoexcept

Set a new internal container safely disposing of the old one.

Parameters
newCont- new internal container
newOwnerMode- owner of the new container

◆ shareCount()

template<MArgumentType Type>
mint LLU::MContainerBase< Type >::shareCount ( ) const
inlinenoexcept

Return share count of internal container, if present and 0 otherwise.