LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
Generic/NumericArray.hpp
Go to the documentation of this file.
1 
5 #ifndef LLU_CONTAINERS_GENERIC_NUMERICARRAY_HPP
6 #define LLU_CONTAINERS_GENERIC_NUMERICARRAY_HPP
7 
10 
11 namespace LLU {
12 
13  template<>
14  class MContainer<MArgumentType::NumericArray>;
15 
17  using GenericNumericArray = MContainer<MArgumentType::NumericArray>;
18 
22  template<>
23  class MContainer<MArgumentType::NumericArray> : public NumericArrayInterface, public MContainerBase<MArgumentType::NumericArray> {
24  public:
27 
31  MContainer() = default;
32 
40  MContainer(numericarray_data_t type, mint rank, const mint* dims);
41 
50  GenericNumericArray convert(numericarray_data_t t, NA::ConversionMethod method, double param) const;
51 
57  MContainer clone() const {
58  return MContainer {cloneContainer(), Ownership::Library};
59  }
60 
62  mint getRank() const override {
63  return LibraryData::NumericArrayAPI()->MNumericArray_getRank(this->getContainer());
64  }
65 
67  mint const* getDimensions() const override {
68  return LibraryData::NumericArrayAPI()->MNumericArray_getDimensions(this->getContainer());
69  }
70 
72  mint getFlattenedLength() const override {
73  return LibraryData::NumericArrayAPI()->MNumericArray_getFlattenedLength(this->getContainer());
74  }
75 
77  numericarray_data_t type() const override {
78  return LibraryData::NumericArrayAPI()->MNumericArray_getType(this->getContainer());
79  }
80 
82  void* rawData() const noexcept override {
83  return LibraryData::NumericArrayAPI()->MNumericArray_getData(this->getContainer());
84  }
85 
86  private:
87 
92  Container cloneImpl() const override;
93 
98  mint shareCountImpl() const noexcept override {
99  return LibraryData::NumericArrayAPI()->MNumericArray_shareCount(this->getContainer());
100  }
101 
103  void passImpl(MArgument& res) const noexcept override {
104  MArgument_setMNumericArray(res, this->getContainer());
105  }
106  };
107 
108 } // namespace LLU
109 
110 #endif // LLU_CONTAINERS_GENERIC_NUMERICARRAY_HPP
LLU::MContainerBase
Template of the base class for all generic containers.
Definition: Base.hpp:35
LLU::NumericArrayInterface
Abstract class that defines a basic set of operations on a numeric array.
Definition: Interfaces.h:106
LLU::MContainer< MArgumentType::NumericArray >::type
numericarray_data_t type() const override
Get the data type of this array.
Definition: Generic/NumericArray.hpp:77
LLU::MContainer< MArgumentType::NumericArray >
MContainer specialization for MNumericArray.
Definition: Generic/NumericArray.hpp:23
LLU
Main namespace of LibraryLink Utilities.
Definition: Queue.h:13
LLU::MContainer
MContainer is an abstract class template for generic containers. Only specializations shall be used.
Definition: Base.hpp:245
LLU::Argument::Typed::NumericArray
MContainer< MArgumentType::NumericArray > NumericArray
NumericArray stands for a GenericNumericArray - type agnostic wrapper over MNumericArray.
Definition: TypedMArgument.h:53
LLU::MContainer< MArgumentType::NumericArray >::getRank
mint getRank() const override
Get rank.
Definition: Generic/NumericArray.hpp:62
LLU::NA::ConversionMethod
ConversionMethod
Possible methods of handling out-of-range data when converting a NumericArray to different type.
Definition: Utilities.hpp:207
LLU::Ownership::Library
@ Library
The library (LLU) is responsible for managing the container's memory. Used for Manual passing and con...
LLU::MContainer< MArgumentType::NumericArray >::MContainer
MContainer()=default
Default constructor, the MContainer does not manage any instance of MNumericArray.
LLU::MContainer< MArgumentType::NumericArray >::getFlattenedLength
mint getFlattenedLength() const override
Get length.
Definition: Generic/NumericArray.hpp:72
Base.hpp
Definitions of MContainerBase and MContainer class templates.
LLU::MContainer< MArgumentType::NumericArray >::rawData
void * rawData() const noexcept override
Get access to the raw data.
Definition: Generic/NumericArray.hpp:82
LLU::MContainer< MArgumentType::NumericArray >::getDimensions
mint const * getDimensions() const override
Get dimensions.
Definition: Generic/NumericArray.hpp:67
LLU::LibraryData::NumericArrayAPI
static const st_WolframNumericArrayLibrary_Functions * NumericArrayAPI()
Get a pointer to structure with function pointers to MNumericArray API.
Definition: LibraryData.cpp:33
LLU::MArgumentType
MArgumentType
Strongly type enum with possible types of data stored in MArgument.
Definition: MArgument.h:22
Interfaces.h
LLU::MContainer< MArgumentType::NumericArray >::clone
MContainer clone() const
Clone this MContainer, performs a deep copy of the underlying MNumericArray.
Definition: Generic/NumericArray.hpp:57