The Good Ones in the Pot, the Bad Ones in the Crop.

You might be familiar with the scene from Cinderella where Cinderella's stepsisters bully her with sorting peas. For many of us, sorting and organizing is a chore, even though we know that structure and order can make our jobs easier. In C++, namespaces can be used to structure code elements that belong together, thereby modularizing the code. This order gives the developer more freedom in naming functions, classes, or variables, because it ensures that these things are always understood only in the respective namespace, and there can be no ambiguity. Especially in heavily distributed development processes, name ambiguities in different software components can cause problems that are not discovered until late in the integration phase. In this blog post, we'll show you how namespaces can be currently used in TargetLink and what interesting new features we will be releasing with TargetLink 2023-B. 

First: The What
Figure 1: Namespace declaration and definition

First: The What

In C++, namespaces are defined using the namespace keyword. The namespace keyword is followed by curly braces, which provide a scope for the symbols contained within it, i.e., types, functions, or variables. You can nest namespaces to create hierarchies that represent the modular architecture of your code. To address a symbol from a namespace, prefix the symbol with a namespace name, as shown in figure 1.

Second: The Why

Many of you probably know that C++ is the programming language of the Adaptive AUTOSAR standard. The service-oriented architecture of the Adaptive AUTOSAR standard has a lot to offer when it comes to meeting future challenges in the automotive domain, such as autonomous driving, vehicle connectivity, or using high performance controllers (HPCs). The Adaptive AUTOSAR standard and its associated coding guidelines encourage users to use namespaces because they enable structured, modular, and controlled development, which improves flexibility, scalability, and durability. 

Third: The How

Creating and managing namespaces in TargetLink takes place in the TargetLink Data Dictionary (DD) and is as convenient as for other data . You can create namespaces and custom namespace groups in the Pool area. You can then reference the corresponding namespace at AUTOSAR DD objects such as service interfaces or TargetLink DD objects as typedefs.

Figure 2: Creating and referencing namespaces in TargetLink

Of course, this also works in the recommended top-down workflow, where you start with an ARXML file from an architecture modeling tool. After importing the ARXML into the DD, all the namespaces contained in the ARXML are created for you and referenced at the corresponding DD objects. This means that everything is ready for generating a working frame model and modeling the behavior of the AUTOSAR software component.

In discussions with our customers, we have found that you want to make sure that all of your application code is generated in a namespace, either because of the Adaptive AUTOSAR coding guidelines or other requirements. For this reason, we are introducing a new feature with TargetLink 2023-B: the general namespace. The general namespace feature lets you assign a namespace to a module or software component. The namespace is then inherited by all objects in the module or software component, although you can still reference other namespaces on selected objects as usual. Just as the pigeons helped Cinderella sort the peas, this feature saves you from having to manually assign namespaces to all variables, functions, and types of the application.
 

Figure 3: Using the general namespace feature

Figure 4: NamespaceQualification Code Generator option set to Reduced and Full

While we always try to generate the best and most compliant code possible, you may still want to customize the generated code to suit your needs. It is important to us that you get exactly the code you want, so we have naturally included customization for namespace usage. For example, by setting the NamespaceQualification Code Generator option to Reduced, you can configure whether elements in the generated code are qualified with their full namespace or only with the namespace that differs from the surrounding namespace. If you set the Code Generator option to Reduced, you will get more readable code. On the downside, ambiguities related to symbol names might appear if you integrate external code. Therefore, the Code Generator option is set to Full by default.

Last: Your Take

The Adaptive AUTOSAR standard has a lot to offer for the automotive domain and its future challenges, and it is closely linked to modern C++. At dSPACE, we want to offer you the best solution for your challenges, so we are always happy to talk to you about your future needs regarding C++ and receive your feedback on existing features. The general namespace function of TargetLink 2023-B is one of the topics that we discussed frequently in customer meetings. We therefore encourage you to contact us so that we can continue to be the pigeons that help you.

About the Autor

Sven Siemon

Sven Siemon

Technical Author, R&D Governance & Competence Partners, dSPACE GmbH

Drive innovation forward. Always on the pulse of technology development.

Subscribe to our expert knowledge. Learn from our successful project examples. Keep up to date on simulation and validation. Subscribe to/manage dSPACE direct and aerospace & defense now.

Enable form call

At this point, an input form from Click Dimensions is integrated. This enables us to process your newsletter subscription. The form is currently hidden due to your privacy settings for our website.

External input form

By activating the input form, you consent to personal data being transmitted to Click Dimensions within the EU, in the USA, Canada or Australia. More on this in our privacy policy.