Code covered by the BSD License  

Highlights from
arrayadapt

Be the first to rate this file! 2 Downloads (last 30 days) File Size: 8.64 KB File ID: #32406

arrayadapt

by Armin Schmidt

 

02 Aug 2011 (Updated 08 Aug 2011)

A C++ wrapper class for MATLAB's mxArray type

| Watch this File

File Information
Description

arrayadapt provides a convient way to access mxArrays in MATLAB's .mex files.
The 'ArrayAdaptor' class template can be specialzed for one of the builtin
numeric types and a fixed number of dimensions. It allows for subscripted
indexing in additon to using C's []-indexing style.
An array which is constructed to be n-dimensional will only take 'n' arguments for
specifying the size of each dimension in the constructor. Specifying a different
number will result in a compiler-error. Furthermore, also the indexing
operator will take exactly 'n' arguments. Providing more or less than 'n' indices
will result in a compiler-error, again. One source of headache eliminated.

Currently, one- through three-dimensional arrays of any numeric type can be
wrapped, but extending to an arbitrary number of dimensions can be easily done
by implementing two simple class templates. One that takes care of construction
and one that encapsulates element access.

If debug mode is active for your mex-file, bounds-checking on element access
and type-checking on construction is done (at runtime, of course).

Since arrayadapt only provides a different interface to the underlying mxArray
it will never interfere, in any way, with existing code that changes the data
by other means (direct access, other wrappers, etc).

Along with arrayadapt comes an 'mx_traits' class template which is currently
used to provide a consistent way to get the mxClassID associated with the
numeric types in C.

On performance:
Any decent compiler should be able to strip away the arrayadapt extras completely.
On my systems (tested on gcc 4.5 and 4.6) there is no trace left of it in the
resulting assembly. No function calls, no classes, no nothing.

All files are also available directly via github (https://github.com/Dunkelschorsch/arrayadapt).

MATLAB release MATLAB 7.12 (R2011a)
Other requirements C++ compiler with proper support for C99's exact-width integer types (defined in stdint.h)
Tags for This File  
Everyone's Tags
c, matrix, mex, vector
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
08 Aug 2011

Dropped the non-singleton dimension constraint

Contact us