LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Main namespace of LibraryLink Utilities. More...
Main namespace of LibraryLink Utilities.
Every symbol defined in LLU will be in this namespace, but one needs to remember that LLU internally includes WolframLibrary and WSTP headers which define C APIs and therefore do not use namespaces and in consequence will inject names in the global namespace.
Namespaces | |
Argument | |
Namespace for functionality related to arguments passed from LibraryLink to library functions and their types. | |
ErrorCode | |
Error codes predefined in Library Link. | |
ErrorName | |
Names of all errors used across LLU. | |
NA | |
Small namespace for NumericArray related utilities. | |
WS | |
Contains definitions related to WSTP functionality in LLU. | |
Classes | |
struct | AlwaysReadExclusiveWrite |
Default policy for Import/Export paclets - always allow reading, deny writing when we write. More... | |
class | DataList |
Top-level wrapper over LibraryLink's DataStore. More... | |
class | DataNode |
Wrapper over DataStoreNode structure from LibraryLink. More... | |
class | DataStoreIterator |
Proxy input iterator over DataStoreNodes, when dereferenced yields GenericDataNode proxy objects. More... | |
struct | dependent_false |
Get a type that inherits from false_type and ignores the template parameter completely. More... | |
class | ErrorManager |
"Static" class responsible for error registration and throwing More... | |
struct | GenericDataNode |
Basic wrapper over DataStoreNode, provides class-like interface and conversion of the underlying value from MArgument to TypedArgument. More... | |
class | Image |
This is a class template, where template parameter T is the type of data elements. Image is derived from MArray. More... | |
struct | ImageInterface |
Abstract class that defines a basic set of operations on an image. More... | |
class | ImageView |
Simple, light-weight, non-owning wrappper over MImage. More... | |
class | IterableContainer |
Abstract class that provides iterators (c/r/begin and c/r/end methods) and subscript operator for any contiguous container. More... | |
struct | LibraryData |
This structure offers a static copy of WolframLibData accessible throughout the whole life of the DLL. More... | |
class | LibraryLinkError |
Class representing an exception in paclet code. More... | |
class | Logger |
Logger class is responsible for sending log messages via WSTP to Mathematica. More... | |
class | ManagedExpressionStore |
ManagedExpressionStore will keep track of instances of managed class T and will provide safe access to them. More... | |
class | MArgumentManager |
Manages arguments exchanged between the paclet C++ code and LibraryLink interface. More... | |
class | MArray |
This is a class template, where template parameter T is the type of data elements. MArray is the base class for NumericArray, Tensor and Image. More... | |
class | MArrayDimensions |
Helper class that carries meta-information about container's size and dimensions. More... | |
class | MContainer |
MContainer is an abstract class template for generic containers. Only specializations shall be used. More... | |
class | MContainer< MArgumentType::DataStore > |
MContainer specialization for DataStore, provides basic list interface for the underlying raw DataStore. More... | |
class | MContainer< MArgumentType::Image > |
MContainer specialization for MImage. More... | |
class | MContainer< MArgumentType::NumericArray > |
MContainer specialization for MNumericArray. More... | |
class | MContainer< MArgumentType::SparseArray > |
MContainer specialization for MSparseArray. More... | |
class | MContainer< MArgumentType::Tensor > |
MContainer specialization for MTensor. More... | |
class | MContainerBase |
Template of the base class for all generic containers. More... | |
struct | NameAdaptor |
Iterator adaptor for DataList that makes begin() and end() return proxy iterators for node names. More... | |
struct | NodeIterator |
Simple proxy input iterator that goes over a DataStore and returns proxy DataNodes when dereferenced. More... | |
struct | NodeNameIterator |
Simple proxy input iterator that goes over a DataStore and returns node names when dereferenced. More... | |
struct | NodeValueIterator |
Simple proxy input iterator that goes over a DataStore and returns node values of requested type when dereferenced. More... | |
class | NumericArray |
This is a class template, where template parameter T is the type of data elements. NumericArray is derived from MArray. More... | |
struct | NumericArrayFromEnum |
Utility structure that matches an MNumericArray data type with corresponding C++ type. More... | |
struct | NumericArrayInterface |
Abstract class that defines a basic set of operations on a numeric array. More... | |
class | NumericArrayTypedView |
Simple, light-weight, non-owning wrappper over MNumericArray. More... | |
class | NumericArrayView |
Simple, light-weight, non-owning, data-type-agnostic wrappper over MNumericArray. More... | |
class | PrimitiveWrapper |
Small class that wraps a reference to MArgument and provides proper API to work with this MArgument. More... | |
class | ProgressMonitor |
Stores and updates current progress of computation in a location shared between the library and WL Kernel. More... | |
struct | SharePolicy |
Base class for shared access policies on Windows. More... | |
class | SparseArray |
Strongly typed wrapper for MSparseArray. More... | |
class | Tensor |
This is a class template, where template parameter T is the type of data elements. Tensor is derived from MArray. More... | |
struct | TensorInterface |
Abstract class that defines a basic set of operations on a tensor. More... | |
class | TensorView |
Simple, light-weight, non-owning wrappper over MTensor. More... | |
class | TypedImage |
Typed interface for Image. More... | |
class | TypedNumericArray |
Typed interface for NumericArray. More... | |
class | TypedTensor |
Typed interface for Tensor. More... | |
struct | ValueAdaptor |
Iterator adaptor for DataList that makes begin() and end() return proxy iterators for node values. More... | |
class | WSStream |
Wrapper class over WSTP with a stream-like interface. More... | |
Type aliases | |
using | BasicPool = Async::BasicThreadPool< Async::ThreadsafeQueue< Async::FunctionWrapper > > |
Alias for BasicThreadPool with ThreadsafeQueue storing Async::FunctionWrappers. More... | |
using | ThreadPool = Async::GenericThreadPool< Async::ThreadsafeQueue< Async::FunctionWrapper >, Async::WorkStealingQueue< std::deque< Async::FunctionWrapper > >> |
Alias for GenericThreadPool with ThreadsafeQueue and WorkStealingQueue storing Async::FunctionWrappers. More... | |
using | GenericDataList = MContainer< MArgumentType::DataStore > |
MContainer specialization for DataStore is called GenericDataList. More... | |
using | GenericImage = MContainer< MArgumentType::Image > |
MContainer specialization for MImage is called GenericImage. More... | |
using | GenericNumericArray = MContainer< MArgumentType::NumericArray > |
MContainer specialization for MNumericArray is called GenericNumericArray. More... | |
using | GenericSparseArray = MContainer< MArgumentType::SparseArray > |
MContainer specialization for MSparseArray is called GenericSparseArray. More... | |
using | GenericTensor = MContainer< MArgumentType::Tensor > |
MContainer specialization for MTensor is called GenericTensor. More... | |
using | FilePtr = std::unique_ptr< std::FILE, int(*)(std::FILE *)> |
Smart pointer type around std::FILE. More... | |
template<typename T > | |
using | remove_cv_ref = std::remove_cv_t< std::remove_reference_t< T > > |
Utility type that strips any given type from reference and cv qualifiers. More... | |
template<typename A , typename B > | |
using | disable_if_same_or_derived = typename std::enable_if_t<!std::is_same< A, B >::value &&!std::is_base_of< A, remove_cv_ref< B > >::value > |
Utility type that is valid only if B is not A and not a subclass of A. More... | |
template<typename A , typename B > | |
using | enable_if_same_or_derived = typename std::enable_if_t< std::is_same< A, B >::value||std::is_base_of< A, remove_cv_ref< B > >::value > |
Utility type that is valid only if B is A or a subclass of A. More... | |
template<typename Iterator > | |
using | enable_if_input_iterator = enable_if_same_or_derived< std::input_iterator_tag, typename std::iterator_traits< Iterator >::iterator_category > |
Utility type that checks if given type can be treated as input iterator. More... | |
template<typename Container > | |
using | enable_if_integral_elements = typename std::enable_if_t< std::is_integral< typename std::remove_reference_t< Container >::value_type >::value > |
Utility type that checks if given container type has elements that are integers (and therefore can be used as Tensor or NumericArray dimensions) More... | |
template<numericarray_data_t rat> | |
using | NumericArrayTypeFromEnum = typename NumericArrayFromEnum< rat >::type |
Simple type alias to easily extract type from NumericArrayFromEnum. More... | |
Enumerations | |
enum | Ownership : uint8_t { Ownership::LibraryLink, Ownership::Library, Ownership::Shared } |
An enum listing possible owners of a LibraryLink container. More... | |
enum | MArgumentType { MArgument = MType_Undef, Boolean = MType_Boolean, Integer = MType_Integer, Real = MType_Real, Complex = MType_Complex, Tensor = MType_Tensor, SparseArray = MType_SparseArray, NumericArray = MType_NumericArray, Image = MType_Image, UTF8String = MType_UTF8String, DataStore = MType_DataStore } |
Strongly type enum with possible types of data stored in MArgument. More... | |
enum | Passing { Automatic, Constant, Manual, Shared } |
Enumerated type representing different modes in which a container can be passed from LibraryLink to the library. More... | |
Functions | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &os, const MArray< T > &c) |
Insertion operator to allow pretty-printing of MArray. More... | |
template<typename F > | |
auto | asTypedSparseArray (const GenericSparseArray &sa, F &&callable) |
Take a SparseArray-like object t and a function callable and call the function with a SparseArrayTypedView created from t . More... | |
template<typename ImageT , typename F > | |
auto | asTypedImage (ImageT &&img, F &&callable) |
Take a Image-like object img and a function callable and call the function with a ImageTypedView created from img . More... | |
template<typename NumericArrayT , typename F > | |
auto | asTypedNumericArray (NumericArrayT &&na, F &&callable) |
Take a NumericArray-like object na and a function callable and call the function with a NumericArrayTypedView created from na . More... | |
template<typename TensorT , typename F > | |
auto | asTypedTensor (TensorT &&t, F &&callable) |
Take a Tensor-like object t and a function callable and call the function with a TensorTypedView created from t . More... | |
FilePtr | claimFile (std::FILE *f) |
Create a unique owning pointer of a FILE. More... | |
void | validatePath (const std::string &fileName, std::ios::openmode mode) |
Check if the file fileName under open mode mode is accessible in the current sandbox setting. More... | |
template<typename T > | |
std::basic_string< T > | fromUTF8toUTF16 (const std::string &source) |
Convert string from UTF8 to UTF16. More... | |
template<typename T > | |
std::string | fromUTF16toUTF8 (const std::basic_string< T > &source) |
Convert string from UTF16 to UTF8. More... | |
template<typename T > | |
std::basic_string< T > | fromUTF8toUTF32 (const std::string &source) |
Convert string from UTF8 to UTF32. More... | |
template<typename T > | |
std::string | fromUTF32toUTF8 (const std::basic_string< T > &source) |
Convert string from UTF32 to UTF8. More... | |
FilePtr | openFile (const std::string &fileName, std::ios::openmode mode, const SharePolicy &shp=AlwaysReadExclusiveWrite {}) |
Open given file with specified mode (read, write, append, etc.). More... | |
std::fstream | openFileStream (const std::string &fileName, std::ios::openmode mode, const SharePolicy &shp=AlwaysReadExclusiveWrite {}) |
Open a file stream with specified mode (read, write, append, etc.). More... | |
template<class T > | |
void | manageInstanceCallback (WolframLibraryData, mbool, mint) |
A template for library callback used by LibraryLink to manage instances of ManagedLibraryExpressions. More... | |
template<typename VariantType , typename T , std::size_t index = 0> | |
constexpr std::size_t | variant_index () |
Get index of given type in the variant. More... | |
template<typename... Ts> | |
void | Unused (Ts &&...) |
Dummy function called on otherwise unused parameters to eliminate compiler warnings. More... | |
EXTERN_C DLLEXPORT int | sendRegisteredErrors ([[maybe_unused]] WolframLibraryData libData, WSLINK mlp) |
LibraryLink function that LLU will call to send all errors registered in C++ to the Wolfram Language layer. More... | |
LIBRARY_LINK_FUNCTION (setExceptionDetailsContext) | |
LibraryLink function that LLU will call to set the context for the symbol, to which exception details are assigned. More... | |
LIBRARY_LINK_FUNCTION (setLoggerContext) | |
LibraryLink function that LLU will call to set the context for the symbol, to which log details are assigned. More... | |
Variables | |
template<MArgumentType T> | |
constexpr bool | alwaysFalse = false |
Helper template variable that is always false. More... | |
template<typename Container > | |
constexpr bool | has_size_v = has_size<Container>::value |
A type trait to check whether type Container has a member function size() More... | |
template<typename Container , typename T > | |
constexpr bool | is_iterable_container_with_matching_type_v |
A type trait to check whether type Container is a class type with a member type alias value_type equal to T and with begin() and end() methods. More... | |
template<typename T > | |
constexpr bool | dependent_false_v = dependent_false<T>::value |
Compile-time boolean constant false that "depends" on a template parameter. More... | |
template<typename T > | |
constexpr imagedata_t | ImageType = MImage_Type_Undef |
Utility variable template that matches a C++ type with a corresponding MImage data type. More... | |
template<typename T > | |
constexpr numericarray_data_t | NumericArrayType = MNumericArray_Type_Undef |
Utility structure that matches a C++ type with a corresponding MNumericArray data type. More... | |
template<typename T > | |
constexpr mint | TensorType = MType_Undef |
Utility structure that matches a C++ type with a corresponding MTensor data type. More... | |
using LLU::BasicPool = typedef Async::BasicThreadPool<Async::ThreadsafeQueue<Async::FunctionWrapper> > |
Alias for BasicThreadPool with ThreadsafeQueue storing Async::FunctionWrappers.
Good default choice for a thread pool for any paclet.
using LLU::disable_if_same_or_derived = typedef typename std::enable_if_t<!std::is_same<A, B>::value && !std::is_base_of<A, remove_cv_ref<B> >::value> |
Utility type that is valid only if B is not A and not a subclass of A.
A | - any type |
B | - any type, will be stripped of reference and cv-qualifiers before comparing with A |
using LLU::enable_if_input_iterator = typedef enable_if_same_or_derived<std::input_iterator_tag, typename std::iterator_traits<Iterator>::iterator_category> |
Utility type that checks if given type can be treated as input iterator.
Iterator | - iterator type |
using LLU::enable_if_integral_elements = typedef typename std::enable_if_t<std::is_integral<typename std::remove_reference_t<Container>::value_type>::value> |
Utility type that checks if given container type has elements that are integers (and therefore can be used as Tensor or NumericArray dimensions)
Container | - container type |
using LLU::enable_if_same_or_derived = typedef typename std::enable_if_t<std::is_same<A, B>::value || std::is_base_of<A, remove_cv_ref<B> >::value> |
Utility type that is valid only if B is A or a subclass of A.
A | - any type |
B | - any type, will be stripped of reference and cv-qualifiers before comparing with A |
using LLU::FilePtr = typedef std::unique_ptr<std::FILE, int (*)(std::FILE*)> |
Smart pointer type around std::FILE.
using LLU::GenericDataList = typedef MContainer<MArgumentType::DataStore> |
MContainer specialization for DataStore is called GenericDataList.
using LLU::GenericImage = typedef MContainer<MArgumentType::Image> |
MContainer specialization for MImage is called GenericImage.
using LLU::GenericNumericArray = typedef MContainer<MArgumentType::NumericArray> |
MContainer specialization for MNumericArray is called GenericNumericArray.
using LLU::GenericSparseArray = typedef MContainer<MArgumentType::SparseArray> |
MContainer specialization for MSparseArray is called GenericSparseArray.
using LLU::GenericTensor = typedef MContainer<MArgumentType::Tensor> |
MContainer specialization for MTensor is called GenericTensor.
using LLU::NumericArrayTypeFromEnum = typedef typename NumericArrayFromEnum<rat>::type |
Simple type alias to easily extract type from NumericArrayFromEnum.
using LLU::remove_cv_ref = typedef std::remove_cv_t<std::remove_reference_t<T> > |
Utility type that strips any given type from reference and cv qualifiers.
T | - any type |
using LLU::ThreadPool = typedef Async::GenericThreadPool<Async::ThreadsafeQueue<Async::FunctionWrapper>, Async::WorkStealingQueue<std::deque<Async::FunctionWrapper> >> |
Alias for GenericThreadPool with ThreadsafeQueue and WorkStealingQueue storing Async::FunctionWrappers.
Good choice for a thread pool if the tasks that will be executed involve submitting new tasks for the pool.
|
strong |
Strongly type enum with possible types of data stored in MArgument.
|
strong |
An enum listing possible owners of a LibraryLink container.
Ownership determines the memory management of a container.
Enumerator | |
---|---|
LibraryLink | LibraryLink is responsible for managing the container's memory. Corresponds to Automatic and "Constant" passing. |
Library | The library (LLU) is responsible for managing the container's memory. Used for Manual passing and containers created by the library. |
Shared | When the container is shared LLU only needs to decrease share count when it's done. Only used for arguments passed as "Shared". |
|
strong |
Enumerated type representing different modes in which a container can be passed from LibraryLink to the library.
auto LLU::asTypedImage | ( | ImageT && | img, |
F && | callable | ||
) |
Take a Image-like object img
and a function callable
and call the function with a ImageTypedView created from img
.
ImageT | - a Image-like type (GenericImage, ImageView or MNumericAray) |
F | - any callable object |
img | - Image-like object on which an operation will be performed |
callable | - a callable object that can be called with a ImageTypedView of any type |
callable
on a ImageTypedView over img
auto LLU::asTypedNumericArray | ( | NumericArrayT && | na, |
F && | callable | ||
) |
Take a NumericArray-like object na
and a function callable
and call the function with a NumericArrayTypedView created from na
.
NumericArrayT | - a NumericArray-like type (GenericNumericArray, NumericArrayView or MNumericAray) |
F | - any callable object |
na | - NumericArray-like object on which an operation will be performed |
callable | - a callable object that can be called with a NumericArrayTypedView of any type |
callable
on a NumericArrayTypedView over na
auto LLU::asTypedSparseArray | ( | const GenericSparseArray & | sa, |
F && | callable | ||
) |
Take a SparseArray-like object t
and a function callable
and call the function with a SparseArrayTypedView created from t
.
SparseArrayT | - a SparseArray-like type (GenericSparseArray, SparseArrayView or MNumericArray) |
F | - any callable object |
t | - SparseArray-like object on which an operation will be performed |
callable | - a callable object that can be called with a SparseArrayTypedView of any type |
callable
on a SparseArrayTypedView over t
auto LLU::asTypedTensor | ( | TensorT && | t, |
F && | callable | ||
) |
Take a Tensor-like object t
and a function callable
and call the function with a TensorTypedView created from t
.
TensorT | - a Tensor-like type (GenericTensor, TensorView or MNumericAray) |
F | - any callable object |
t | - Tensor-like object on which an operation will be performed |
callable | - a callable object that can be called with a TensorTypedView of any type |
callable
on a TensorTypedView over t
FilePtr LLU::claimFile | ( | std::FILE * | f | ) |
Create a unique owning pointer of a FILE.
f | - a stream pointer obtained from fopen |
f
that will call fclose
on f
in destructor f
is not a result of fopen
, the behavior is undefined std::string LLU::fromUTF16toUTF8 | ( | const std::basic_string< T > & | source | ) |
Convert string from UTF16 to UTF8.
T | - character type of the UTF16 string, supported types are char16_t, char32_t, or wchar_t |
source | - string in UTF16 encoding |
std::string LLU::fromUTF32toUTF8 | ( | const std::basic_string< T > & | source | ) |
Convert string from UTF32 to UTF8.
T | - character type of the UTF32 string |
source | - string in UTF32 encoding |
std::basic_string<T> LLU::fromUTF8toUTF16 | ( | const std::string & | source | ) |
Convert string from UTF8 to UTF16.
T | - character type for the result, supported types are char16_t, char32_t, or wchar_t |
source | - string in UTF8 encoding |
std::basic_string<T> LLU::fromUTF8toUTF32 | ( | const std::string & | source | ) |
Convert string from UTF8 to UTF32.
T | - character type for the result |
source | - string in UTF8 encoding |
LLU::LIBRARY_LINK_FUNCTION | ( | setExceptionDetailsContext | ) |
LLU::LIBRARY_LINK_FUNCTION | ( | setLoggerContext | ) |
void LLU::manageInstanceCallback | ( | WolframLibraryData | , |
mbool | , | ||
mint | |||
) |
A template for library callback used by LibraryLink to manage instances of ManagedLibraryExpressions.
Specializations should typically just call manageInstance method from the ManagedExpressionStore corresponding to class T.
T | - class to be managed |
FilePtr LLU::openFile | ( | const std::string & | fileName, |
std::ios::openmode | mode, | ||
const SharePolicy & | shp = AlwaysReadExclusiveWrite {} |
||
) |
Open given file with specified mode (read, write, append, etc.).
Checks with WolframLibraryData if the path is "valid" (we don't know what that really means). Converts file name to UTF-16 wide string on Windows. Uses open modes from std::ios.
fileName | - path to the input file |
mode | - file open mode |
shp | - shared access policy, only used on Windows. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/sharing-constants |
ErrorName::OpenFileFailed | if the file could not be opened |
std::fstream LLU::openFileStream | ( | const std::string & | fileName, |
std::ios::openmode | mode, | ||
const SharePolicy & | shp = AlwaysReadExclusiveWrite {} |
||
) |
Open a file stream with specified mode (read, write, append, etc.).
Checks with WolframLibraryData if the path is "valid" (we don't know what that really means). Converts file name to UTF-16 wide string on Windows.
fileName | - path to the input file |
mode | - file open mode |
shp | - shared access policy, only used on Windows. See https://docs.microsoft.com/en-us/cpp/c-runtime-library/sharing-constants |
ErrorName::OpenFileFailed | if the file could not be opened |
std::ostream& LLU::operator<< | ( | std::ostream & | os, |
const MArray< T > & | c | ||
) |
EXTERN_C DLLEXPORT int LLU::sendRegisteredErrors | ( | [[maybe_unused] ] WolframLibraryData | libData, |
WSLINK | mlp | ||
) |
LibraryLink function that LLU will call to send all errors registered in C++ to the Wolfram Language layer.
This way LLU is able to translate exceptions from C++ to appropriate Failure expressions in the Wolfram Language.
libData | - WolframLibraryData |
mlp | - WSTP link to transfer data |
void LLU::Unused | ( | Ts && | ... | ) |
Dummy function called on otherwise unused parameters to eliminate compiler warnings.
Ts | - variadic template parameter, any number of arbitrary types |
void LLU::validatePath | ( | const std::string & | fileName, |
std::ios::openmode | mode | ||
) |
Check if the file fileName
under open mode mode
is accessible in the current sandbox setting.
fileName | - file whose path is to be validated |
mode | - file open mode |
|
constexpr |
Get index of given type in the variant.
VariantType | - any variant type |
T | - any type, if T is repeated in the variant, index of the first occurrence will be returned |
index | - implementation detail, do not specify explicitly |
|
inlineconstexpr |
Helper template variable that is always false.
Useful in meta-programming.
|
inlineconstexpr |
Compile-time boolean constant false that "depends" on a template parameter.
Useful utility for static_assert.
|
inlineconstexpr |
A type trait to check whether type Container
has a member function size()
|
inlineconstexpr |
Utility variable template that matches a C++ type with a corresponding MImage data type.
|
inlineconstexpr |
A type trait to check whether type Container
is a class type with a member type alias value_type
equal to T and with begin() and end() methods.
|
inlineconstexpr |
Utility structure that matches a C++ type with a corresponding MNumericArray data type.
|
inlineconstexpr |
Utility structure that matches a C++ type with a corresponding MTensor data type.