IBM Support

How to generate unnamed (anonymous) namespace from Rhapsody model

Question & Answer


Question

How do you use IBM Rational Rhapsody to generate unnamed namespace in source file?

Cause

C++ allows you to declare an unnamed namespace as an alternative to global static variable.

You can use below properties in Rhapsody model to generate namespace in source file.

  • CPP_CG::Package:DefineNameSpace
  • CPP_CG::Package::NameSpaceName

But only enabling CPP_CG:Package::DefineNameSpace and leaving CPP_CG::Package::NameSpaceName empty won't generate unnamed namespace as expected.

Rhapsody would use the package name as the namespace by default if no value given in CPP_CG::Package::Name.

Answer

You have two solutions to generate unnamed namespace from Rhapsody model as follows;

Solution 1:

Directly put unnamed namespace code namespace {" and "} into below corresponding properties.


CPP_CG::Class::SpecificationProlog

CPP_CG::Class::SpecificationEpilog

CPP_CG::Class::ImplementationProlog

CPP_CG::Class::ImplementationEpilog

Note: You can also apply this solution to define a namespace on a specific class or even operation.

For example, if you hoping to create namespace against a class, then you should put the corresponding code into below properties of the target class:

CPP_CG::Class::SpecificationProlog

CPP_CG::Class::SpecificationEpilog

CPP_CG::Class::ImplementationProlog

CPP_CG::Class::ImplementationEpilog



Solution 2:

  1. Define an empty definition (ANONYMOUS_NAMESPACE)
  2. Put the definition name into property CPP_CG::Package::NameSpaceName

    Below code is expected in the source file.

-------------------------start----------------------------------
#define ANONYMOUS_NAMESPACE
namespace ANONYMOUS_NAMESPACE{

}
--------------------------end-----------------------------------

Note: A corresponding product enhancement requesting Rhapsody Code Generation simply creating unnamed(anonymous) namespace (RFE ID: 37791) is now registered in IBM RFE Community Site.

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.5;8.0.3;7.5.0.1;7.5.1;7.5.1.1;7.5.2;7.5.2.1;7.5.3;7.5.3.1;7.5.3.2;7.5.3.3;7.6;7.6.0.1;7.6.1;7.6.1.1;7.6.1.2;7.6.1.3;7.6.1.4;8.0;8.0.1;8.0.2","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21645128