Define Missing SHAPE
Parameter
In C++, pointer arguments are used for both scalar data and array data. To use a pointer
as an array, MATLAB® needs dimension information to safely convert the array between C++ and
MATLAB. The SHAPE
parameter helps you specify the dimensions for the
pointer.
Note
Pointers representing arrays of C++ class objects can only be used as scalars. Define
SHAPE as 1
in the library definition file.
The following example C++ signatures show you how to specify the shape of an argument. In these tables, the descriptions for the functions in the C++ Signature and Role of Pointer column are based on assumed knowledge of the arguments. The signature itself does not provide this information.
Define Pointer Argument to Fixed Scalar
C++ Signature and Role of Pointer | defineArgument Values |
---|---|
The input to this function is a scalar pointer
void readScalarPtr(int const * in) | For argument defineArgument(readScalarPtrDefinition, "in", ... "int32", "input", 1); |
The input to this function is a scalar pointer to class
void readScalarPtr(ns::MyClass2 const * in) | For argument defineArgument(readScalarPtrDefinition, "in", ... "clib.cppUseCases.ns.MyClass2", "input", 1); |
Define Pointer Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a pointer to an integer array of length
void readMatrix1DPtr(int const * mat, size_t m) | For argument defineArgument(readMatrix1DPtrDefinition, "mat", ... "int32", "input", "m"); |
The input to this function is a pointer to a fixed-length array
void readMatrix1DPtrFixedSize(int const * mat) | For argument defineArgument(readMatrix1DPtrFixedSizeDefinition, ... "mat", "int32", "input", 5); |
The input to this function is a pointer to a two-dimensional integer
matrix void readMatrix2DPtr(int const * mat, size_t m, size_t n) | For argument defineArgument(readMatrix2DPtrDefinition, "mat", ... "int32", "input", ["m","n"]); |
The input to this function is a pointer to a two-dimensional matrix
void readMatrix2DPtrFixedSize(int const * mat) | For argument defineArgument(readMatrix2DPtrFixedSizeDefinition, ... "mat", "int32", "input", 6); |
The input to this function is a pointer to a three-dimensional matrix
void readMatrix3DPtr(int const * mat, size_t m, size_t n, size_t p) | For argument defineArgument(readMatrix3DPtrDefinition, "mat", ... "int32", "input", ["m","n","p"]); |
Define Array Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a one-dimensional array
void readMatrix1DArr(int const [] mat, size_t len) | For argument defineArgument(readMatrix1DArrDefinition, "mat", ... "int32", "input", "len"); |
The input to this function is a two-dimensional array
void readMatrix2DArr(int const [] mat, size_t len, size_t typeSz) | For argument defineArgument(readMatrix2DArrDefinition, "mat", ... "int32", "input", ["len","typeSz"]); |
Define Output Pointer Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a pointer to an array of length
int const * getRandomValues(size_t len) | For the return value defineOutput(getRandomValuesDefinition, "RetVal", ... "int32", "len"); |
The input to this function is a pointer to an array of length
int const * getRandomValues(size_t len) | For the return value defineOutput(getRandomValuesDefinition, "RetVal", ... "int32", "len", "DeleteFcn", "CustomDeleteFcn"); |
The output argument of this function is a pointer to a fixed-length array. int const * getRandomValuesFixedSize() | For the return value defineOutput(getRandomValuesFixedSizeDefinition, ... "RetVal", "int32", 5); |
The output argument of this function is a pointer to a 2-by-2 array. double * getRandomValuesArray() | For the return value defineOutput(getRandomValuesArrayDefinition, ... "RetVal", "double", [2,2]); |
The output argument of this function is a pointer to a 1-by-2 vector of
type double. The library provides a function named
double * getRandomValuesDouble() | For the return value defineOutput(getRandomValuesDoubleDefinition, ... "RetVal", "double", 2, "DeleteFcn", "CustomDeleteFcn"); |
The output argument of this function is a pointer to a 1-by-2 vector of
type double const * getRandomConstDouble() | For the return value defineOutput(getRandomConstDoubleDefinition, ... "RetVal", "double", 2, "DeleteFcn", "CustomDeleteFcn"); |
Define Additional Output Arguments
C++ Signature | defineArgument Values |
---|---|
This function returns an integer value and the value to which input
argument int getValues(int * arg) | For argument defineArgument(getValuesDefinition, "arg", "int32", "output", 1); |
To call the function built into interface
[out1, out2] = clib.A.getValues |
Define Scalar Object Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a pointer to class
double addClassByPtr(ns::MyClass2 const * myc2) | For the defineArgument(addClassByPtrDefinition, "myc2", ... "clib.cppUseCases.ns.MyClass2", "input", 1); |
The input to this function is a pointer to class
void updateClassByPtr(ns::MyClass2 * myc2, double a, short b, long c) | For argument defineArgument(updateClassByPtrDefinition, "myc2", ... "clib.cppUseCases.ns.MyClass2", "input", 1); |
The input to this function is a pointer to class
void readClassByPtr(ns::MyClass2 * myc2) | For argument defineArgument(readClassByPtrDefinition, "myc2", ... "clib.cppUseCases.ns.MyClass2", "input", 1); |
The input to this function is a pointer to class
void fillClassByPtr(ns::MyClass2 * myc2, double a, short b, long c) | For argument defineArgument(fillClassByPtrDefinition, "myc2", ... "clib.cppUseCases.ns.MyClass2", "input", 1); |
Define Matrix Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a pointer to an integer vector of length
void updateMatrix1DPtrByX(int * mat, size_t len, int x) | For argument defineArgument(updateMatrix1DPtrByXDefinition, ... "mat", "int32", "inputoutput", "len"); |
The input to this function is a reference to an integer array of length
void updateMatrix1DArrByX(int [] mat, size_t len, int x) | For argument defineArgument(updateMatrix1DArrByXDefinition, ... "mat", "int32", "inputoutput", "len"); |
The input to this function is a pointer to an integer vector of length
int addValuesByPtr(int * mat, size_t len) | For argument defineArgument(addValuesByPtrDefinition, "mat", ... "int32", "input", "len"); |
The input to this function is a reference to an integer array of length
int addValuesByArr(int [] mat, size_t len) | For argument defineArgument(addValuesByArrDefinition, ... "mat", "int32", "input", "len"); |
This function creates an integer vector of length void fillRandomValuesToPtr(int * mat, size_t len) | For argument defineArgument(fillRandomValuesToPtrDefinition, ... "mat", "int32", "output", "len"); |
This function creates an integer vector of length void fillRandomValuesToArr(int [] mat, size_t len) | For argument defineArgument(fillRandomValuesToArrDefinition, ... "mat", "int32", "output", "len"); |
Define String Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a C-style string. char const * getStringCopy(char const * str) | For argument defineArgument(getStringCopyDefinition, "str", ... "string", "input", "nullTerminated"); |
The return value for this function is a string. char const * getStringCopy(char const * str) | For return value defineOutput(getStringCopyDefinition, ... "RetVal", "string", "nullTerminated"); |
The return value for this function is a string of length
void getMessage(char * pmsg, int buf) | MATLAB defines argument %defineArgument(getMessageDefinition, "pmsg", ... "clib.array.libname.Char", "input", <SHAPE>); To
define
defineArgument(getMessageDefinition, "pmsg", ... "string, "output", "nullTerminated", ... "NumElementsInBuffer", "buf"); |
The input to this function is a string specified by length
void readCharArray(char const * chArray, size_t len) | For argument defineArgument(readCharArrayDefinition, ... "chArray", "char", "input", "len"); |
The input to this function is an array of type void readInt8Array(char const * int8Array, size_t len) | For argument defineArgument(readInt8ArrayDefinition, ... "int8Array", "int8", "input", "len"); |
The return value for this function is a scalar of characters. char const * getRandomCharScalar() | For return value defineOutput(getRandomCharScalarDefinition, ... "RetVal", "char", 1); |
The return value for this function is a 2 element character vector. char * getRandomChars() | For return value defineOutput(getRandomCharsDefinition, ... "RetVal", "char", 2); |
The return value for this function is a 2 element character vector. The
library provides a function named char * getRandomChars() | For return value defineOutput(getRandomCharsDefinition, ... "RetVal", "char", 2 "DeleteFcn", "CustomDeleteFcn"); |
The type of the return value for this function is
char const * getRandomInt8Scalar() | For return value defineOutput(getRandomInt8ScalarDefinition, ... "RetVal", "int8", 1); |
This function updates the input argument void updateCharArray(char* chArray, size_t len) | For argument defineArgument(updateCharArrayDefinition, ... "chArray", "int8", "inputoutput", "len"); |
The input to these functions is an array of C-string of size
void readCStrArray(char** strs, int numStrs); void readCStrArray(char* strs[], int numStrs); | For argument defineArgument(readCStrArrayDefinition, ... "strs", "string", "input", ["numStrs", "nullTerminated"]) |
The input to these functions is a void readConstCStrArray (const char** strs, int numStrs); void readConstCStrArray (const char* strs[], int numStrs); | Call defineArgument(readConstCStrArrayDefinition, ... "strs", "string", "input", ["numStrs", "nullTerminated"]) |
The input to this function is a fixed-size array of C-string. void readFixedCStrArray (char* strs[5]); | For argument defineArgument(readFixedCStrArrayDefinition, ... "strs", "string", "input", [5, "nullTerminated"]) |
The input to this function is a fixed-size void readConstCFixedStrArray (const char* strs[5]); | Call defineArgument(readConstFixedCStrArrayDefinition, ... "strs", "string", "input", [5, "nullTerminated"]) |
Define Typed Pointer Argument
C++ Signature | defineArgument Values |
---|---|
The input to this function is a pointer to typedef
void useTypedefPtr(intDataPtr input1)
typedef int16_t intData; typedef intData * intDataPtr; | For argument defineArgument(useTypedefPtrDefinition, "input1", ... "int16", "input", 1); |
Use Property or Method as SHAPE
You can use a public nonstatic C++ data member (property) as the
SHAPE
for the return type of a nonstatic method or another nonstatic
data member (property) in the same class. The property must be defined as an integer (C++
type int
). Similarly, you can use a static C++ data members as a
SHAPE
parameter for a return type of a static method or another static
data member in the same class.
You can use a public, nonstatic C++ method as the SHAPE
parameter for
a nonstatic property or for the return type of a nonstatic method in the same class. The
method must be fully implemented, without input arguments, and the return type must be
defined as a C++ type int
.
You can use a combination of parameters, properties and methods as the
SHAPE
parameter for a method return type. If the specified
SHAPE
exists as both a parameter and a method or property, then
parameters take precedence. In this case SHAPE
is treated as a
parameter.
C++ Signature | SHAPE Values |
---|---|
The size of data member class A { public: int rows; int cols; int* rowData; int channels(); }; | For property addProperty(ADefinition, "rowdata", ["rows","cols","channels"]... "Description", "clib.array.libname.Int Data member of C++ class A."); |
The size of the array returned by class B { public: int rows; int cols; int* rowData; int channels(); const int* getData(); }; | For the return value of method defineOutput(getDataDefinition, "RetVal", "clib.array.libname.Int", ... ["rows","cols","channels"]); |
The size of the array returned by class C { public: int rows; int channels(); const int* getData (int rows); }; | For the return value of method defineOutput(getDataDefinition, "RetVal", "clib.array.C.Int", ["rows","channels"]); |