 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
7 #ifndef LLU_TYPEDMARGUMENT_H
8 #define LLU_TYPEDMARGUMENT_H
11 #include <string_view>
85 inline constexpr
bool WrapperQ = std::is_same_v<T, TypedArgument> || (variant_index<TypedArgument, T>() < std::variant_size_v<TypedArgument>);
91 template<MArgumentType T>
92 using WrapperType = std::conditional_t<T == MArgumentType::MArgument, TypedArgument, std::variant_alternative_t<static_cast<size_t>(T),
TypedArgument>>;
119 template<MArgumentType T>
121 if constexpr (T == MArgumentType::Complex) {
122 return {value->ri[0], value->ri[1]};
123 }
else if constexpr (T == MArgumentType::UTF8String) {
125 }
else if constexpr (ContainerTypeQ<T>) {
138 template<MArgumentType T>
140 if constexpr (T == MArgumentType::Complex) {
141 return {value.real(), value.imag()};
142 }
else if constexpr (T == MArgumentType::UTF8String) {
144 return const_cast<char*
>(value.data());
145 }
else if constexpr (ContainerTypeQ<T>) {
146 return value.abandonContainer();
153 #endif // LLU_TYPEDMARGUMENT_H
std::conditional_t< T==MArgumentType::MArgument, MArgument, std::variant_alternative_t< static_cast< size_t >(T), PrimitiveAny > > CType
Type alias that binds given MArgumentType (enumerated value) to the corresponding type of MArgument.
Definition: MArgument.h:53
MContainer specialization for DataStore, provides basic list interface for the underlying raw DataSto...
Definition: Generic/DataStore.hpp:23
MContainer specialization for MNumericArray.
Definition: Generic/NumericArray.hpp:23
std::variant< std::monostate, Typed::Boolean, Typed::Integer, Typed::Real, Typed::Complex, Typed::Tensor, Typed::SparseArray, Typed::NumericArray, Typed::Image, Typed::UTF8String, Typed::DataStore > TypedArgument
C++ wrapper over LibraryLink's MArgument, which is a plain union.
Definition: TypedMArgument.h:67
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
MContainer is an abstract class template for generic containers. Only specializations shall be used.
Definition: Base.hpp:245
MContainer< MArgumentType::NumericArray > NumericArray
NumericArray stands for a GenericNumericArray - type agnostic wrapper over MNumericArray.
Definition: TypedMArgument.h:53
MContainer specialization for MSparseArray.
Definition: SparseArray.hpp:23
void toMArgument(const TypedArgument &tma, MArgument &res)
Assign current value of given TypedArgument to given MArgument.
Definition: TypedMArgument.cpp:38
constexpr bool WrapperQ
Type trait to determine if given type is a "wrapper type" (i.e.
Definition: TypedMArgument.h:85
TypedArgument Any
Any is a union of all supported types. Typed::Any can be used as a template parameter for DataList to...
Definition: TypedMArgument.h:70
MContainer< MArgumentType::SparseArray > SparseArray
SparseArray stands for a GenericSparseArray - type agnostic wrapper over MSparseArray.
Definition: TypedMArgument.h:50
CType< T > toPrimitiveType(const WrapperType< T > &value)
Convert value of one of the wrapper types (see LLU::Argument::Typed namespace) to the corresponding L...
Definition: TypedMArgument.h:139
WrapperType< T > toWrapperType(const CType< T > &value)
Convert a value of one of the LibraryLink argument type to its wrapper.
Definition: TypedMArgument.h:120
MContainer specialization for MImage.
Definition: Generic/Image.hpp:23
GenericImage definition and implementation.
GenericTensor definition and implementation.
MContainer< MArgumentType::DataStore > DataStore
DataStore stands for a GenericDataList - type agnostic wrapper over DataStore.
Definition: TypedMArgument.h:62
std::conditional_t< T==MArgumentType::MArgument, TypedArgument, std::variant_alternative_t< static_cast< size_t >(T), TypedArgument > > WrapperType
Get wrapper type corresponding to primitive LibraryLink argument type T.
Definition: TypedMArgument.h:92
std::string_view UTF8String
String values from LibraryLink (char*) are wrapped in std::string_view.
Definition: TypedMArgument.h:59
GenericSparseArray definition and implementation.
MContainer< MArgumentType::Image > Image
Image stands for a GenericImage - type agnostic wrapper over MImage.
Definition: TypedMArgument.h:56
constexpr MArgumentType WrapperIndex
Index of a wrapper type in the TypedArgument variant or std::variant_size_v<TypedArgument> otherwise.
Definition: TypedMArgument.h:78
mint Integer
Machine integer type.
Definition: TypedMArgument.h:38
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
MContainer specialization for MTensor.
Definition: Generic/Tensor.hpp:24
@ LibraryLink
LibraryLink is responsible for managing the container's memory. Corresponds to Automatic and "Constan...
std::complex< double > Complex
Complex number type, bitwise-compatible with mcomplex defined in WolframLibrary.h.
Definition: TypedMArgument.h:44
Template class and utilities to work with MArgument in type-safe manner.
double Real
Double precision floating point type.
Definition: TypedMArgument.h:41
TypedArgument fromMArgument(MArgument m, MArgumentType t)
Get a TypeArgument from plain MArgument and an enum describing the active union member.
Definition: TypedMArgument.cpp:17
MContainer< MArgumentType::Tensor > Tensor
Tensor stands for a GenericTensor - type agnostic wrapper over MTensor.
Definition: TypedMArgument.h:47
Short but generally useful functions.
Namespace for functionality related to arguments passed from LibraryLink to library functions and the...
Definition: MArgument.h:36
bool Boolean
Boolean type, corresponds to True or False in the Wolfram Language.
Definition: TypedMArgument.h:35
GenericNumericArray definition and implementation.