Conditional properties

With conditional properties, you can define the value for one property as a conditional expression that is evaluated according to the value of another property. In other words, the value of one property depends on the value of another property.

Using conditional properties

In the following examples, these properties are for illustrative purposes only; they do not exist in the product.
  • CG::Class::PrefixCode
  • CG::Class::ClassCompilationFlag

For CG::Class::PrefixCode, you might enter a value of #define $<CG::Class::ClassCompilationFlag>. This means that the value for CG::Class::PrefixCode is based on the value of CG::Class::ClassCompilationFlag.

Because you do not want to get an empty #define, you must set the property to use the value from CG::Class::ClassCompilationFlag only if it is not an empty string. You must define CG::Class::PrefixCode with a condition. See the following example.

In this example, the keywords for the conditional expression are in boldface type.

?<begin> $<CG::Class::ClassCompilationFlag> ?<!=>?<?>#define $<CG::Class::ClassCompilationFlag>?<:>?<end> 

This expression means that if the value of CG::Class::ClassCompilationFlag is not an empty string; the value for the property is #define $<CG::Class::ClassCompilationFlag>. Otherwise, the value is an empty string.

Syntax

The template for a conditional expression is like the conditional assignment in the C language and C++ languages:

(Condition ? True-Part : False-Part)

For the property definition, the template is:

?<begin> Condition?<?>True-Part?<:>False-Part?<end>

To make the definition more flexible, each part (the True-Part or False-Part) of the conditional expression is recursive; that is, it also can be a conditional expression.

In this example, the keywords for the conditional expression are in boldface type and italic type. The operators for the conditional expression are in boldface, and the tokens are in italics.

?<begin> Condition1?<?>?<begin> Condition2?<?>True-Part2 ?<:>False-Part2?<end>?<:>False-Part1?<end>

True-Part2, False-Part2, and False-Part1 can be conditional expressions as well.

The condition part of the expression can use one of the following keywords to create a more complex conditional expression:

?<==> (equals), ?<!=> (not equals), ?<&&> (and), ?<||> (or),

In this example, the keywords for the conditional expression are in boldface type and italic type. The operators for the conditional expression are in boldface, and the tokens are in italics.

?<begin> $<CG::Class::ClassCompilationFlag> ?<!=>FLAG1 ?<&&> $<CG::Class::ClassCompilationFlag ?<!=>FLAG2 ?<||>
$<CG::Class::ClassCompilationFlag> ?<!=>FLAG3 ?<?>#define $<CG::Class::ClassCompilationFlag>?<:> /*No Compilation Flag for this class */?<end>

Defining the prefix

To have the value of a property evaluated as a conditional expression, you must add a prefix to the property. The prefix is defined in the General::Project::ConditionalPropertyPrefix property at the project level only. For the MicroC profile, the default value for this property is ?<IsConditionalProperty>. The ?<IsConditionalProperty> token is removed from the value of the property after it is evaluated, as in the following example.

?<IsConditionalProperty>?<begin> $<CG::Class::ClassCompilationFlag> ?<!=>?<?>#define $<CG::Class::ClassCompilationFlag>?<:>?<end>

In this example, the property value is evaluated as a conditional expression and the conditional expression to be evaluated is:

?<begin> $<CG::Class::ClassCompilationFlag> ?<!=>?<?>#define $<CG::Class::ClassCompilationFlag>?<:>?<end>

In all these examples, the full path for a property is used, that is, $<Subject::Meta-Class::Property-Name>.

If you use only one token, for example, $<Property-Name>, the product treats the token as a shortcut to the full path, that is, $<CG::<Environment>::Property-Name>, where <Environment> is the name of the selected environment in the Settings tab for the active configuration.

The CG token is replaced with C_CG, CPP_CG, in this example, depending on the relevant language of the component.

Every $<token> in the property definition is replaced, either by the value of the referenced property (the full path or shortcut) or with an empty string when the referenced property is not found.

Other options that can be used with conditional properties

$<Tag::tag-name> - use to include the value of a tag on the queried element, for example, $<Tag::testStatus>.

$<Env::environment variable name> - use to include the value of an environment variable.

$<INI::section name,variable name> - use to include the value of a variable from the rhapsody.ini file.

$<ProjectFolder> - use to include the path of the project folder (the folder that contains the .rpy file, for example, L:\IBM\Rhapsody\8.4\Samples\CppSamples\HomeAlarm)

$<ProjectPath> - use to include the path to the project's _rpy folder, for example, L:\IBM\Rhapsody\8.4\Samples\CppSamples\HomeAlarm\HomeAlarm_rpy

$<ProjectName> - use to include the name of the project

$<UnitFileName> - use to include the name of the file for the unit (for example, MySubPackage_1.sbsx)

$<ConnectionID> - use to include the connection string (for example, RHAPSODY2.8.4.0.0:14960:x64)

$<GUID> - use to include the GUID of the element