LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
LLU::Argument Namespace Reference

Namespace for functionality related to arguments passed from LibraryLink to library functions and their types. More...

Detailed Description

Namespace for functionality related to arguments passed from LibraryLink to library functions and their types.

Namespaces

 Typed
 Namespace defining C++ types corresponding to primitive LibraryLink argument types.
 

Type aliases

using PrimitiveAny = std::variant< std::monostate, mbool, mint, mreal, mcomplex, MTensor, MSparseArray, MNumericArray, MImage, char *, DataStore >
 A variant holding all possible MArgument types. More...
 
template<MArgumentType T>
using CType = std::conditional_t< T==MArgumentType::MArgument, MArgument, std::variant_alternative_t< static_cast< size_t >(T), PrimitiveAny > >
 Type alias that binds given MArgumentType (enumerated value) to the corresponding type of MArgument. More...
 
using TypedArgument = std::variant< std::monostate, Typed::Boolean, Typed::Integer, Typed::Real, Typed::Complex, Typed::Tensor, Typed::SparseArray, Typed::NumericArray, Typed::Image, Typed::UTF8String, Typed::DataStore >
 C++ wrapper over LibraryLink's MArgument, which is a plain union. More...
 
template<MArgumentType T>
using WrapperType = std::conditional_t< T==MArgumentType::MArgument, TypedArgument, std::variant_alternative_t< static_cast< size_t >(T), TypedArgument > >
 Get wrapper type corresponding to primitive LibraryLink argument type T. More...
 

Functions

TypedArgument fromMArgument (MArgument m, MArgumentType t)
 Get a TypeArgument from plain MArgument and an enum describing the active union member. More...
 
void toMArgument (const TypedArgument &tma, MArgument &res)
 Assign current value of given TypedArgument to given MArgument. More...
 
template<MArgumentType T>
WrapperType< T > toWrapperType (const CType< T > &value)
 Convert a value of one of the LibraryLink argument type to its wrapper. More...
 
template<MArgumentType T>
CType< T > toPrimitiveType (const WrapperType< T > &value)
 Convert value of one of the wrapper types (see LLU::Argument::Typed namespace) to the corresponding LibraryLink type. More...
 

Variables

template<typename T >
constexpr MArgumentType PrimitiveIndex = static_cast<MArgumentType>(variant_index<PrimitiveAny, T>())
 PrimitiveIndex<T> is the index of type T in the PrimitiveAny variant converted to MArgumentType enum. More...
 
template<typename T >
constexpr bool PrimitiveQ = (variant_index<PrimitiveAny, T>() < std::variant_size_v<PrimitiveAny>)
 Type trait for checking if T is a primitive LibraryLink type (belongs to the MArgument union) More...
 
template<MArgumentType T>
constexpr bool ContainerTypeQ
 Helper template variable that says if an MArgumentType is a LibraryLink container type. More...
 
template<typename T >
constexpr MArgumentType WrapperIndex = static_cast<MArgumentType>(variant_index<TypedArgument, T>())
 Index of a wrapper type in the TypedArgument variant or std::variant_size_v<TypedArgument> otherwise. More...
 
template<typename T >
constexpr bool WrapperQ = std::is_same_v<T, TypedArgument> || (variant_index<TypedArgument, T>() < std::variant_size_v<TypedArgument>)
 Type trait to determine if given type is a "wrapper type" (i.e. More...
 

Type aliases documentation

◆ CType

template<MArgumentType T>
using LLU::Argument::CType = typedef std::conditional_t<T == MArgumentType::MArgument, MArgument, std::variant_alternative_t<static_cast<size_t>(T), PrimitiveAny> >

Type alias that binds given MArgumentType (enumerated value) to the corresponding type of MArgument.

Template Parameters
T- any value of type MArgumentType

◆ PrimitiveAny

using LLU::Argument::PrimitiveAny = typedef std::variant<std::monostate, mbool, mint, mreal, mcomplex, MTensor, MSparseArray, MNumericArray, MImage, char*, DataStore>

A variant holding all possible MArgument types.

◆ TypedArgument

C++ wrapper over LibraryLink's MArgument, which is a plain union.

◆ WrapperType

template<MArgumentType T>
using LLU::Argument::WrapperType = typedef std::conditional_t<T == MArgumentType::MArgument, TypedArgument, std::variant_alternative_t<static_cast<size_t>(T), TypedArgument> >

Get wrapper type corresponding to primitive LibraryLink argument type T.

Template Parameters
T- an enumerated value of type MArgumentType

Function Documentation

◆ fromMArgument()

TypedArgument LLU::Argument::fromMArgument ( MArgument  m,
MArgumentType  t 
)

Get a TypeArgument from plain MArgument and an enum describing the active union member.

Parameters
m- MArgument
t- index of the active member of the MArgument m
Returns
a TypedArgument whose active member is a wrapper of the active member of m
Note
When creating a wrapper of a LibraryLink container, no deep copy is being made, so in a way this function acts more like a cast than a conversion.

◆ toMArgument()

void LLU::Argument::toMArgument ( const TypedArgument tma,
MArgument &  res 
)

Assign current value of given TypedArgument to given MArgument.

Parameters
[in]tma- a TypedArgument
[out]res- raw MArgument to be assigned to
Note
When extracting the underlying raw value from a wrapper type, no deep copy is being made, so in a way this function acts more like a cast than a conversion.

◆ toPrimitiveType()

template<MArgumentType T>
CType<T> LLU::Argument::toPrimitiveType ( const WrapperType< T > &  value)

Convert value of one of the wrapper types (see LLU::Argument::Typed namespace) to the corresponding LibraryLink type.

Template Parameters
T- MArgument type index
Parameters
value- a value of the wrapper type corresponding to T
Returns
plain LibraryLink type value extracted from its wrapper (e.g. GenericTensor -> MTensor, std::complex<double> -> mcomplex, bool -> mbool, etc.)

◆ toWrapperType()

template<MArgumentType T>
WrapperType<T> LLU::Argument::toWrapperType ( const CType< T > &  value)

Convert a value of one of the LibraryLink argument type to its wrapper.

Template Parameters
T- MArgument type index
Parameters
value- a value of the LibraryLink argument type corresponding to T (e.g. MArgumentType::Complex corresponds to mcomplex type)
Returns
LLU wrapper of given value (e.g. MTensor -> GenericTensor, mcomplex -> std::complex<double>, mbool -> bool, etc.)

Variable Documentation

◆ ContainerTypeQ

template<MArgumentType T>
constexpr bool LLU::Argument::ContainerTypeQ
inlineconstexpr
Initial value:

Helper template variable that says if an MArgumentType is a LibraryLink container type.

◆ PrimitiveIndex

template<typename T >
constexpr MArgumentType LLU::Argument::PrimitiveIndex = static_cast<MArgumentType>(variant_index<PrimitiveAny, T>())
inlineconstexpr

PrimitiveIndex<T> is the index of type T in the PrimitiveAny variant converted to MArgumentType enum.

◆ PrimitiveQ

template<typename T >
constexpr bool LLU::Argument::PrimitiveQ = (variant_index<PrimitiveAny, T>() < std::variant_size_v<PrimitiveAny>)
inlineconstexpr

Type trait for checking if T is a primitive LibraryLink type (belongs to the MArgument union)

◆ WrapperIndex

template<typename T >
constexpr MArgumentType LLU::Argument::WrapperIndex = static_cast<MArgumentType>(variant_index<TypedArgument, T>())
inlineconstexpr

Index of a wrapper type in the TypedArgument variant or std::variant_size_v<TypedArgument> otherwise.

Template Parameters
T- any type

◆ WrapperQ

template<typename T >
constexpr bool LLU::Argument::WrapperQ = std::is_same_v<T, TypedArgument> || (variant_index<TypedArgument, T>() < std::variant_size_v<TypedArgument>)
inlineconstexpr

Type trait to determine if given type is a "wrapper type" (i.e.

if it is a member of TypedArgument variant)

Template Parameters
T- any type
LLU::Argument::Typed::NumericArray
MContainer< MArgumentType::NumericArray > NumericArray
NumericArray stands for a GenericNumericArray - type agnostic wrapper over MNumericArray.
Definition: TypedMArgument.h:53
LLU::Argument::Typed::SparseArray
MContainer< MArgumentType::SparseArray > SparseArray
SparseArray stands for a GenericSparseArray - type agnostic wrapper over MSparseArray.
Definition: TypedMArgument.h:50
LLU::Argument::Typed::DataStore
MContainer< MArgumentType::DataStore > DataStore
DataStore stands for a GenericDataList - type agnostic wrapper over DataStore.
Definition: TypedMArgument.h:62
LLU::Argument::Typed::Image
MContainer< MArgumentType::Image > Image
Image stands for a GenericImage - type agnostic wrapper over MImage.
Definition: TypedMArgument.h:56
LLU::Argument::Typed::Tensor
MContainer< MArgumentType::Tensor > Tensor
Tensor stands for a GenericTensor - type agnostic wrapper over MTensor.
Definition: TypedMArgument.h:47