Main Content

clibgen.api.FunctionDefinition

R2026b

MATLAB definition for C++ function

Since R2026b

    Description

    A clibgen.api.FunctionDefinition object represents the MATLAB® definition of a C++ function.

    Creation

    fcnDef = idef.Functions creates a function definition object from the Functions property of a clibgen.api.InterfaceDefinition object.

    fcnDef = idef.IncompleteFunctions creates a function definition object from the IncompleteFunctions property.

    Properties

    expand all

    This property is read-only.

    Fully qualified C++ function name, represented as a string scalar.

    MATLAB name for the C++ function, specified as a string scalar.

    This property is read-only.

    C++ signature, represented as a string scalar.

    This property is read-only.

    MATLAB signature for the function, represented as a string scalar.

    This property is read-only.

    MATLAB definition of C++ input parameters, represented as a clibgen.api.InputArgumentDefinition object.

    This property is read-only.

    MATLAB definition of the C++ return argument, represented as a clibgen.api.OutputArgumentDefinition object.

    This property is read-only.

    Whether any C++ input or output argument requires additional definition, represented as Complete or Incomplete.

    Whether this construct is included in the interface, specified as a numeric or logical 1 (true) or 0 (false).

    This property is read-only.

    Whether the function is overloaded, represented as true or false.

    Doxygen @brief comments that describe the function for the end user, specified as a string scalar. If the header file does not contain @brief comments, the text for Description is:

    MATLABName    Representation of C++ function CPPName.

    Use the Description property to modify the description in the FunctionDefinition object.

    Doxygen @details comments from the header file, specified as a string scalar. If the header file does not contain Doxygen comments about the function, then DetailedDescription is empty and does not appear in the definition file.

    If DetailedDescription is not empty, then the MATLAB doc command displays the following sentence before displaying the value of DetailedDescription:

    This content is from the external library documentation.

    Use the DetailedDescription property to provide more information about the interface definition file.

    Examples

    collapse all

    Identify and define an incomplete function processReadings.

    Configure the interface for a library defined by processReadings.hpp.

    icfg = clibgen.api.InterfaceConfiguration("libname",HeaderFiles = "processReadings.hpp");
    idef = clibgen.api.InterfaceDefinition(icfg);
    

    Display all functions, complete and incomplete.

    idef.Functions
    ans = 
      1×2 FunctionDefinition array with properties:
    
        CPPName
        MATLABName
        Overloaded
        CPPSignature
        MATLABSignature
        CPPInputs
        CPPOutput
        Status
        Included
    
      Display as table
    

    If there are multiple functions, click the Display as table link.

             CPPName                   MATLABName              Overloaded      Status      Included
        _________________    ______________________________    __________    __________    ________
    
        "processReadings"    "clib.libname.processReadings"      false       Incomplete     false  
        "debugDump"          "clib.libname.debugDump"            false       Complete       true   
    

    Inspect the processReadings function.

    fcnDef = idef.findFunction("processReadings")
    fcnDef = 
    
      FunctionDefinition with properties:
    
                CPPName: "processReadings"
             MATLABName: "clib.libname.processReadings"
             Overloaded: false
           CPPSignature: "void processReadings(double * data,int length)"
        MATLABSignature: <Define incomplete inputs to see the MATLAB signature.>
              CPPInputs: [1×2 clibgen.api.InputArgumentDefinition]
              CPPOutput: [1×0 clibgen.api.OutputArgumentDefinition]
                 Status: Incomplete
               Included: false
    
      Show all properties

    The status of processReadings is incomplete.

    Inspect the arguments.

    fcnDef.CPPInputs
    
    ans = 
    
      1×2 InputArgumentDefinition array with properties:
    
        Name
        Position
        CPPType
        MATLABType
        Direction
        Size
        Status
    
      Display as table

    To see argument details, click the Display as table link.

          Name      Position     CPPType              MATLABType               Status  
        ________    ________    __________    ___________________________    __________
    
        "data"         1        "double *"    "clib.array.libname.Double"    Incomplete
        "length"       2        "int"         "int32"                        Complete  

    Display the signature to see how the function uses the arguments.

    fcnDef.CPPSignature
    ans = 
    
        "void processReadings(double * data,int length)"
    

    The data argument is a pointer. MATLAB cannot automatically determine the size of data. Define data as an input array whose size is the length argument.

    argDef = fcnDef.CPPInputs([fcnDef.CPPInputs.Name] == "data");
    argDef.define(MATLABType="double",Direction="input",Size="length");

    Verify that the processReadings function is complete and included in the interface.

    fcnDef
      FunctionDefinition with properties:
    
                CPPName: "processReadings"
             MATLABName: "clib.libname.processReadings"
             Overloaded: false
           CPPSignature: "void processReadings(double * data,int length)"
        MATLABSignature: clib.libname.processReadings(data)
              CPPInputs: [1×2 clibgen.api.InputArgumentDefinition]
              CPPOutput: [1×0 clibgen.api.OutputArgumentDefinition]
                 Status: Complete
               Included: true
    
      Show all properties

    When you create an input array in MATLAB, the variable has a defined size. So the syntax to call processReadings in MATLAB is clib.libname.processReadings(data).

    fcnDef.MATLABSignature
    ans = 
    
        "MATLAB signature for FunctionDefinition
         	Maps C++ signature:
         	void processReadings(double * data,int length)
         
         	to MATLAB as:
         	clib.libname.processReadings(data)
         		Input Arguments
         			data vector double
         "

    Version History

    Introduced in R2026b