Main Content

defineArgument

R2026b

Class: clibgen.ConstructorDefinition
Namespace: clibgen

(Not recommended) Add input argument definition for C++ constructor

defineArgument is not recommended. For more information on updating your code, see Version History.

Description

defineArgument(ConstructorDefinition,CPPName,MATLABType) adds an input argument definition for a C++ constructor.

defineArgument(ConstructorDefinition,CPPName,MATLABType,Direction) defines whether argument is input, output, or both.

defineArgument(ConstructorDefinition,CPPName,MATLABType,Direction,Shape) provides information about data dimensions.

defineArgument(___,Name=Value) adds additional argument definition options specified by one or more name-value arguments, and can include any of the input parameters in previous syntaxes.

Input Arguments

expand all

Constructor definition, specified as a clibgen.ConstructorDefinition object.

C++ argument name, specified as a string scalar or a character vector and is used with the Description name-value argument.

MATLAB® type, specified as a string scalar or a character vector.

Argument type, specified as "input" for an input argument, "output" for an output argument, or "inputoutput" for both an input and an output argument.

Dimension definition used by MATLAB to define data dimensions, specified as a string vector, scalar text, positive integer vector, "nullTerminated", or a cell array. For a cell array, the elements are a combination of scalar text and scalar positive integers. For more information, see Define Missing Size Property.

If you can define the argument dimension as a fixed scalar value, then enter a number, such as 5.

If the dimension is defined by another argument, then enter the argument name as a string. For example, consider the following C++ signature. If argument len defines the length of data, then the value of Shape is "len".

myFunc(const int *data, int len)

If the size of an argument is defined by an array, then the value of Shape is one of the following:

  • 1

  • Fixed dimensions: Enter a numerical array, such as [5,2].

  • Variable dimensions: Enter a string array of parameter names, such as ["row","col"].

If the C++ type for the argument is a string, then use these options to choose values for the MATLABType and Shape arguments.

C++ TypeMATLABTypeDirectionOptions for Size
char*a

"int8"

"input"

Scalar value
Array of scalar values

char**
char*[]

"string"

"input"

cell

const char*

"char"

 

Scalar value
Array of scalar values

"string"

"input"

"nullTerminated"

const char**
const char*[]

"char"

"input"

Scalar value
Array of scalar values

"string"

"input"

"nullTerminated"

a These types are equivalent to MATLAB char:

  • wchar_t

  • char16_t

  • char32_t

For more information, see C++ to MATLAB Data Type Mapping.

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

C++ argument description, specified as a string scalar or a character vector. This value sets the Description property.

Transfer memory ownership of argument, specified as a numeric or logical 1 (true) or 0 (false). MATLAB owns memory that is allocated as a pointer or a reference for an input argument. The C++ library should not free this memory. To change this behavior for a non-const argument, set ReleaseOnCall to true.

The ReleaseOnCall argument is not supported for:

  • const arguments.

  • Double pointer (obj** or void**) arguments defined as output.

If ReleaseOnCall is not specified, then ReleaseOnCall is false.

For more information, see Lifetime Management of C++ Objects in MATLAB.

Where to pad dimensions, specified as a numeric or logical 1 (true) or 0 (false). By default, when a MATLAB input has fewer dimensions than the corresponding C++ argument, then MATLAB inserts singleton dimensions at the beginning of the Shape argument. To insert singleton dimensions at the end, set AddTrailingSingletons to true. For more information , see Dimension Matching.

Example: AddTrailingSingletons=true

Data Types: logical

Version History

Introduced in R2019a

collapse all