主要内容

findMethod

R2026b

Find method in C++ class

Since R2026b

    Description

    methodDef = findMethod(classDef,CPPName) finds a method in the specified class that matches the specified name and returns a clibgen.api.MethodDefinition object for the matching method. If the function does not find a match, it returns an empty MethodDefinition object.

    example

    methodDef = findMethod(classDef,CPPName,CPPInputTypeNames=typeNames) finds methods with the specified input type list.

    example

    Examples

    collapse all

    Find a method in the Shape class, then display its MATLAB signature.

    Configure the interface for a library defined by shapelib.hpp and create an interface definition object.

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

    Display information about the methods of the Shape class.

    clsDef = idef.findClass("geometry::Shape");
    clsDef.Methods
    ans = 
      1×7 MethodDefinition array with properties:
    
        CPPName
        MATLABName
        Overloaded
        OwningClassName
        CPPSignature
        MATLABSignature
        CPPInputs
        CPPOutput
        Status
        Included
    
      Display as table
    

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

           CPPName        MATLABName      Overloaded      Status      Included
        _____________    _____________    __________    __________    ________
    
        "setVertices"    "setVertices"      false       Incomplete     false  
        "getVertices"    "getVertices"      false       Incomplete     false  
        "area"           "area"             false       Complete       true   
        "perimeter"      "perimeter"        false       Complete       true   
        "scale"          "scale"            true        Complete       true   
        "scale"          "scale"            true        Incomplete     false  
        "getName"        "getName"          false       Complete       true   
    
    

    Display the MATLAB signature for the area method.

    clsDef = idef.findClass("geometry::Shape");
    methDef = clsDef.findMethod("area");
    methDef.MATLABSignature
    ans = 
    
        "MATLAB signature for MethodDefinition
         	Maps C++ signature:
         	double geometry::Shape::area() const
         
         	to MATLAB as:
         	RetVal = clib.shapelib.geometry.Shape/area()
         		Output Arguments
         			RetVal  double
         "

    If a method has overloads, use CPPInputTypeNames argument to disambiguate.

    Using the shapelib interface, display information about the methods.

    clsDef = idef.findClass("geometry::Shape");
    scaleDef = clsDef.findMethod("scale")
    scaleDef = 
      1×2 MethodDefinition array with properties:
    
        CPPName
        MATLABName
        Overloaded
        OwningClassName
        CPPSignature
        MATLABSignature
        CPPInputs
        CPPOutput
        Status
        Included
    
      Display as table
    

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

      CPPName    MATLABName    Overloaded      Status      Included
        _______    __________    __________    __________    ________
    
        "scale"     "scale"        true        Complete       true   
        "scale"     "scale"        true        Incomplete     false  
    

    Display the signature of the scale method that is included in the interface.

    scaleDef = clsDef.findMethod("scale",CPPInputTypeNames="double");
    scaleDef.MATLABSignature
    
    ans = 
        "MATLAB signature for MethodDefinition
         	Maps C++ signature:
         	void geometry::Shape::scale(double factor)
         
         	to MATLAB as:
         	clib.shapelib.geometry.Shape/scale(factor)
         		Input Arguments
         			factor  double
         "
    

    Choose the method with the double argument.

    scaleDef = clsDef.findMethod("scale",CPPInputTypeNames="double")
    
    scaleDef = 
      MethodDefinition with properties:
    
                CPPName: "scale"
             MATLABName: "scale"
             Overloaded: true
        OwningClassName: "geometry::Shape"
           CPPSignature: "void geometry::Shape::scale(double factor)"
        MATLABSignature: clib.shapelib.geometry.Shape/scale(factor)
              CPPInputs: [1×1 clibgen.api.InputArgumentDefinition]
              CPPOutput: [1×0 clibgen.api.OutputArgumentDefinition]
                 Status: Complete
               Included: true
    
      Show all properties
    

    To call this method in MATLAB, type clib.shapelib.geometry.Shape/scale(factor).

    Input Arguments

    collapse all

    Class definition, specified as a clibgen.api.ClassDefinition object.

    C++ class method name, specified as a string scalar.

    Fully qualified C++ input type names, specified as a string vector, used to disambiguate overloaded methods.

    Output Arguments

    collapse all

    Method definition, returned as a clibgen.api.MethodDefinition object.

    Version History

    Introduced in R2026b