MocoExtendProblem: Interface Between OpenSim and MATLAB for Rapidly Developing Direct Collocation Goals in Moco 1.1.0
add custom Moco goals to existing matlab scripts
MxArray Class Reference

mxArray object wrapper for data conversion and manipulation. More...

#include <mxarray.h>

Public Member Functions

 MxArray ()
 Empty MxArray constructor.
 
MxArrayoperator= (std::nullptr_t)
 NULL assignment.
 
 MxArray (MxArray &&array) NOEXCEPT
 Move constructor.
 
MxArrayoperator= (MxArray &&rhs) NOEXCEPT
 Move assignment.
 
 MxArray (const mxArray *array)
 MxArray constructor from const mxArray*.
 
 MxArray (mxArray *array)
 MxArray constructor from mutable mxArray*.
 
MxArrayoperator= (const mxArray *rhs)
 Assignment from const mxArray*.
 
MxArrayoperator= (mxArray *rhs)
 Assignment from mutable mxArray*.
 
template<typename T >
 MxArray (const T &value)
 MxArray constructor from scalar.
 
virtual ~MxArray ()
 Destructor.
 
void swap (MxArray &rhs)
 Swap operation.
 
void reset (const mxArray *array=NULL)
 Reset an mxArray to a const mxArray*.
 
void reset (mxArray *array)
 Reset an mxArray.
 
mxArray * release ()
 Release managed mxArray* pointer, or clone if not owner.
 
mxArray * clone () const
 Clone mxArray.
 
const mxArray * get () const
 Conversion to const mxArray*.
 
mxArray * getMutable ()
 Get raw mxArray*.
 
 operator bool () const
 Return true if the array is not NULL.
 
bool isOwner () const
 Return true if owner.
 
template<typename T >
to () const
 Convert MxArray to a specified type.
 
template<typename T >
void to (T *value) const
 
template<typename T >
at (mwIndex index) const
 Template for element accessor.
 
template<typename T >
void at (mwIndex index, T *value) const
 
const mxArray * at (mwIndex index) const
 
template<typename T >
at (mwIndex row, mwIndex column) const
 Template for element accessor.
 
template<typename T >
at (const std::vector< mwIndex > &subscripts) const
 Template for element accessor.
 
template<typename T >
at (const std::string &field, mwIndex index=0) const
 Struct element accessor.
 
template<typename T >
void at (const std::string &field, T *value, mwIndex index=0) const
 
const mxArray * at (const std::string &field, mwIndex index=0) const
 
template<typename T >
void set (mwIndex index, const T &value)
 Template for element write accessor.
 
template<typename T >
void set (mwIndex row, mwIndex column, const T &value)
 Template for element write accessor.
 
template<typename T >
void set (const std::vector< mwIndex > &subscripts, const T &value)
 Template for element write accessor.
 
void set (mwIndex index, mxArray *value)
 Cell element write accessor.
 
void set (mwIndex row, mwIndex column, mxArray *value)
 Cell element write accessor.
 
void set (const std::vector< mwIndex > &subscripts, mxArray *value)
 Cell element write accessor.
 
template<typename T >
void set (const std::string &field, const T &value, mwIndex index=0)
 Struct element write accessor.
 
void set (const std::string &field, mxArray *value, mwIndex index=0)
 Struct element write accessor.
 
template<typename T >
T * getData () const
 Get raw data pointer.
 
template<typename T >
T * getImagData () const
 Get raw data pointer to imaginary part.
 
mxLogical * getLogicals () const
 
mxChar * getChars () const
 
mxClassID classID () const
 Class ID of mxArray.
 
const std::string className () const
 Class name of mxArray.
 
mwSize size () const
 Number of elements in an array.
 
mwSize dimensionSize () const
 Number of dimensions.
 
std::vector< mwSize > dimensions () const
 Array of each dimension.
 
mwSize rows () const
 Number of rows in an array.
 
mwSize cols () const
 Number of columns in an array.
 
int fieldSize () const
 Number of fields in a struct array.
 
std::string fieldName (int index) const
 Get field name of a struct array.
 
std::vector< std::string > fieldNames () const
 Get field names of a struct array.
 
mwSize nonZeroMax () const
 Number of elements in IR, PR, and PI arrays.
 
mwIndex subscriptIndex (mwIndex row, mwIndex column) const
 Offset from first element to desired element.
 
mwIndex subscriptIndex (const std::vector< mwIndex > &subscripts) const
 Offset from first element to desired element.
 
bool isCell () const
 Determine whether input is cell array.
 
bool isChar () const
 Determine whether input is string array.
 
bool isVector () const
 Determine whether input is vector array.
 
bool isIntegral (const char *name) const
 Determine whether array is integral type.
 
bool isClass (const char *name) const
 Determine whether array is member of specified class.
 
bool isComplex () const
 Determine whether data is complex.
 
bool isDouble () const
 Determine whether mxArray represents data as double-precision, floating-point numbers.
 
bool isEmpty () const
 Determine whether array is empty.
 
bool isFromGlobalWS () const
 Determine whether array was copied from MATLAB global workspace.
 
bool isInt8 () const
 Determine whether array represents data as signed 8-bit integers.
 
bool isInt16 () const
 Determine whether array represents data as signed 16-bit integers.
 
bool isInt32 () const
 Determine whether array represents data as signed 32-bit integers.
 
bool isInt64 () const
 Determine whether array represents data as signed 64-bit integers.
 
bool isLogical () const
 Determine whether array is of type mxLogical.
 
bool isLogicalScalar () const
 Determine whether scalar array is of type mxLogical.
 
bool isLogicalScalarTrue () const
 Determine whether scalar array of type mxLogical is true.
 
bool isNumeric () const
 Determine whether array is numeric.
 
bool isSingle () const
 Determine whether array represents data as single-precision, floating-point numbers.
 
bool isSparse () const
 Determine whether input is sparse array.
 
bool isStruct () const
 Determine whether input is structure array.
 
bool isUint8 () const
 Determine whether array represents data as unsigned 8-bit integers.
 
bool isUint16 () const
 Determine whether array represents data as unsigned 16-bit integers.
 
bool isUint32 () const
 Determine whether array represents data as unsigned 32-bit integers.
 
bool isUint64 () const
 Determine whether array represents data as unsigned 64-bit integers.
 
bool hasField (const std::string &field_name, mwIndex index=0) const
 Determine whether a struct array has a specified field.
 
int elementSize () const
 Element size.
 

Static Public Member Functions

template<typename T >
static mxArray * Numeric (int rows=1, int columns=1)
 Create a new numeric (real or complex) matrix.
 
template<typename T >
static mxArray * Numeric (std::vector< std::size_t > dims)
 Create a new numeric (real or complex) matrix.
 
static mxArray * Logical (int rows=1, int columns=1)
 Create a new logical matrix.
 
static mxArray * Cell (int rows=1, int columns=1)
 Create a new cell matrix.
 
static mxArray * Struct (int nfields=0, const char **fields=NULL, int rows=1, int columns=1)
 Generic constructor for a struct matrix.
 
template<typename T >
static mxArray * from (const T &value)
 mxArray* importer methods.
 
static mxArray * from (const char *value)
 
static mxArray * from (int32_t value)
 
template<typename T >
static void to (const mxArray *array, T *value)
 mxArray* exporter methods.
 
template<typename T >
static T to (const mxArray *array)
 
template<typename T >
static T at (const mxArray *array, mwIndex index)
 mxArray* element reader methods.
 
template<typename T >
static void at (const mxArray *array, mwIndex index, T *value)
 
static const mxArray * at (const mxArray *array, mwIndex index)
 
template<typename T >
static void at (const mxArray *array, const std::string &field, T *value, mwIndex index=0)
 
static const mxArray * at (const mxArray *array, const std::string &field, mwIndex index=0)
 
template<typename T >
static void set (mxArray *array, mwIndex index, const T &value)
 mxArray* element writer methods.
 
static void set (mxArray *array, mwIndex index, mxArray *value)
 
template<typename T >
static void set (mxArray *array, const std::string &field, const T &value, mwIndex index=0)
 
static void set (mxArray *array, const std::string &field, mxArray *value, mwIndex index=0)
 
static bool IsFinite (double value)
 Determine whether input is finite.
 
static bool IsInf (double value)
 Determine whether input is infinite.
 
static bool IsNaN (double value)
 Determine whether input is NaN (Not-a-Number).
 
static double Inf ()
 Value of infinity.
 
static double NaN ()
 Value of NaN (Not-a-Number).
 
static double Eps ()
 Value of EPS.
 

Private Member Functions

 MxArray (const MxArray &array)
 Copy constructor is prohibited except internally.
 
MxArrayoperator= (const MxArray &rhs)
 Copy assignment operator is prohibited.
 

Static Private Member Functions

template<typename T >
static mxArray * fromInternal (const typename std::enable_if< MxArithmeticType< T >::value, T >::type &value)
 Templated mxArray importers

 
template<typename T >
static mxArray * fromInternal (const typename std::enable_if< MxComplexType< T >::value, T >::type &value)
 Complex types, complex<float> or complex<double>.
 
template<typename Container >
static mxArray * fromInternal (const typename std::enable_if< MxArithmeticCompound< Container >::value, Container >::type &value)
 Container with fundamental numerics, i.e.
 
template<typename Container >
static mxArray * fromInternal (const typename std::enable_if< MxComplexCompound< Container >::value, Container >::type &value)
 Container with complex numbers, i.e.
 
template<typename T >
static mxArray * fromInternal (const typename std::enable_if< MxCharType< T >::value, T >::type &value)
 Char type.
 
template<typename Container >
static mxArray * fromInternal (const typename std::enable_if<(MxCharCompound< Container >::value) &&(std::is_signed< typename Container::value_type >::value), Container >::type &value)
 Containter with signed char.
 
template<typename Container >
static mxArray * fromInternal (const typename std::enable_if<(MxCharCompound< Container >::value) &&!(std::is_signed< typename Container::value_type >::value), Container >::type &value)
 Container with unsigned char.
 
template<typename T >
static mxArray * fromInternal (const typename std::enable_if< MxLogicalType< T >::value, T >::type &value)
 Logicals.
 
template<typename Container >
static mxArray * fromInternal (const typename std::enable_if< MxLogicalCompound< Container >::value, Container >::type &value)
 Container with logicals.
 
template<typename Container >
static mxArray * fromInternal (const typename std::enable_if< MxCellCompound< Container >::value, Container >::type &value)
 Container with cell type content.
 
template<typename T >
static void toInternal (const mxArray *array, typename std::enable_if< MxArithmeticType< T >::value||MxComplexType< T >::value||MxLogicalType< T >::value||MxCharType< T >::value, T >::type *value)
 Templated mxArray exporters

 
template<typename T >
static void toInternal (const mxArray *array, typename std::enable_if< MxComplexOrArithmeticCompound< T >::value||MxLogicalCompound< T >::value||MxCharCompound< T >::value, T >::type *value)
 Vector types.
 
template<typename T >
static void toInternal (const mxArray *array, typename std::enable_if< MxCellType< T >::value &&(!std::is_compound< T >::value||MxCellType< typename T::value_type >::value), T >::type *value)
 Nested types (leads into recursive deduction).
 
template<typename T >
static void atInternal (const mxArray *array, mwIndex index, typename std::enable_if< MxComplexOrArithmeticType< T >::value||MxLogicalType< T >::value||MxCharType< T >::value, T >::type *value)
 Templated mxArray getters

 
template<typename T >
static void atInternal (const mxArray *array, mwIndex index, typename std::enable_if< std::is_compound< T >::value &&!MxComplexType< T >::value, T >::type *value)
 Converter for nested types.
 
template<typename T >
static void atInternal (const mxArray *array, const std::string &field, mwIndex index, T *value)
 Structure access.
 
template<typename T >
static void setInternal (mxArray *array, mwIndex index, const typename std::enable_if< !std::is_compound< T >::value||MxComplexType< T >::value, T >::type &value)
 Templated mxArray element setters

 
template<typename T >
static void setInternal (mxArray *array, mwIndex index, const typename std::enable_if< MxCellType< T >::value, T >::type &value)
 Container types.
 
template<typename T >
static void setInternal (mxArray *array, const std::string &field, mwIndex index, const T &value)
 Structure access.
 
template<typename T , typename R >
static void assignTo (const mxArray *array, mwIndex index, typename std::enable_if< std::is_integral< R >::value, R >::type *value)
 Assignment helpers (for MxArray.to<type>(value))

 
template<typename T , typename R >
static void assignTo (const mxArray *array, mwIndex index, typename std::enable_if< std::is_floating_point< R >::value, R >::type *value)
 Explicit floating point element assignment.
 
template<typename T , typename R >
static void assignTo (const mxArray *array, mwIndex index, typename std::enable_if< MxComplexType< R >::value, R >::type *value)
 Explicit complex element assignment.
 
template<typename R >
static void assignCharTo (const mxArray *array, mwIndex index, typename std::enable_if< std::is_signed< R >::value, R >::type *value)
 Explicit char (signed) element assignment.
 
template<typename R >
static void assignCharTo (const mxArray *array, mwIndex index, typename std::enable_if< !std::is_signed< R >::value, R >::type *value)
 Explicit char (unsigned) element assignment.
 
template<typename T >
static void assignCellTo (const mxArray *array, mwIndex index, T *value)
 Explicit cell element assignment.
 
template<typename T , typename R >
static void assignTo (const mxArray *array, typename std::enable_if< MxArithmeticCompound< R >::value||MxLogicalCompound< R >::value||MxCharCompound< R >::value, R >::type *value)
 Explicit numeric array assignment.
 
template<typename T , typename R >
static void assignTo (const mxArray *array, typename std::enable_if< MxComplexCompound< R >::value, R >::type *value)
 Explicit complex array assigment.
 
template<typename R >
static void assignStringTo (const mxArray *array, typename std::enable_if< std::is_signed< typename R::value_type >::value, R >::type *value)
 Explicit char (signed) array assignment.
 
template<typename R >
static void assignStringTo (const mxArray *array, typename std::enable_if< !std::is_signed< typename R::value_type >::value, R >::type *value)
 Explicit char (unsigned) array assignment.
 
template<typename T >
static void assignCellTo (const mxArray *array, T *value)
 Explicit cell array assignment.
 
template<typename R , typename T >
static void assignFrom (mxArray *array, mwIndex index, const typename std::enable_if< MxArithmeticType< T >::value||MxCharType< T >::value, T >::type &value)
 Assignment helpers (for MxArray.set<type>(i, value))

 
template<typename R , typename T >
static void assignFrom (mxArray *array, mwIndex index, const typename std::enable_if< MxComplexType< T >::value, T >::type &value)
 Explicit complex element assignment.
 
template<typename T >
static void assignCharFrom (mxArray *array, mwIndex index, const typename std::enable_if< std::is_floating_point< T >::value, T >::type &value)
 
template<typename T >
static void assignCharFrom (mxArray *array, mwIndex index, const typename std::enable_if< std::is_integral< T >::value &&std::is_signed< T >::value, T >::type &value)
 
template<typename T >
static void assignCharFrom (mxArray *array, mwIndex index, const typename std::enable_if< std::is_integral< T >::value &&!std::is_signed< T >::value, T >::type &value)
 
template<typename T >
static void assignCharFrom (mxArray *array, mwIndex index, const typename std::enable_if< MxComplexType< T >::value, T >::type &value)
 

Private Attributes

mxArray * array_
 Pointer to the mxArray C object.
 
bool owner_
 Flag to enable resource management.
 

Detailed Description

mxArray object wrapper for data conversion and manipulation.

The class is similar to a combination of unique_ptr and wrapper around Matlab's matrix API. An MxArray object created from a mutable mxArray* pointer automatically frees its internal memory unless explicitly released. When MxArray is created from a const mxArray*, the object does not manage memory but still provides the same matrix API.

Constructor & Destructor Documentation

◆ MxArray() [1/6]

MxArray ( )
inline

Empty MxArray constructor.

Use reset() to set a pointer.

◆ MxArray() [2/6]

MxArray ( MxArray && array)
inline

Move constructor.

◆ MxArray() [3/6]

MxArray ( const mxArray * array)
inlineexplicit

MxArray constructor from const mxArray*.

MxArray will not manage memory.

Parameters
arraymxArray pointer given by mexFunction.

◆ MxArray() [4/6]

MxArray ( mxArray * array)
inlineexplicit

MxArray constructor from mutable mxArray*.

MxArray will manage memory.

Parameters
arraymxArray pointer.

◆ MxArray() [5/6]

template<typename T >
MxArray ( const T & value)
inlineexplicit

MxArray constructor from scalar.

◆ ~MxArray()

virtual ~MxArray ( )
inlinevirtual

Destructor.

Unreleased pointers will be destroyed.

◆ MxArray() [6/6]

MxArray ( const MxArray & array)
private

Copy constructor is prohibited except internally.

Member Function Documentation

◆ assignCellTo() [1/2]

template<typename T >
static void assignCellTo ( const mxArray * array,
mwIndex index,
T * value )
inlinestaticprivate

Explicit cell element assignment.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ assignCellTo() [2/2]

template<typename T >
static void assignCellTo ( const mxArray * array,
T * value )
inlinestaticprivate

Explicit cell array assignment.

Here is the call graph for this function:

◆ assignCharFrom() [1/4]

template<typename T >
static void assignCharFrom ( mxArray * array,
mwIndex index,
const typename std::enable_if< MxComplexType< T >::value, T >::type & value )
inlinestaticprivate

◆ assignCharFrom() [2/4]

template<typename T >
static void assignCharFrom ( mxArray * array,
mwIndex index,
const typename std::enable_if< std::is_floating_point< T >::value, T >::type & value )
inlinestaticprivate
Here is the caller graph for this function:

◆ assignCharFrom() [3/4]

template<typename T >
static void assignCharFrom ( mxArray * array,
mwIndex index,
const typename std::enable_if< std::is_integral< T >::value &&!std::is_signed< T >::value, T >::type & value )
inlinestaticprivate

◆ assignCharFrom() [4/4]

template<typename T >
static void assignCharFrom ( mxArray * array,
mwIndex index,
const typename std::enable_if< std::is_integral< T >::value &&std::is_signed< T >::value, T >::type & value )
inlinestaticprivate

◆ assignCharTo() [1/2]

template<typename R >
static void assignCharTo ( const mxArray * array,
mwIndex index,
typename std::enable_if< !std::is_signed< R >::value, R >::type * value )
inlinestaticprivate

Explicit char (unsigned) element assignment.

◆ assignCharTo() [2/2]

template<typename R >
static void assignCharTo ( const mxArray * array,
mwIndex index,
typename std::enable_if< std::is_signed< R >::value, R >::type * value )
inlinestaticprivate

Explicit char (signed) element assignment.

Here is the caller graph for this function:

◆ assignFrom() [1/2]

template<typename R , typename T >
static void assignFrom ( mxArray * array,
mwIndex index,
const typename std::enable_if< MxArithmeticType< T >::value||MxCharType< T >::value, T >::type & value )
inlinestaticprivate

Assignment helpers (for MxArray.set<type>(i, value))

Explicit numeric element assignment.

Here is the caller graph for this function:

◆ assignFrom() [2/2]

template<typename R , typename T >
static void assignFrom ( mxArray * array,
mwIndex index,
const typename std::enable_if< MxComplexType< T >::value, T >::type & value )
inlinestaticprivate

Explicit complex element assignment.

◆ assignStringTo() [1/2]

template<typename R >
static void assignStringTo ( const mxArray * array,
typename std::enable_if< !std::is_signed< typename R::value_type >::value, R >::type * value )
inlinestaticprivate

Explicit char (unsigned) array assignment.

◆ assignStringTo() [2/2]

template<typename R >
static void assignStringTo ( const mxArray * array,
typename std::enable_if< std::is_signed< typename R::value_type >::value, R >::type * value )
inlinestaticprivate

Explicit char (signed) array assignment.

Here is the caller graph for this function:

◆ assignTo() [1/5]

template<typename T , typename R >
static void assignTo ( const mxArray * array,
mwIndex index,
typename std::enable_if< MxComplexType< R >::value, R >::type * value )
inlinestaticprivate

Explicit complex element assignment.

◆ assignTo() [2/5]

template<typename T , typename R >
static void assignTo ( const mxArray * array,
mwIndex index,
typename std::enable_if< std::is_floating_point< R >::value, R >::type * value )
inlinestaticprivate

Explicit floating point element assignment.

◆ assignTo() [3/5]

template<typename T , typename R >
static void assignTo ( const mxArray * array,
mwIndex index,
typename std::enable_if< std::is_integral< R >::value, R >::type * value )
inlinestaticprivate

Assignment helpers (for MxArray.to<type>(value))

Explicit integer element assignment.

Here is the caller graph for this function:

◆ assignTo() [4/5]

template<typename T , typename R >
static void assignTo ( const mxArray * array,
typename std::enable_if< MxArithmeticCompound< R >::value||MxLogicalCompound< R >::value||MxCharCompound< R >::value, R >::type * value )
inlinestaticprivate

Explicit numeric array assignment.

◆ assignTo() [5/5]

template<typename T , typename R >
static void assignTo ( const mxArray * array,
typename std::enable_if< MxComplexCompound< R >::value, R >::type * value )
inlinestaticprivate

Explicit complex array assigment.

◆ at() [1/13]

static const mxArray * at ( const mxArray * array,
const std::string & field,
mwIndex index = 0 )
inlinestatic

◆ at() [2/13]

template<typename T >
static void at ( const mxArray * array,
const std::string & field,
T * value,
mwIndex index = 0 )
inlinestatic
Here is the call graph for this function:

◆ at() [3/13]

template<typename T >
static T at ( const mxArray * array,
mwIndex index )
inlinestatic

mxArray* element reader methods.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ at() [4/13]

static const mxArray * at ( const mxArray * array,
mwIndex index )
inlinestatic

◆ at() [5/13]

template<typename T >
static void at ( const mxArray * array,
mwIndex index,
T * value )
inlinestatic
Here is the call graph for this function:

◆ at() [6/13]

template<typename T >
T at ( const std::string & field,
mwIndex index = 0 ) const
inline

Struct element accessor.

Parameters
fieldfield name of the struct array.
indexindex of the struct array.
Returns
value of the element at the specified field.
Here is the call graph for this function:

◆ at() [7/13]

const mxArray * at ( const std::string & field,
mwIndex index = 0 ) const
inline
Here is the call graph for this function:

◆ at() [8/13]

template<typename T >
void at ( const std::string & field,
T * value,
mwIndex index = 0 ) const
inline
Here is the call graph for this function:

◆ at() [9/13]

template<typename T >
T at ( const std::vector< mwIndex > & subscripts) const

Template for element accessor.

Parameters
subscriptssubscript indexes of elements.
Returns
value of the element at subscript index.
Here is the call graph for this function:

◆ at() [10/13]

template<typename T >
T at ( mwIndex index) const
inline

Template for element accessor.

Parameters
indexindex of the array element.
Returns
value of the element at index.

Example:

MxArray array(prhs[0]);
double value = array.at<double>(0);
mxArray object wrapper for data conversion and manipulation.
Definition mxarray.h:101
Here is the call graph for this function:

◆ at() [11/13]

const mxArray * at ( mwIndex index) const
inline
Here is the call graph for this function:

◆ at() [12/13]

template<typename T >
void at ( mwIndex index,
T * value ) const
inline
Here is the call graph for this function:

◆ at() [13/13]

template<typename T >
T at ( mwIndex row,
mwIndex column ) const

Template for element accessor.

Parameters
rowindex of the first dimension.
columnindex of the second dimension.
Returns
value of the element at (row, column).
Here is the call graph for this function:

◆ atInternal() [1/3]

template<typename T >
void atInternal ( const mxArray * array,
const std::string & field,
mwIndex index,
T * value )
staticprivate

Structure access.

Here is the call graph for this function:

◆ atInternal() [2/3]

template<typename T >
void atInternal ( const mxArray * array,
mwIndex index,
typename std::enable_if< MxComplexOrArithmeticType< T >::value||MxLogicalType< T >::value||MxCharType< T >::value, T >::type * value )
staticprivate

Templated mxArray getters

Fundamental numeric types.

Converter from fundamental numeric or complex types.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ atInternal() [3/3]

template<typename T >
void atInternal ( const mxArray * array,
mwIndex index,
typename std::enable_if< std::is_compound< T >::value &&!MxComplexType< T >::value, T >::type * value )
staticprivate

Converter for nested types.

Here is the call graph for this function:

◆ Cell()

static mxArray * Cell ( int rows = 1,
int columns = 1 )
inlinestatic

Create a new cell matrix.

Parameters
rowsNumber of rows.
columnsNumber of cols.

Example:

MxArray cell_array = MxArray::Cell(1, 2);
cell_array.set(0, 1);
cell_array.set(1, "another value");
plhs[0] = cell_array.release();
mxArray * release()
Release managed mxArray* pointer, or clone if not owner.
Definition mxarray.h:202
static mxArray * Cell(int rows=1, int columns=1)
Create a new cell matrix.
Definition mxarray.h:266
static void set(mxArray *array, mwIndex index, const T &value)
mxArray* element writer methods.
Definition mxarray.h:358
Here is the call graph for this function:

◆ classID()

mxClassID classID ( ) const
inline

Class ID of mxArray.

Here is the caller graph for this function:

◆ className()

const std::string className ( ) const
inline

Class name of mxArray.

Here is the caller graph for this function:

◆ clone()

mxArray * clone ( ) const
inline

Clone mxArray.

This always allocates new mxArray*.

Returns
Unmanaged mxArray*. Always caller must destroy.
Here is the caller graph for this function:

◆ cols()

mwSize cols ( ) const
inline

Number of columns in an array.

Here is the caller graph for this function:

◆ dimensions()

std::vector< mwSize > dimensions ( ) const
inline

Array of each dimension.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dimensionSize()

mwSize dimensionSize ( ) const
inline

Number of dimensions.

Here is the caller graph for this function:

◆ elementSize()

int elementSize ( ) const
inline

Element size.

◆ Eps()

static double Eps ( )
inlinestatic

Value of EPS.

◆ fieldName()

std::string fieldName ( int index) const
inline

Get field name of a struct array.

Parameters
indexindex of the struct array.
Returns
std::string.
Here is the caller graph for this function:

◆ fieldNames()

std::vector< std::string > fieldNames ( ) const
inline

Get field names of a struct array.

Returns
std::vector<std::string> of struct field names.
Here is the call graph for this function:

◆ fieldSize()

int fieldSize ( ) const
inline

Number of fields in a struct array.

Here is the caller graph for this function:

◆ from() [1/3]

static mxArray * from ( const char * value)
inlinestatic

◆ from() [2/3]

template<typename T >
static mxArray * from ( const T & value)
inlinestatic

mxArray* importer methods.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ from() [3/3]

static mxArray * from ( int32_t value)
inlinestatic

◆ fromInternal() [1/10]

template<typename Container >
mxArray * fromInternal ( const typename std::enable_if< MxArithmeticCompound< Container >::value, Container >::type & value)
staticprivate

Container with fundamental numerics, i.e.

vector<double>.

◆ fromInternal() [2/10]

template<typename T >
mxArray * fromInternal ( const typename std::enable_if< MxArithmeticType< T >::value, T >::type & value)
staticprivate

Templated mxArray importers

Fundamental numerics.

Fundamental numeric type.

Here is the caller graph for this function:

◆ fromInternal() [3/10]

template<typename Container >
mxArray * fromInternal ( const typename std::enable_if< MxCellCompound< Container >::value, Container >::type & value)
staticprivate

Container with cell type content.

Here is the call graph for this function:

◆ fromInternal() [4/10]

template<typename T >
mxArray * fromInternal ( const typename std::enable_if< MxCharType< T >::value, T >::type & value)
staticprivate

Char type.

◆ fromInternal() [5/10]

template<typename Container >
mxArray * fromInternal ( const typename std::enable_if< MxComplexCompound< Container >::value, Container >::type & value)
staticprivate

Container with complex numbers, i.e.

vector<complex<double>>.

◆ fromInternal() [6/10]

template<typename T >
mxArray * fromInternal ( const typename std::enable_if< MxComplexType< T >::value, T >::type & value)
staticprivate

Complex types, complex<float> or complex<double>.

Complex type, complex<float> or complex<double>.

◆ fromInternal() [7/10]

template<typename Container >
mxArray * fromInternal ( const typename std::enable_if< MxLogicalCompound< Container >::value, Container >::type & value)
staticprivate

Container with logicals.

◆ fromInternal() [8/10]

template<typename T >
mxArray * fromInternal ( const typename std::enable_if< MxLogicalType< T >::value, T >::type & value)
staticprivate

Logicals.

◆ fromInternal() [9/10]

template<typename Container >
mxArray * fromInternal ( const typename std::enable_if<(MxCharCompound< Container >::value) &&!(std::is_signed< typename Container::value_type >::value), Container >::type & value)
staticprivate

Container with unsigned char.

Here is the call graph for this function:

◆ fromInternal() [10/10]

template<typename Container >
mxArray * fromInternal ( const typename std::enable_if<(MxCharCompound< Container >::value) &&(std::is_signed< typename Container::value_type >::value), Container >::type & value)
staticprivate

Containter with signed char.

Here is the call graph for this function:

◆ get()

const mxArray * get ( ) const
inline

Conversion to const mxArray*.

Returns
const mxArray* pointer.

◆ getChars()

mxChar * getChars ( ) const
inline
Here is the call graph for this function:

◆ getData()

template<typename T >
T * getData ( ) const

Get raw data pointer.

Returns
pointer T*. If MxArray is not compatible, return NULL.
Here is the call graph for this function:

◆ getImagData()

template<typename T >
T * getImagData ( ) const

Get raw data pointer to imaginary part.

Returns
pointer T*. If MxArray is not compatible, return NULL.
Here is the call graph for this function:

◆ getLogicals()

mxLogical * getLogicals ( ) const
inline
Here is the call graph for this function:

◆ getMutable()

mxArray * getMutable ( )
inline

Get raw mxArray*.

Returns
mxArray* pointer.

◆ hasField()

bool hasField ( const std::string & field_name,
mwIndex index = 0 ) const
inline

Determine whether a struct array has a specified field.

Here is the call graph for this function:

◆ Inf()

static double Inf ( )
inlinestatic

Value of infinity.

◆ isCell()

bool isCell ( ) const
inline

Determine whether input is cell array.

◆ isChar()

bool isChar ( ) const
inline

Determine whether input is string array.

Here is the caller graph for this function:

◆ isClass()

bool isClass ( const char * name) const
inline

Determine whether array is member of specified class.

◆ isComplex()

bool isComplex ( ) const
inline

Determine whether data is complex.

◆ isDouble()

bool isDouble ( ) const
inline

Determine whether mxArray represents data as double-precision, floating-point numbers.

◆ isEmpty()

bool isEmpty ( ) const
inline

Determine whether array is empty.

◆ IsFinite()

static bool IsFinite ( double value)
inlinestatic

Determine whether input is finite.

◆ isFromGlobalWS()

bool isFromGlobalWS ( ) const
inline

Determine whether array was copied from MATLAB global workspace.

◆ IsInf()

static bool IsInf ( double value)
inlinestatic

Determine whether input is infinite.

◆ isInt16()

bool isInt16 ( ) const
inline

Determine whether array represents data as signed 16-bit integers.

◆ isInt32()

bool isInt32 ( ) const
inline

Determine whether array represents data as signed 32-bit integers.

◆ isInt64()

bool isInt64 ( ) const
inline

Determine whether array represents data as signed 64-bit integers.

◆ isInt8()

bool isInt8 ( ) const
inline

Determine whether array represents data as signed 8-bit integers.

◆ isIntegral()

bool isIntegral ( const char * name) const
inline

Determine whether array is integral type.

◆ isLogical()

bool isLogical ( ) const
inline

Determine whether array is of type mxLogical.

Here is the caller graph for this function:

◆ isLogicalScalar()

bool isLogicalScalar ( ) const
inline

Determine whether scalar array is of type mxLogical.

◆ isLogicalScalarTrue()

bool isLogicalScalarTrue ( ) const
inline

Determine whether scalar array of type mxLogical is true.

◆ IsNaN()

static bool IsNaN ( double value)
inlinestatic

Determine whether input is NaN (Not-a-Number).

◆ isNumeric()

bool isNumeric ( ) const
inline

Determine whether array is numeric.

◆ isOwner()

bool isOwner ( ) const
inline

Return true if owner.

Here is the caller graph for this function:

◆ isSingle()

bool isSingle ( ) const
inline

Determine whether array represents data as single-precision, floating-point numbers.

◆ isSparse()

bool isSparse ( ) const
inline

Determine whether input is sparse array.

◆ isStruct()

bool isStruct ( ) const
inline

Determine whether input is structure array.

Here is the caller graph for this function:

◆ isUint16()

bool isUint16 ( ) const
inline

Determine whether array represents data as unsigned 16-bit integers.

◆ isUint32()

bool isUint32 ( ) const
inline

Determine whether array represents data as unsigned 32-bit integers.

◆ isUint64()

bool isUint64 ( ) const
inline

Determine whether array represents data as unsigned 64-bit integers.

◆ isUint8()

bool isUint8 ( ) const
inline

Determine whether array represents data as unsigned 8-bit integers.

◆ isVector()

bool isVector ( ) const
inline

Determine whether input is vector array.

◆ Logical()

static mxArray * Logical ( int rows = 1,
int columns = 1 )
inlinestatic

Create a new logical matrix.

Parameters
rowsNumber of rows.
columnsNumber of cols.
Here is the call graph for this function:

◆ NaN()

static double NaN ( )
inlinestatic

Value of NaN (Not-a-Number).

◆ nonZeroMax()

mwSize nonZeroMax ( ) const
inline

Number of elements in IR, PR, and PI arrays.

◆ Numeric() [1/2]

template<typename T >
mxArray * Numeric ( int rows = 1,
int columns = 1 )
static

Create a new numeric (real or complex) matrix.

Parameters
rowsNumber of rows.
columnsNumber of cols.
Here is the call graph for this function:

◆ Numeric() [2/2]

template<typename T >
mxArray * Numeric ( std::vector< std::size_t > dims)
static

Create a new numeric (real or complex) matrix.

Parameters
ndimNumber of dimensions.
dimsDimensions array. Each element in the dimensions array contains the size of the array in that dimension.

◆ operator bool()

operator bool ( ) const
inline

Return true if the array is not NULL.

◆ operator=() [1/5]

MxArray & operator= ( const MxArray & rhs)
private

Copy assignment operator is prohibited.

◆ operator=() [2/5]

MxArray & operator= ( const mxArray * rhs)
inline

Assignment from const mxArray*.

MxArray will not manage memory.

Here is the call graph for this function:

◆ operator=() [3/5]

MxArray & operator= ( MxArray && rhs)
inline

Move assignment.

◆ operator=() [4/5]

MxArray & operator= ( mxArray * rhs)
inline

Assignment from mutable mxArray*.

MxArray will manage memory.

Here is the call graph for this function:

◆ operator=() [5/5]

MxArray & operator= ( std::nullptr_t )
inline

NULL assignment.

Here is the call graph for this function:

◆ release()

mxArray * release ( )
inline

Release managed mxArray* pointer, or clone if not owner.

Returns
Unmanaged mxArray*. Always caller must destroy.
Here is the call graph for this function:

◆ reset() [1/2]

void reset ( const mxArray * array = NULL)
inline

Reset an mxArray to a const mxArray*.

Caller must be VERY careful with this, as the behavior is undefined when the original mxArray* is destroyed. For example, the following will crash.

MxArray foo;
{
MxArray bar(1);
foo.reset(bar.get());
}
foo.toInt(); // Error!
void reset(const mxArray *array=NULL)
Reset an mxArray to a const mxArray*.
Definition mxarray.h:185
Here is the caller graph for this function:

◆ reset() [2/2]

void reset ( mxArray * array)
inline

Reset an mxArray.

◆ rows()

mwSize rows ( ) const
inline

Number of rows in an array.

Here is the caller graph for this function:

◆ set() [1/12]

template<typename T >
void set ( const std::string & field,
const T & value,
mwIndex index = 0 )
inline

Struct element write accessor.

Parameters
fieldfield name of the struct array.
valuevalue of the field.
indexlinear index of the struct array element.
Here is the call graph for this function:

◆ set() [2/12]

void set ( const std::string & field,
mxArray * value,
mwIndex index = 0 )
inline

Struct element write accessor.

Parameters
fieldfield name of the struct array.
valuevalue of the field to be inserted.
indexlinear index of the struct array element.
Here is the call graph for this function:

◆ set() [3/12]

template<typename T >
void set ( const std::vector< mwIndex > & subscripts,
const T & value )

Template for element write accessor.

Parameters
subscriptssubscript index of the element.
valuevalue of the field.
Here is the call graph for this function:

◆ set() [4/12]

void set ( const std::vector< mwIndex > & subscripts,
mxArray * value )
inline

Cell element write accessor.

Parameters
subscriptssubscript index of the element.
valuevalue of the field.
Here is the call graph for this function:

◆ set() [5/12]

template<typename T >
void set ( mwIndex index,
const T & value )
inline

Template for element write accessor.

Parameters
indexoffset of the array element.
valuevalue of the field.
Here is the call graph for this function:

◆ set() [6/12]

void set ( mwIndex index,
mxArray * value )
inline

Cell element write accessor.

Parameters
indexindex of the element.
valuecell element to be inserted.
Here is the call graph for this function:

◆ set() [7/12]

template<typename T >
void set ( mwIndex row,
mwIndex column,
const T & value )

Template for element write accessor.

Parameters
rowindex of the first dimension of the array element.
columnindex of the first dimension of the array element.
valuevalue of the field.
Here is the call graph for this function:

◆ set() [8/12]

void set ( mwIndex row,
mwIndex column,
mxArray * value )
inline

Cell element write accessor.

Parameters
rowindex of the first dimension of the array element.
columnindex of the first dimension of the array element.
valuecell element to be inserted.
Here is the call graph for this function:

◆ set() [9/12]

template<typename T >
static void set ( mxArray * array,
const std::string & field,
const T & value,
mwIndex index = 0 )
inlinestatic
Here is the call graph for this function:

◆ set() [10/12]

static void set ( mxArray * array,
const std::string & field,
mxArray * value,
mwIndex index = 0 )
inlinestatic

◆ set() [11/12]

template<typename T >
static void set ( mxArray * array,
mwIndex index,
const T & value )
inlinestatic

mxArray* element writer methods.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set() [12/12]

static void set ( mxArray * array,
mwIndex index,
mxArray * value )
inlinestatic

◆ setInternal() [1/3]

template<typename T >
void setInternal ( mxArray * array,
const std::string & field,
mwIndex index,
const T & value )
staticprivate

Structure access.

Here is the call graph for this function:

◆ setInternal() [2/3]

template<typename T >
void setInternal ( mxArray * array,
mwIndex index,
const typename std::enable_if< !std::is_compound< T >::value||MxComplexType< T >::value, T >::type & value )
staticprivate

Templated mxArray element setters

Templated mxArray setters

Fundamental numeric and complex types.

Converter from fundamental numeric or complex types.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInternal() [3/3]

template<typename T >
void setInternal ( mxArray * array,
mwIndex index,
const typename std::enable_if< MxCellType< T >::value, T >::type & value )
staticprivate

Container types.

Converter from fundamental numeric or complex types.

Here is the call graph for this function:

◆ size()

mwSize size ( ) const
inline

Number of elements in an array.

◆ Struct()

static mxArray * Struct ( int nfields = 0,
const char ** fields = NULL,
int rows = 1,
int columns = 1 )
inlinestatic

Generic constructor for a struct matrix.

Parameters
fieldsfield names.
nfieldsnumber of field names.
rowssize of the first dimension.
columnssize of the second dimension.

Example:

const char* fields[] = {"field1", "field2"};
MxArray struct_array(MxArray::Struct(2, fields));
struct_array.set("field1", 1);
struct_array.set("field2", "field2 value");
plhs[0] = struct_array.release();
static mxArray * Struct(int nfields=0, const char **fields=NULL, int rows=1, int columns=1)
Generic constructor for a struct matrix.
Definition mxarray.h:286
Here is the call graph for this function:

◆ subscriptIndex() [1/2]

mwIndex subscriptIndex ( const std::vector< mwIndex > & subscripts) const
inline

Offset from first element to desired element.

Parameters
subscriptssubscript indexes of the array.
Returns
linear offset of the specified subscript index.

◆ subscriptIndex() [2/2]

mwIndex subscriptIndex ( mwIndex row,
mwIndex column ) const
inline

Offset from first element to desired element.

Parameters
rowindex of the first dimension of the array.
columnindex of the second dimension of the array.
Returns
linear offset of the specified subscript index.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ swap()

void swap ( MxArray & rhs)
inline

Swap operation.

◆ to() [1/4]

template<typename T >
T to ( ) const
inline

Convert MxArray to a specified type.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to() [2/4]

template<typename T >
static T to ( const mxArray * array)
inlinestatic
Here is the call graph for this function:

◆ to() [3/4]

template<typename T >
static void to ( const mxArray * array,
T * value )
inlinestatic

mxArray* exporter methods.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to() [4/4]

template<typename T >
void to ( T * value) const
inline
Here is the call graph for this function:

◆ toInternal() [1/3]

template<typename T >
static void toInternal ( const mxArray * array,
typename std::enable_if< MxArithmeticType< T >::value||MxComplexType< T >::value||MxLogicalType< T >::value||MxCharType< T >::value, T >::type * value )
inlinestaticprivate

Templated mxArray exporters

Singleton types.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toInternal() [2/3]

template<typename T >
void toInternal ( const mxArray * array,
typename std::enable_if< MxCellType< T >::value &&(!std::is_compound< T >::value||MxCellType< typename T::value_type >::value), T >::type * value )
staticprivate

Nested types (leads into recursive deduction).

Converter from nested types to container.

Here is the call graph for this function:

◆ toInternal() [3/3]

template<typename T >
void toInternal ( const mxArray * array,
typename std::enable_if< MxComplexOrArithmeticCompound< T >::value||MxLogicalCompound< T >::value||MxCharCompound< T >::value, T >::type * value )
staticprivate

Vector types.

Templated mxArray exporters

Converter from numeric matrix to container.

Here is the call graph for this function:

Member Data Documentation

◆ array_

mxArray* array_
private

Pointer to the mxArray C object.

◆ owner_

bool owner_
private

Flag to enable resource management.


The documentation for this class was generated from the following file: