SetParameter Aspect
[ParameterDatabase Group]

This aspect is defined in file: ../../AspectXLib/ParameterDatabase/ParameterDatabase/aspects/SetParameter.ax

Aspect Description

Inserts function calls that replaces member variables where the value of the variable is updated. One of fours sample aspect programs that modifies the component to access all its parameters from a parameter database. This group of aspect programs show an example of how the implementation of selected classes in a certain code base can be modified to change the way in which member variables are handled. In this example, all member variables in the base code are moved to a dedicated object called parameter database (see Parameter Database Design Pattern).

The DC_BasicDatabase is used as a component that stores the parameter data of target class. The DC_BasicDatabase class extends the abstract class ParameterDatabase. Both classes are defined and implemented in OBS Framework.

These aspect programs replace all three member variables in class SampleClass by respective method calls setParameter() and getParameterXXX() of class DC_BasicDatabase. String XXX stands for data type of member variable being replaced. In this example it is assumed that member variable names starts with underline ( _ ) character. For each member variable there is as parameter identifier woven in the base code. Parameter identifier is a constant in the form PDxxx where "xxx" is member variable name in upper case. Parameter identifiers are used to uniquely identify the parameters stored in the parameter database. Methods getParameterXXX() takes the parameter identifiers as their parameters. Methods setParameter() have two parameters. The first one is the parameter identifier, the second one is the new value of the parameter that is to be stored in the database.

This aspect contains two advices. They replace member variables with pDB->setParameter() method call. This aspect program uses pointcuts defined in file PointcutLibrary.xml.
Author:
A. Pasetti, O. Rohlik
See also:
PointcutLibrary
BaseParameter
GetParameter
Includes:
PointcutLibrary(PointcutLibrary.ax)

Pointcuts

exprtargetIntExprSetter
 
exprtargetFloatExprSetter
 

Advices

replacetargetIntExprSetter
  Replace integer member variable with the pDB->setParameter() method call
replacetargetFloatExprSetter
  Replace float member variable with the pDB->setParameter() method call

Pointcut Documentation

expr targetIntExprSetter (source)
expr targetFloatExprSetter (source)

Advice Documentation

replace targetIntExprSetter (source)

Triplet: expr replace codeFragment

Replace integer member variable with the pDB->setParameter() method call. Only those member variable occurrences are replaced where the value of the variable is changed. Other cases, where the value is not changed, are covered by advice targetIntNameGetter.

For example consider the assignment to member variable _width. The expression _width = 2 * iRadius is replaced by pDB->setParameter(PD_WIDTH, 2 * iRadius);. The substring _WIDTH is automatically generated from the variable name. The second parameter (i.e. 2 * iRadius) is extracted from expr srcML element as substring after the equal sign (=).

This advice assumes that assignments are not used in conditions (e.g. if (foo = 1) foo = 0;) since the setParameter() method does not have any return value.

Refers to global pointcut: expr targetIntExprSetter (PointcutLibrary)

replace targetFloatExprSetter (source)

Triplet: expr replace codeFragment

Replace float member variable with the pDB->setParameter() method call. Only those member variable occurrences are replaced where the value of the variable is changed. Other cases, where the value is not changed, are covered by advice targetFloatNameGetter.

For example consider the assignment to member variable _flt. The expression _flt = 3.14f * fRadius is replaced by pDB->setParameter(PD_FLT, 3.14f * fRadius);. The substring _FLT is automatically generated from the variable name. The second parameter (i.e. 3.14f * fRadius) is extracted from expr srcML element as substring after the equal sign (=).

This advice assumes that assignments are not used in conditions (e.g. if (foo = 1.0) foo = 0.0f;) since the setParameter() method does not have any return value.

Refers to global pointcut: expr targetFloatExprSetter (PointcutLibrary)