Main Content

setClassNamespace

Set class namespace of model

Since R2021a

Description

example

setClassNamespace(myCPPMappingObj, namespace) sets the class namespace of the model in the generated code. Control the scope of the generated code by specifying a namespace for the generated class. In systems that use a model hierarchy, you can specify a different namespace for each model in the hierarchy.

Examples

collapse all

Specify a class namespace for a model and generate C++ code.

Open the model. To access the CodeMappingCPP object associated with the model, use the coder.mapping.api.get function.

open_system('CppClassRateBased');
cm = coder.mapping.api.get('CppClassRateBased');

To specify a namespace for the model in the generated code, use the setClassNamespace function.

setClassNamespace(cm, 'myClassNamespace');

To configure a nested namespace, use the scope resolution operator :: to specify scope.

setClassNamespace(cm, 'myNestedClassNamespace1::ns2::ns3');

Input Arguments

collapse all

C++ code mapping object, returned by a call to either the coder.mapping.utils.create function or the coder.mapping.api.get function.

Class namespace of model in the generated code, specified as a character vector. If you do not specify a class namespace, the model class is generated at the global scope. To configure a nested namespace, use the scope resolution operator :: in the form ns1::ns2::ns3.

Data Types: char | string

Version History

Introduced in R2021a