 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
8 #ifndef LLU_MARGUMENT_H
9 #define LLU_MARGUMENT_H
23 MArgument = MType_Undef,
24 Boolean = MType_Boolean,
25 Integer = MType_Integer,
27 Complex = MType_Complex,
32 UTF8String = MType_UTF8String,
33 DataStore = MType_DataStore
38 using PrimitiveAny = std::variant<std::monostate, mbool, mint, mreal, mcomplex, MTensor, MSparseArray, MNumericArray, MImage, char*, DataStore>;
46 inline constexpr
bool PrimitiveQ = (variant_index<PrimitiveAny, T>() < std::variant_size_v<PrimitiveAny>);
52 template<MArgumentType T>
53 using CType = std::conditional_t<T == MArgumentType::MArgument, MArgument, std::variant_alternative_t<static_cast<size_t>(T),
PrimitiveAny>>;
58 template<MArgumentType T>
59 inline constexpr
bool ContainerTypeQ = (T == MArgumentType::Tensor || T == MArgumentType::Image || T == MArgumentType::NumericArray ||
60 T == MArgumentType::DataStore || T == MArgumentType::SparseArray);
66 template<MArgumentType T>
75 template<MArgumentType T>
142 template<MArgumentType T>
144 addDataStoreNode(ds, name, get());
149 #define LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(ArgType) \
151 auto PrimitiveWrapper<MArgumentType::ArgType>::get()->typename PrimitiveWrapper::value_type&; \
153 auto PrimitiveWrapper<MArgumentType::ArgType>::get() const->const typename PrimitiveWrapper::value_type&; \
155 void PrimitiveWrapper<MArgumentType::ArgType>::addDataStoreNode(DataStore ds, std::string_view name, value_type val); \
157 void PrimitiveWrapper<MArgumentType::ArgType>::addDataStoreNode(DataStore ds, value_type val); \
159 auto PrimitiveWrapper<MArgumentType::ArgType>::getAddress() const->typename PrimitiveWrapper::value_type*; \
161 void PrimitiveWrapper<MArgumentType::ArgType>::set(typename PrimitiveWrapper::value_type newValue);
163 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(Boolean)
164 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(Integer)
165 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(Real)
166 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(Complex)
167 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(
Tensor)
168 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(DataStore)
169 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(
SparseArray)
170 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(
NumericArray)
171 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(
Image)
172 LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS(UTF8String)
189 #undef LLU_ARGUMENT_DEFINE_SPECIALIZATIONS_OF_MEMBER_FUNCTIONS
194 #endif // LLU_MARGUMENT_H
void set(value_type newValue)
Set new value of type T in MArgument.
constexpr bool ContainerTypeQ
Helper template variable that says if an MArgumentType is a LibraryLink container type.
Definition: MArgument.h:59
void addToDataStore(DataStore ds, const std::string &name, MArgumentType actualType=T) const
Add arg to the DataStore ds inside a node named name The optional parameter should only be used by ex...
Definition: MArgument.h:143
constexpr bool PrimitiveQ
Type trait for checking if T is a primitive LibraryLink type (belongs to the MArgument union)
Definition: MArgument.h:46
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
This is a class template, where template parameter T is the type of data elements....
Definition: NumericArray.h:54
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
This is a class template, where template parameter T is the type of data elements....
Definition: Image.h:127
value_type * getAddress() const
Get address of the value stored in MArgument.
std::variant< std::monostate, mbool, mint, mreal, mcomplex, MTensor, MSparseArray, MNumericArray, MImage, char *, DataStore > PrimitiveAny
A variant holding all possible MArgument types.
Definition: MArgument.h:38
This is a class template, where template parameter T is the type of data elements....
Definition: Tensor.h:53
static void addDataStoreNode(DataStore ds, std::string_view name, value_type val)
Add val to the DataStore ds inside a node named name This is a static method because there is no MArg...
const value_type & get() const
Get the read-only value stored in MArgument.
Small class that wraps a reference to MArgument and provides proper API to work with this MArgument.
Definition: MArgument.h:76
PrimitiveWrapper(MArgument &a)
Construct PrimitiveWrapper from a reference to MArgument.
Definition: MArgument.h:86
value_type & get()
Get the value stored in MArgument.
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
Strongly typed wrapper for MSparseArray.
Definition: SparseArray.h:20
constexpr bool alwaysFalse
Helper template variable that is always false.
Definition: MArgument.h:67
Argument::CType< T > value_type
This is the actual type of data stored in arg.
Definition: MArgument.h:79
static void addDataStoreNode(DataStore ds, value_type val)
Add val to the DataStore ds inside an unnamed node This is a static method because there is no MArgum...
constexpr MArgumentType PrimitiveIndex
PrimitiveIndex<T> is the index of type T in the PrimitiveAny variant converted to MArgumentType enum.
Definition: MArgument.h:42
Short but generally useful functions.