How to include user headers before #include guard automatically generated by Rhapsody

Technote (FAQ)


Question

How do you control the way IBM Rational Rhapsody generates #include statements so that you can ensure a particular header you want to include gets included prior to any other headers automatically generated by Rhapsody?

Cause

Generally, using Rhapsody model properties (<Lang>_CG::Class::SpecIncludes or <Lang>_CG::Class::ImpIncludes) allows you to generate #include statement in the generated files. However, the specified #include statement will be located under the auto-generated #include lines as below:

//## auto-generated

#include <oxf\oxf.h>

//## auto-generated

#include "Default.h"

//## auto-generated

#include "HeaderAddedInProperty.h"

In some cases (for example to satisfy certain dependency requirements), you may need to have HeaderAddedInProperty.h being included before the auto-generated #include lines as below:

#include "HeaderAddedInProperty.h"

//## auto-generated

#include <oxf\oxf.h>

//## auto-generated

#include "Default.h"

Answer

To customize the order of #include statements, consider using Rhapsody Java API or PostProcessor tool feature. The easiest way will be to use <Lang>_CG::File::SpecificationHeader and/or <Lang>_CG::File::ImplementationHeader properties, but there is a known problem of using these properties for this purpose.

Background:

The original usage of above properties is to define your own header information like copyright which is always generated at the right beginning of generated files. If you add the additional #include statement at the end of the header section, the specified #include statement would be generated before the tool auto-generated #include lines. However, by doing so, you will see a File element representing HeaderAddedInProperty.h being mapped into your model which will indirectly cause the specified #include statement repeatedly generated as below:

#include "HeaderAddedInProperty.h"
#include "HeaderAddedInProperty.h"

//## auto-generated

#include <oxf\oxf.h>

//## auto-generated

#include "Default.h"

OPTIONS:

  • Use "ignore" annotation

    Rhapsody RoundTrip takes effects based on a set of pre-defined internal annotations.

    If annotation "//#[ ignore ..//#]" is used to surround the user #include statement, RoundTrip won't map the include code into model. As a result, you won't see duplicated #include statement being generated.

    Below is an example of the value set in property <Lang>_CG::File::SpecificationHeader and/or <Lang>_CG::File::ImplementationHeader .

    /*********************************************************************
    Rhapsody : $RhapsodyVersion
    Login : $Login
    Component : $ComponentName
    Configuration : $ConfigurationName
    Model Element : $FullModelElementName
    //! Generated Date : $CodeGeneratedDate
    File Path : $FullCodeGeneratedFileName
    *********************************************************************/
    //#[ ignore
    #include "HeaderAddedInProperty.h"
    //#]

  • Use "preserve" annotation (for v7.6.1 or higher)

    Since Rhapsody v 7.6.1, annotation "preserve" has been introduced in the tool to exclude user code from RoundTrip and Reverse Engineering. For more information, refer to the topic "Excluding code from roundtripping and reverse engineering" at IBM Rational Rhapsody Info Center.

    Below is an example of the value set in property <Lang>_CG::File::SpecificationHeader and/or <Lang>_CG::File::ImplementationHeader .

    //#[preserve
    /*********************************************************************
    Rhapsody : $RhapsodyVersion
    Login : $Login
    Component : $ComponentName
    Configuration : $ConfigurationName
    Model Element : $FullModelElementName
    //! Generated Date : $CodeGeneratedDate
    File Path : $FullCodeGeneratedFileName
    *********************************************************************/
    #include "HeaderAddedInProperty.h"
    //#]preserve

    Important: Above examples are only applied for Rhapsody C++ models. For Rhapsody C models, add "/*#[ preserve*/" before and "/*#] preserve*/" after the block.


Related information

Excluding code from roundtripping and reverse engineeri

Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

Rational Rhapsody
General Information

Software version:

7.5, 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, 8.0, 8.0.1, 8.0.2

Operating system(s):

Windows

Reference #:

1627219

Modified date:

2013-05-21

Translate my page

Machine Translation

Content navigation