 |
LibraryLink Utilities
3.0.1
Modern C++ wrapper over LibraryLink and WSTP
|
Go to the documentation of this file.
6 #ifndef LLU_CONTAINERS_GENERIC_BASE_HPP
7 #define LLU_CONTAINERS_GENERIC_BASE_HPP
34 template<MArgumentType Type>
65 mc.container =
nullptr;
78 reset(mc.container, mc.owner);
79 mc.container =
nullptr;
117 return shareCountImpl();
126 void pass(MArgument& res)
const {
151 if (container ==
nullptr) {
162 if constexpr (Type == MArgumentType::DataStore) {
164 }
else if constexpr (Type == MArgumentType::Image) {
166 }
else if constexpr (Type == MArgumentType::NumericArray) {
168 }
else if constexpr (Type == MArgumentType::SparseArray) {
170 }
else if constexpr (Type == MArgumentType::Tensor) {
173 static_assert(alwaysFalse<Type>,
"Unsupported MContainer type.");
182 if constexpr (Type == MArgumentType::DataStore) {
184 }
else if constexpr (Type == MArgumentType::Image) {
186 }
else if constexpr (Type == MArgumentType::NumericArray) {
188 }
else if constexpr (Type == MArgumentType::SparseArray) {
190 }
else if constexpr (Type == MArgumentType::Tensor) {
193 static_assert(alwaysFalse<Type>,
"Unsupported MContainer type.");
203 if (newCont != container) {
215 owner = newOwnerMode;
222 virtual mint shareCountImpl()
const = 0;
228 virtual void passImpl(MArgument& res)
const = 0;
241 template<MArgumentType Type,
typename std::enable_if_t<Argument::ContainerTypeQ<Type>,
int> = 0>
244 #else // On other platforms we get a nice, compile-time error.
246 static_assert(alwaysFalse<Type>,
"Trying to instantiate unspecialized MContainer template.");
251 #endif // LLU_CONTAINERS_GENERIC_BASE_HPP
Template of the base class for all generic containers.
Definition: Base.hpp:35
Ownership getOwner() const noexcept
Get ownership information.
Definition: Base.hpp:141
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
void reset(Container newCont, Ownership newOwnerMode=Ownership::Library) noexcept
Set a new internal container safely disposing of the old one.
Definition: Base.hpp:202
MContainerBase & operator=(MContainerBase &&mc) noexcept
Move-assignment operator disposes of the current raw container and steals the new one keeping its own...
Definition: Base.hpp:76
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
@ Shared
When the container is shared LLU only needs to decrease share count when it's done....
void disown() const noexcept
Disown internal container if present.
Definition: Base.hpp:158
static const st_WolframSparseLibrary_Functions * SparseArrayAPI()
Get a pointer to structure with function pointers to MSparseArray API.
Definition: LibraryData.cpp:37
mint shareCount() const noexcept
Return share count of internal container, if present and 0 otherwise.
Definition: Base.hpp:115
MContainerBase()=default
Default constructor, creates an empty wrapper.
MContainerBase & operator=(const MContainerBase &mc)=delete
Copy-assignment is deleted, same as copy-constructor.
MContainerBase(Container c, Ownership owner)
Create MContainerBase from a raw container and its owner.
Definition: Base.hpp:51
static WolframLibraryData API()
Get currently owned WolframLibraryData, if any.
Definition: LibraryData.cpp:22
MContainerBase(const MContainerBase &mc)=delete
Container wrappers are non-copyable, they act somewhat like unique_ptr around the raw container.
Argument::CType< Type > Container
The type of underlying LibraryLink structure (e.g. MTensor, MImage, etc.) will be called "Container".
Definition: Base.hpp:38
MContainerBase(MContainerBase &&mc) noexcept
Move-constructor steals the raw container keeping the ownership info.
Definition: Base.hpp:64
@ Library
The library (LLU) is responsible for managing the container's memory. Used for Manual passing and con...
const std::string CreateFromNullError
attempting to create a generic container from nullptr
static const st_WolframImageLibrary_Functions * ImageAPI()
Get a pointer to structure with function pointers to MImage API.
Definition: LibraryData.cpp:41
Container getContainer() const noexcept
Get internal container.
Definition: Base.hpp:97
Container cloneContainer() const
Clone the raw container, if it's present.
Definition: Base.hpp:150
void pass(MArgument &res) const
Pass the internal container as result of a LibraryLink function.
Definition: Base.hpp:126
Definition of the ErrorManager class responsible for error registration and throwing.
static void throwException(const std::string &errorName, T &&... args)
Throw exception with given name.
Definition: ErrorManager.h:199
virtual ~MContainerBase() noexcept
Destructor takes appropriate action depending on the ownership info.
Definition: Base.hpp:85
static const st_WolframNumericArrayLibrary_Functions * NumericArrayAPI()
Get a pointer to structure with function pointers to MNumericArray API.
Definition: LibraryData.cpp:33
Container abandonContainer() const noexcept
Give a handle to internal container and stop owning it.
Definition: Base.hpp:107
void free() const noexcept
Free internal container if present.
Definition: Base.hpp:178
@ LibraryLink
LibraryLink is responsible for managing the container's memory. Corresponds to Automatic and "Constan...
static bool hasLibraryData()
Check if libData is populated.
Definition: LibraryData.cpp:18
static const st_WolframIOLibrary_Functions * DataStoreAPI()
Get a pointer to structure with function pointers to DataStore API.
Definition: LibraryData.cpp:45
Template class and utilities to work with MArgument in type-safe manner.
Ownership
An enum listing possible owners of a LibraryLink container.
Definition: Base.hpp:22
Short but generally useful functions.