MexIFace
A C++/Matlab object-based interface library and cross-platform CMake MEX build tool.
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
mexiface::MexIFace Class Referenceabstract

Base class for the C++ side of a MexIFace interface class. More...

#include </home/travis/build/markjolah/MexIFace/include/MexIFace/MexIFace.h>

Inheritance diagram for mexiface::MexIFace:
[legend]
Collaboration diagram for mexiface::MexIFace:
[legend]

Public Types

using MXArgCountT = int
 
using IdxT = arma::uword
 
template<class T >
using Vec = arma::Col< T >
 
template<class T >
using Mat = arma::Mat< T >
 
template<class T >
using Cube = arma::Cube< T >
 
template<class T >
using Hypercube = hypercube::Hypercube< T >
 
template<class T >
using Dict = std::map< std::string, T >
 
template<class T >
using IsArithmeticT = typename std::enable_if< std::is_arithmetic< T >::value >::type
 
template<class T >
using IsNotArithmeticT = typename std::enable_if<!std::is_arithmetic< T >::value >::type
 
template<class T >
using IsIntegralT = typename std::enable_if< std::is_integral< T >::value >::type
 
template<class T >
using IsUnsignedIntegralT = typename std::enable_if< std::is_integral< T >::value &&std::is_same< T, typename std::make_unsigned< T >::type >::value >::type
 
template<class T >
using IsFloatingPointT = typename std::enable_if< std::is_floating_point< T >::value >::type
 

Public Member Functions

 MexIFace ()
 Default constructor. More...
 
void mexFunction (MXArgCountT _nlhs, mxArray *_lhs[], MXArgCountT _nrhs, const mxArray *_rhs[])
 The mexFunction that will be exposed as the entry point for the .mex file. More...
 

Static Public Member Functions

template<class ElemT = double, typename = IsArithmeticT<ElemT>>
static ElemT toScalar (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Vec< ElemT > toVec (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Mat< ElemT > toMat (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Cube< ElemT > toCube (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Hypercube< ElemT > toHypercube (const mxArray *m)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
static ElemT checkedToScalar (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Vec< ElemT > checkedToVec (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Mat< ElemT > checkedToMat (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Cube< ElemT > checkedToCube (const mxArray *m)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static Hypercube< ElemT > checkedToHypercube (const mxArray *m)
 
static mxArray * toMXArray (bool val)
 
static mxArray * toMXArray (const char *val)
 
static mxArray * toMXArray (std::string val)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (ElemT val)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (const Vec< ElemT > &arr)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (const Mat< ElemT > &arr)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (const Cube< ElemT > &arr)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (const Hypercube< ElemT > &arr)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (const arma::SpMat< ElemT > &arr)
 
template<class ElemT , typename = IsArithmeticT<ElemT>>
static mxArray * toMXArray (const std::list< ElemT > &arr)
 
template<class ConvertableT >
static mxArray * toMXArray (const Dict< ConvertableT > &arr)
 
template<template< typename... > class Array, class ConvertableT >
static mxArray * toMXArray (const Array< ConvertableT > &arr)
 
template<class SrcIntT , class DestIntT , typename = IsIntegralT<SrcIntT>, typename = IsIntegralT<DestIntT>>
static DestIntT checkedIntegerToIntegerConversion (const mxArray *m)
 
template<class SrcFloatT , class DestIntT , typename = IsFloatingPointT<SrcFloatT>, typename = IsIntegralT<DestIntT>>
static DestIntT checkedFloatToIntegerConversion (const mxArray *m)
 
template<class SrcIntT , class DestFloatT , typename = IsIntegralT<SrcIntT>, typename = IsFloatingPointT<DestFloatT>>
static DestFloatT checkedIntegerToFloatConversion (const mxArray *m)
 
template<class SrcFloatT , class DestFloatT , typename = IsFloatingPointT<SrcFloatT>, typename = IsFloatingPointT<DestFloatT>>
static DestFloatT checkedFloatToFloatConversion (const mxArray *m)
 
template<class ElemT >
static void checkType (const mxArray *m)
 
static void checkType (const mxArray *m, mxClassID classid)
 
static void checkNdim (const mxArray *m, mwSize expected_dim)
 
static void checkMaxNdim (const mxArray *m, mwSize max_expected_dim)
 
static void checkScalarSize (const mxArray *m)
 
static void checkVectorSize (const mxArray *m)
 
static void checkVectorSize (const mxArray *m, mwSize expected_numel)
 Checks that a matlab mxArray object has the correct 2D dimensions. More...
 
static void checkMatrixSize (const mxArray *m, mwSize expected_rows, mwSize expected_cols)
 Checks that a matlab mxArray object has the correct 2D dimensions. More...
 
static void checkSameLastDim (const mxArray *m1, const mxArray *m2)
 Checks that two matlab mxArray objects have the same sized last dimension. More...
 

Protected Types

using MethodMap = std::map< std::string, std::function< void()>>
 

Protected Member Functions

void checkNumArgs (MXArgCountT expected_nlhs, MXArgCountT expected_nrhs) const
 Checks the mex function was called with an exact number of input and output arguments. More...
 
void checkMinNumArgs (MXArgCountT min_nlhs, MXArgCountT min_nrhs) const
 Checks the mex function was called with a minimum number of input and output arguments. More...
 
void checkMaxNumArgs (MXArgCountT max_nlhs, MXArgCountT max_nrhs) const
 Checks the mex function was called with a maximum number of input and output arguments. More...
 
void checkInputArgRange (MXArgCountT min_nrhs, MXArgCountT max_nrhs) const
 
void checkOutputArgRange (MXArgCountT min_nlhs, MXArgCountT max_nlhs) const
 
template<class ElemT = double>
ElemT getAsScalar (const mxArray *m=nullptr)
 
bool getAsBool (const mxArray *m=nullptr)
 
template<class IntT = int64_t, typename = IsIntegralT<IntT>>
IntT getAsInt (const mxArray *m=nullptr)
 Reads a mxArray as a scalar C++ int32_t type. More...
 
template<class UnsignedT = uint64_t, typename = IsUnsignedIntegralT<UnsignedT>>
UnsignedT getAsUnsigned (const mxArray *m=nullptr)
 
template<class FloatT = double, typename = IsFloatingPointT<FloatT>>
FloatT getAsFloat (const mxArray *m=nullptr)
 
template<class ElemT = double>
Dict< ElemT > getAsScalarDict (const mxArray *m=nullptr)
 
template<template< typename... > class Array = std::vector, class ElemT = double>
Array< ElemT > getAsScalarArray (const mxArray *m=nullptr)
 
std::string getString (const mxArray *mxdata=nullptr)
 Reads a mxArray as a string. More...
 
template<template< typename... > class Array = std::vector>
Array< std::string > getStringArray (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
ElemT getScalar (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Vec< ElemT > getVec (const mxArray *mxdata=nullptr)
 Create a armadillo Column vector to directly use the Matlab data for a 1D array of arbitrary element type. More...
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Mat< ElemT > getMat (const mxArray *mxdata=nullptr)
 Create an armadillo Mat object to directly work with the Matlab data for a 2D array of arbitrary element type. More...
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Cube< ElemT > getCube (const mxArray *mxdata=nullptr)
 Create an armadillo Cube object to directly work with the Matlab data for a 3D array of arbitrary element type. More...
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Hypercube< ElemT > getHypercube (const mxArray *mxdata=nullptr)
 Create an Hypercube object to directly work with the Matlab data for a 4D array of arbitrary element type. More...
 
template<template< typename > class NumericArrayT, class ElemT = double>
NumericArrayT< ElemT > getNumeric (const mxArray *m=nullptr)
 
template<template< typename... > class Array = std::vector, class ElemT = double>
Array< ElemT > getScalarArray (const mxArray *mxdata=nullptr)
 
template<template< typename > class Array = std::vector, class ElemT = double, typename = IsArithmeticT<ElemT>>
Array< Vec< ElemT > > getVecArray (const mxArray *mxdata=nullptr)
 
template<template< typename > class Array = std::vector, class ElemT = double, typename = IsArithmeticT<ElemT>>
Array< Mat< ElemT > > getMatArray (const mxArray *mxdata=nullptr)
 
template<template< typename > class Array = std::vector, class ElemT = double, typename = IsArithmeticT<ElemT>>
Array< Cube< ElemT > > getCubeArray (const mxArray *mxdata=nullptr)
 
template<template< typename > class Array = std::vector, class ElemT = double, typename = IsArithmeticT<ElemT>>
Array< Hypercube< ElemT > > getHypercubeArray (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Dict< ElemT > getScalarDict (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Dict< Vec< ElemT > > getVecDict (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Dict< Mat< ElemT > > getMatDict (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Dict< Cube< ElemT > > getCubeDict (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Dict< Hypercube< ElemT > > getHypercubeDict (const mxArray *mxdata=nullptr)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Vec< ElemT > makeOutputArray (IdxT nelem)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Mat< ElemT > makeOutputArray (IdxT rows, IdxT cols)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Cube< ElemT > makeOutputArray (IdxT rows, IdxT cols, IdxT slices)
 
template<class ElemT = double, typename = IsArithmeticT<ElemT>>
Hypercube< ElemT > makeOutputArray (IdxT rows, IdxT cols, IdxT slices, IdxT hyperslices)
 
void output (mxArray *m) overridefinal
 Append a generic mxArray to the output arguments This is virtual because MexIFaceHandler need to use it to output a Handle pointer. More...
 
template<class ConvertableT >
void output (ConvertableT &&val)
 
void error (std::string condition, std::string message) const
 Reports an error condition to Matlab using the mexErrMsgIdAndTxt function. More...
 
void error (std::string component, std::string condition, std::string message) const
 Reports an error condition in a specified component to Matlab using the mexErrMsgIdAndTxt function. More...
 
virtual void objConstruct ()=0
 Called when the mexFunction gets the @new command, passing on the remaining input arguments. More...
 
virtual void objDestroy (const mxArray *mxhandle)=0
 Called when the mexFunction gets the @delete command. More...
 
virtual void getObjectFromHandle (const mxArray *mxhandle)=0
 Helper method which saves a pointer to the wrapped class's object in an internal member variable called obj. More...
 
virtual std::string obj_name () const =0
 Get the name of the class of the stored object. More...
 

Protected Attributes

MethodMap methodmap
 Maps names (std::string) to member functions (std::function<void()>) More...
 
MethodMap staticmethodmap
 Maps names (std::string) to static member functions (std::function<void()>) More...
 
MXArgCountT nlhs
 Number of left-hand-side (output) arguments passed to MexIFace::mexFunction. More...
 
mxArray ** lhs
 Left-hand-side (output) argument array. Size=nlhs. More...
 
IdxT lhs_idx
 Index of the next left-hand-side argument to write as output. More...
 
MXArgCountT nrhs
 Number of right-hand-side (input) arguments passed to MexIFace::mexFunction. More...
 
const mxArray ** rhs
 Right-hand-side (input) argument array. Size=nrhs. More...
 
IdxT rhs_idx
 Index of the next right-hand-side argument to read as input. More...
 

Detailed Description

Base class for the C++ side of a MexIFace interface class.

The MexIFace class is responsible for managing the C++ side of the MEX interface. The primary entry point from Matlab is the MexIFace::mexFunction method which takes in a variable number of arguments and returns a variable number of arguments. The first input argument is always a string that gives the command name. If it the special command "\@new" or "\@delete" a C++ instance is created or destroyed. The @new command returns a unique handle (number) which can be held onto by the Matlab IfaceMixin base class. This C++ object then remains in memory until the @delete command is called on the MexIFace, which then frees the underlying C++ class from memory.

The special command "\@static" allows static C++ methods to be called by the name passed as the second argument, and there is no need to have a existing object to call the method on because it is static.

Otherwise the command is interpreted as a named method which is registered in the methodmap, internal data structure which maps strings to callable member functions of the interface object which take in no arguments and return no arguments. The Matlab arguments are passed to these functions through the internal storage of the MexIFace object's rhs and lhs member variables.

A C++ class is wrapped by creating a new IFace class that inherits from MexIFace. At a minimum the Iface class must define the pure virtual functions objConstruct(), objDestroy(), and getObjectFromHandle(). It also must implement the interface for any of the methods and static methods that are required. Each of these methods in the Iface class must process the passed Matlab arguments in the rhs member variable and save outputs in the lhs member variable.

In general the Iface mex modules are not intended to be used directly, but rather are paired with a special Matlab class that inherits from the MexIFaceMixin.m base class.

Design decision: Because of the complexities of inheriting from a templated base class with regard to name lookups in superclasses, we chose to keep this MexIFace class non-templated. For this reason any methods and member variables which specifically mention the type of the wrapped class must be defined in the subclass of MexIFace.

Finally we provide many get* and make* which allow the lhs and rhs arguments to be interpreted as armadillo arrays on the C++ side. These methods are part of what makes this interface efficient as we don't need to create new storage and copy data, instead we just use the matlab memory directly, and matlab does all the memory management of parameters passed in and out.

Definition at line 64 of file MexIFace.h.

Member Typedef Documentation

template<class T >
using mexiface::MexIFace::Cube = arma::Cube<T>

Definition at line 71 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::Dict = std::map<std::string,T>

A convenient form for reporting dictionaries of named FP data to matlab

Definition at line 74 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::Hypercube = hypercube::Hypercube<T>

Definition at line 72 of file MexIFace.h.

using mexiface::MexIFace::IdxT = arma::uword

A logical type for an IdxT integer index

Definition at line 67 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::IsArithmeticT = typename std::enable_if<std::is_arithmetic<T>::value>::type

Definition at line 76 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::IsFloatingPointT = typename std::enable_if< std::is_floating_point<T>::value >::type

Definition at line 80 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::IsIntegralT = typename std::enable_if< std::is_integral<T>::value >::type

Definition at line 78 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::IsNotArithmeticT = typename std::enable_if<!std::is_arithmetic<T>::value>::type

Definition at line 77 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::IsUnsignedIntegralT = typename std::enable_if< std::is_integral<T>::value && std::is_same<T, typename std::make_unsigned<T>::type>::value >::type

Definition at line 79 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::Mat = arma::Mat<T>

Definition at line 70 of file MexIFace.h.

using mexiface::MexIFace::MethodMap = std::map<std::string, std::function<void()>>
protected

The type of mapping for mapping names to member functions to call

Definition at line 177 of file MexIFace.h.

Type for the mexFunction arg counts and associated nrhs and nlhs data members

Definition at line 66 of file MexIFace.h.

template<class T >
using mexiface::MexIFace::Vec = arma::Col<T>

Definition at line 69 of file MexIFace.h.

Constructor & Destructor Documentation

mexiface::MexIFace::MexIFace ( )

Default constructor.

Definition at line 18 of file MexIFace.cpp.

Member Function Documentation

template<class SrcFloatT , class DestFloatT , typename , typename >
DestFloatT mexiface::MexIFace::checkedFloatToFloatConversion ( const mxArray *  m)
static

Definition at line 657 of file MexIFace.h.

References mexiface::get_mx_class_name().

template<class SrcFloatT , class DestIntT , typename , typename >
DestIntT mexiface::MexIFace::checkedFloatToIntegerConversion ( const mxArray *  m)
static

Definition at line 629 of file MexIFace.h.

References mexiface::get_mx_class_name().

template<class SrcIntT , class DestFloatT , typename , typename >
DestFloatT mexiface::MexIFace::checkedIntegerToFloatConversion ( const mxArray *  m)
static

Definition at line 643 of file MexIFace.h.

References mexiface::get_mx_class_name().

template<class SrcIntT , class DestIntT , typename , typename >
DestIntT mexiface::MexIFace::checkedIntegerToIntegerConversion ( const mxArray *  m)
static

Definition at line 600 of file MexIFace.h.

References mexiface::get_mx_class_name().

template<class ElemT , typename >
MexIFace::Cube< ElemT > mexiface::MexIFace::checkedToCube ( const mxArray *  m)
static

Definition at line 584 of file MexIFace.h.

References checkMaxNdim().

template<class ElemT , typename >
MexIFace::Hypercube< ElemT > mexiface::MexIFace::checkedToHypercube ( const mxArray *  m)
static

Definition at line 592 of file MexIFace.h.

References checkMaxNdim().

template<class ElemT , typename >
MexIFace::Mat< ElemT > mexiface::MexIFace::checkedToMat ( const mxArray *  m)
static

Definition at line 576 of file MexIFace.h.

References checkNdim().

template<class ElemT , typename >
ElemT mexiface::MexIFace::checkedToScalar ( const mxArray *  m)
static

Definition at line 560 of file MexIFace.h.

References checkScalarSize().

template<class ElemT , typename >
MexIFace::Vec< ElemT > mexiface::MexIFace::checkedToVec ( const mxArray *  m)
static

Definition at line 568 of file MexIFace.h.

References checkVectorSize().

void mexiface::MexIFace::checkInputArgRange ( MXArgCountT  min_nrhs,
MXArgCountT  max_nrhs 
) const
inlineprotected

Definition at line 432 of file MexIFace.h.

References nrhs.

void mexiface::MexIFace::checkMatrixSize ( const mxArray *  m,
mwSize  expected_rows,
mwSize  expected_cols 
)
inlinestatic

Checks that a matlab mxArray object has the correct 2D dimensions.

Parameters
mA pointer to the mxArray to check
expected_rowsthe expected number of rows
expected_colsthe expected number of cols

Definition at line 399 of file MexIFace.h.

void mexiface::MexIFace::checkMaxNdim ( const mxArray *  m,
mwSize  max_expected_dim 
)
inlinestatic

Test doc here. And more here

Definition at line 343 of file MexIFace.h.

Referenced by checkedToCube(), and checkedToHypercube().

void mexiface::MexIFace::checkMaxNumArgs ( MXArgCountT  max_nlhs,
MXArgCountT  max_nrhs 
) const
inlineprotected

Checks the mex function was called with a maximum number of input and output arguments.

Parameters
max_nlhsMaxmum number of left hand side (output) arguments required.
max_nrhsMaxmum number of right hand side (input) arguments required.

Definition at line 475 of file MexIFace.h.

References nlhs, and nrhs.

void mexiface::MexIFace::checkMinNumArgs ( MXArgCountT  min_nlhs,
MXArgCountT  min_nrhs 
) const
inlineprotected

Checks the mex function was called with a minimum number of input and output arguments.

Parameters
min_nlhsMinimum number of left hand side (output) arguments required.
min_nrhsMinimum number of right hand side (input) arguments required.

Definition at line 456 of file MexIFace.h.

References nlhs, and nrhs.

Referenced by mexFunction().

void mexiface::MexIFace::checkNdim ( const mxArray *  m,
mwSize  expected_dim 
)
inlinestatic

Test doc here. And more here

Definition at line 332 of file MexIFace.h.

Referenced by checkedToMat().

void mexiface::MexIFace::checkNumArgs ( MXArgCountT  expected_nlhs,
MXArgCountT  expected_nrhs 
) const
inlineprotected

Checks the mex function was called with an exact number of input and output arguments.

Parameters
expected_nlhsExpected number of left hand side (output) arguments required.
expected_nrhsExpected number of right hand side (input) arguments required.

Definition at line 494 of file MexIFace.h.

References nlhs, and nrhs.

void mexiface::MexIFace::checkOutputArgRange ( MXArgCountT  min_nlhs,
MXArgCountT  max_nlhs 
) const
inlineprotected

Definition at line 442 of file MexIFace.h.

References nlhs.

void mexiface::MexIFace::checkSameLastDim ( const mxArray *  m1,
const mxArray *  m2 
)
inlinestatic

Checks that two matlab mxArray objects have the same sized last dimension.

Parameters
m1A pointer to the first mxArray to check
m2A pointer to the second mxArray to check

Throws an exception if the last dimensions do not match.

Definition at line 418 of file MexIFace.h.

void mexiface::MexIFace::checkScalarSize ( const mxArray *  m)
inlinestatic

Test doc here. And more here

Definition at line 354 of file MexIFace.h.

Referenced by checkedToScalar(), getAsScalarDict(), getCubeDict(), getHypercubeDict(), getMatDict(), getScalarDict(), and getVecDict().

template<class ElemT >
void mexiface::MexIFace::checkType ( const mxArray *  m)
static
void mexiface::MexIFace::checkType ( const mxArray *  m,
mxClassID  classid 
)
inlinestatic

Test doc here. And more here

Definition at line 321 of file MexIFace.h.

References mexiface::get_mx_class_name().

void mexiface::MexIFace::checkVectorSize ( const mxArray *  m)
inlinestatic
void mexiface::MexIFace::checkVectorSize ( const mxArray *  m,
mwSize  expected_numel 
)
inlinestatic

Checks that a matlab mxArray object has the correct 2D dimensions.

Parameters
mA pointer to the mxArray to check
expected_numelthe expected number of elements

Definition at line 382 of file MexIFace.h.

void mexiface::MexIFace::error ( std::string  condition,
std::string  message 
) const
protected

Reports an error condition to Matlab using the mexErrMsgIdAndTxt function.

Parameters
conditionString describing the error condition encountered.
messageInformative message to accompany the error.

Definition at line 27 of file MexIFace.cpp.

References mexiface::MexIFaceBase::obj_name().

Referenced by mexFunction().

void mexiface::MexIFace::error ( std::string  component,
std::string  condition,
std::string  message 
) const
protected

Reports an error condition in a specified component to Matlab using the mexErrMsgIdAndTxt function.

Parameters
componentString describing the component in which the error was encountered.
conditionString describing the error condition encountered.
messageInformative message to accompany the error.

Definition at line 39 of file MexIFace.cpp.

References mexiface::MexIFaceBase::obj_name().

bool mexiface::MexIFace::getAsBool ( const mxArray *  m = nullptr)
protected

Definition at line 814 of file MexIFace.h.

References mexiface::get_mx_class_name(), rhs, and rhs_idx.

Referenced by getAsScalar().

template<class FloatT , typename >
FloatT mexiface::MexIFace::getAsFloat ( const mxArray *  m = nullptr)
protected

Definition at line 875 of file MexIFace.h.

References mexiface::get_mx_class_name(), rhs, and rhs_idx.

template<class IntT , typename >
IntT mexiface::MexIFace::getAsInt ( const mxArray *  m = nullptr)
protected

Reads a mxArray as a scalar C++ int32_t type.

Parameters
mThe pointer to the mxArray to interpret.

The mxArray must be a signed 32 or 64 bit integer type.

Throws an error if the conversion cannot be made.

Definition at line 846 of file MexIFace.h.

References mexiface::get_mx_class_name(), rhs, and rhs_idx.

template<class ElemT >
ElemT mexiface::MexIFace::getAsScalar ( const mxArray *  m = nullptr)
protected

Definition at line 800 of file MexIFace.h.

References getAsBool().

template<template< typename... > class Array, class ElemT >
Array< ElemT > mexiface::MexIFace::getAsScalarArray ( const mxArray *  m = nullptr)
protected

Definition at line 898 of file MexIFace.h.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

template<class ElemT >
MexIFace::Dict< ElemT > mexiface::MexIFace::getAsScalarDict ( const mxArray *  m = nullptr)
protected

Definition at line 910 of file MexIFace.h.

References checkScalarSize(), checkType(), rhs, and rhs_idx.

template<class UnsignedT , typename >
UnsignedT mexiface::MexIFace::getAsUnsigned ( const mxArray *  m = nullptr)
protected

Definition at line 869 of file MexIFace.h.

template<class ElemT , typename >
MexIFace::Cube< ElemT > mexiface::MexIFace::getCube ( const mxArray *  m = nullptr)
protected

Create an armadillo Cube object to directly work with the Matlab data for a 3D array of arbitrary element type.

Parameters
mThe pointer to the mxArray that is to be interpreted as an armadillo array.
Returns
A new armadillo array that interprets the data stored in the m pointer.

Definition at line 980 of file MexIFace.h.

References rhs, and rhs_idx.

template<template< typename > class Array, class ElemT , typename >
Array< MexIFace::Cube< ElemT > > mexiface::MexIFace::getCubeArray ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1061 of file MexIFace.h.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Dict< MexIFace::Cube< ElemT > > mexiface::MexIFace::getCubeDict ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1122 of file MexIFace.h.

References checkScalarSize(), checkType(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Hypercube< ElemT > mexiface::MexIFace::getHypercube ( const mxArray *  m = nullptr)
protected

Create an Hypercube object to directly work with the Matlab data for a 4D array of arbitrary element type.

Uses the ability of the armadillo arrays to interpret raw data passed to it as preallocated column major format. This allows us to open the array data in C++ using Matlab's memory directly instead of having to allocate a separate space and copy.

Parameters
mThe pointer to the mxArray that is to be interpreted as an armadillo array.
Returns
A new Hypercube that interprets the data stored in the m pointer.

Definition at line 998 of file MexIFace.h.

References rhs, and rhs_idx.

template<template< typename > class Array, class ElemT , typename >
Array< MexIFace::Hypercube< ElemT > > mexiface::MexIFace::getHypercubeArray ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1074 of file MexIFace.h.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Dict< MexIFace::Hypercube< ElemT > > mexiface::MexIFace::getHypercubeDict ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1134 of file MexIFace.h.

References checkScalarSize(), checkType(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Mat< ElemT > mexiface::MexIFace::getMat ( const mxArray *  m = nullptr)
protected

Create an armadillo Mat object to directly work with the Matlab data for a 2D array of arbitrary element type.

Parameters
mThe pointer to the mxArray that is to be interpreted as an armadillo array.
Returns
A new armadillo array that interprets the data stored in the m pointer.

Definition at line 967 of file MexIFace.h.

References rhs, and rhs_idx.

template<template< typename > class Array, class ElemT , typename >
Array< MexIFace::Mat< ElemT > > mexiface::MexIFace::getMatArray ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1049 of file MexIFace.h.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Dict< MexIFace::Mat< ElemT > > mexiface::MexIFace::getMatDict ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1110 of file MexIFace.h.

References checkScalarSize(), checkType(), rhs, and rhs_idx.

template<template< typename > class NumericArrayT, class ElemT >
NumericArrayT< ElemT > mexiface::MexIFace::getNumeric ( const mxArray *  m = nullptr)
protected

Definition at line 1005 of file MexIFace.h.

virtual void mexiface::MexIFaceBase::getObjectFromHandle ( const mxArray *  mxhandle)
protectedpure virtualinherited

Helper method which saves a pointer to the wrapped class's object in an internal member variable called obj.

This pure virtual function is implemented in the MexIFaceHandler class template.

Parameters
mxhandlescalar array where the handle is stored

Implemented in mexiface::MexIFaceHandler< ObjT >.

Referenced by mexFunction().

template<class ElemT , typename >
ElemT mexiface::MexIFace::getScalar ( const mxArray *  m = nullptr)
protected

Get exact type. No conversions.

Definition at line 940 of file MexIFace.h.

References rhs, and rhs_idx.

template<template< typename... > class Array, class ElemT >
Array< ElemT > mexiface::MexIFace::getScalarArray ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1012 of file MexIFace.h.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Dict< ElemT > mexiface::MexIFace::getScalarDict ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1086 of file MexIFace.h.

References checkScalarSize(), checkType(), rhs, and rhs_idx.

std::string mexiface::MexIFace::getString ( const mxArray *  m = nullptr)
protected

Reads a mxArray as a string.

Parameters
mPointer to the mxArray to interpret.

Throws an error if the conversion cannot be made.

Definition at line 59 of file MexIFace.cpp.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

Referenced by getStringArray(), and mexFunction().

template<template< typename... > class Array>
Array< std::string > mexiface::MexIFace::getStringArray ( const mxArray *  mxdata = nullptr)
protected

Definition at line 924 of file MexIFace.h.

References checkType(), checkVectorSize(), getString(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Vec< ElemT > mexiface::MexIFace::getVec ( const mxArray *  m = nullptr)
protected

Create a armadillo Column vector to directly use the Matlab data for a 1D array of arbitrary element type.

Parameters
mPointer to the mxArray to be interpreted. (Default=nullptr). If nullptr then use next rhs param.
Returns
New armadillo array that re-uses the same data stored in the m pointer.

Definition at line 953 of file MexIFace.h.

References rhs, and rhs_idx.

template<template< typename > class Array, class ElemT , typename >
Array< MexIFace::Vec< ElemT > > mexiface::MexIFace::getVecArray ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1037 of file MexIFace.h.

References checkType(), checkVectorSize(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Dict< MexIFace::Vec< ElemT > > mexiface::MexIFace::getVecDict ( const mxArray *  mxdata = nullptr)
protected

Definition at line 1098 of file MexIFace.h.

References checkScalarSize(), checkType(), rhs, and rhs_idx.

template<class ElemT , typename >
MexIFace::Vec< ElemT > mexiface::MexIFace::makeOutputArray ( IdxT  nelem)
protected

Definition at line 1149 of file MexIFace.h.

References lhs, and lhs_idx.

template<class ElemT , typename >
MexIFace::Mat< ElemT > mexiface::MexIFace::makeOutputArray ( IdxT  rows,
IdxT  cols 
)
protected

Definition at line 1157 of file MexIFace.h.

References lhs, and lhs_idx.

template<class ElemT , typename >
MexIFace::Cube< ElemT > mexiface::MexIFace::makeOutputArray ( IdxT  rows,
IdxT  cols,
IdxT  slices 
)
protected

Definition at line 1165 of file MexIFace.h.

References lhs, and lhs_idx.

template<class ElemT , typename >
MexIFace::Hypercube< ElemT > mexiface::MexIFace::makeOutputArray ( IdxT  rows,
IdxT  cols,
IdxT  slices,
IdxT  hyperslices 
)
protected

Definition at line 1174 of file MexIFace.h.

References lhs, and lhs_idx.

void mexiface::MexIFace::mexFunction ( MXArgCountT  _nlhs,
mxArray *  _lhs[],
MXArgCountT  _nrhs,
const mxArray *  _rhs[] 
)

The mexFunction that will be exposed as the entry point for the .mex file.

Parameters
[in]_nlhsThe number of left-hand-side (input) arguments passed from the Matlab side of the Iface.
[in]_lhsThe input arguments passed from the Matlab side of the Iface.
[in]_nrhsThe number of right-hand-side (output) arguments requested from the Matlab side of the Iface.
[in,out]_rhsThe output arguments requested from the Matlab side of the Iface to be filled in.

This command is the main entry point for the .mex file, and allows the mexFunction to act like a class interface. Special @new, @delete, @static strings allow objects to be created and destroyed and static functions to be called otherwise the command is interpreted as a member function to be called on the given object handle which is expected to be the second argument.

Definition at line 85 of file MexIFace.cpp.

References checkMinNumArgs(), error(), mexiface::exploreMexArgs(), mexiface::MexIFaceBase::getObjectFromHandle(), getString(), methodmap, nrhs, mexiface::MexIFaceBase::obj_name(), mexiface::MexIFaceBase::objConstruct(), mexiface::MexIFaceBase::objDestroy(), rhs, and staticmethodmap.

virtual std::string mexiface::MexIFaceBase::obj_name ( ) const
protectedpure virtualinherited

Get the name of the class of the stored object.

Implemented in mexiface::MexIFaceHandler< ObjT >.

Referenced by error(), and mexFunction().

virtual void mexiface::MexIFaceBase::objConstruct ( )
protectedpure virtualinherited

Called when the mexFunction gets the @new command, passing on the remaining input arguments.

The rhs should have a single output argument which is the handle (number) which corresponds to the wrapped object.

This pure virtual function must be overloaded by the concrete MexIFace subclass that can use the get<> methods to take in arbitrary parameters for whatever constrctor(s) exists for that wrapped class.

Referenced by mexFunction().

virtual void mexiface::MexIFaceBase::objDestroy ( const mxArray *  mxhandle)
protectedpure virtualinherited

Called when the mexFunction gets the @delete command.

This pure virtual function is implemented in the MexIFaceHandler class template.

Parameters
mxhandlescalar array where the handle is stored

Implemented in mexiface::MexIFaceHandler< ObjT >.

Referenced by mexFunction().

void mexiface::MexIFace::output ( mxArray *  m)
inlinefinaloverrideprotectedvirtual

Append a generic mxArray to the output arguments This is virtual because MexIFaceHandler need to use it to output a Handle pointer.

Parameters
mArray to append to output arguments.

Implements mexiface::MexIFaceBase.

Definition at line 1186 of file MexIFace.h.

References lhs, and lhs_idx.

Referenced by output().

template<class ConvertableT >
void mexiface::MexIFace::output ( ConvertableT &&  val)
protected

Definition at line 1192 of file MexIFace.h.

References lhs, lhs_idx, nlhs, nrhs, output(), rhs, rhs_idx, and toMXArray().

template<class ElemT , typename >
MexIFace::Cube< ElemT > mexiface::MexIFace::toCube ( const mxArray *  m)
static

Definition at line 535 of file MexIFace.h.

template<class ElemT , typename >
MexIFace::Hypercube< ElemT > mexiface::MexIFace::toHypercube ( const mxArray *  m)
static

Definition at line 546 of file MexIFace.h.

template<class ElemT , typename >
MexIFace::Mat< ElemT > mexiface::MexIFace::toMat ( const mxArray *  m)
static

Definition at line 529 of file MexIFace.h.

mxArray * mexiface::MexIFace::toMXArray ( bool  val)
inlinestatic

Definition at line 673 of file MexIFace.h.

Referenced by output(), and toMXArray().

mxArray * mexiface::MexIFace::toMXArray ( const char *  val)
inlinestatic

Definition at line 681 of file MexIFace.h.

mxArray * mexiface::MexIFace::toMXArray ( std::string  val)
inlinestatic

Definition at line 687 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( ElemT  val)
static

Definition at line 694 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( const Vec< ElemT > &  arr)
static

Definition at line 702 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( const Mat< ElemT > &  arr)
static

Definition at line 711 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( const Cube< ElemT > &  arr)
static

Definition at line 720 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( const Hypercube< ElemT > &  arr)
static

Definition at line 730 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( const arma::SpMat< ElemT > &  arr)
static

Definition at line 740 of file MexIFace.h.

template<class ElemT , typename >
mxArray * mexiface::MexIFace::toMXArray ( const std::list< ElemT > &  arr)
static

Definition at line 762 of file MexIFace.h.

template<class ConvertableT >
mxArray * mexiface::MexIFace::toMXArray ( const Dict< ConvertableT > &  arr)
static

Definition at line 772 of file MexIFace.h.

References toMXArray().

template<template< typename... > class Array, class ConvertableT >
mxArray * mexiface::MexIFace::toMXArray ( const Array< ConvertableT > &  arr)
static

Definition at line 786 of file MexIFace.h.

References toMXArray().

template<class ElemT , typename >
ElemT mexiface::MexIFace::toScalar ( const mxArray *  m)
static

Definition at line 510 of file MexIFace.h.

template<class ElemT , typename >
MexIFace::Vec< ElemT > mexiface::MexIFace::toVec ( const mxArray *  m)
static

Definition at line 523 of file MexIFace.h.

Member Data Documentation

mxArray** mexiface::MexIFace::lhs
protected

Left-hand-side (output) argument array. Size=nlhs.

Definition at line 183 of file MexIFace.h.

Referenced by makeOutputArray(), and output().

IdxT mexiface::MexIFace::lhs_idx
protected

Index of the next left-hand-side argument to write as output.

Definition at line 184 of file MexIFace.h.

Referenced by makeOutputArray(), and output().

MethodMap mexiface::MexIFace::methodmap
protected

Maps names (std::string) to member functions (std::function<void()>)

Definition at line 179 of file MexIFace.h.

Referenced by mexFunction().

MXArgCountT mexiface::MexIFace::nlhs
protected

Number of left-hand-side (output) arguments passed to MexIFace::mexFunction.

Definition at line 182 of file MexIFace.h.

Referenced by checkMaxNumArgs(), checkMinNumArgs(), checkNumArgs(), checkOutputArgRange(), and output().

MXArgCountT mexiface::MexIFace::nrhs
protected

Number of right-hand-side (input) arguments passed to MexIFace::mexFunction.

Definition at line 185 of file MexIFace.h.

Referenced by checkInputArgRange(), checkMaxNumArgs(), checkMinNumArgs(), checkNumArgs(), mexFunction(), and output().

const mxArray** mexiface::MexIFace::rhs
protected
IdxT mexiface::MexIFace::rhs_idx
protected
MethodMap mexiface::MexIFace::staticmethodmap
protected

Maps names (std::string) to static member functions (std::function<void()>)

Definition at line 180 of file MexIFace.h.

Referenced by mexFunction().


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