ParameterDatabaseByPointer Aspect
[ParameterDatabase Group]

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

Aspect Description

Sample aspect program that modifies the component to access all its parameters from a parameter database by pointer. This aspect program shows an example of how the implementation of selected classes in a certain base code 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 the target class. The DC_BasicDatabase class extends the abstract class ParameterDatabase. Both classes are defined and implemented in OBS Framework.

This aspect program replaces all member variables in class SampleClass by the respective pointers to the the instance of class DC_BasicDatabase. 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 getParameterPointerXXX() defined in ParameterDatabase class take the parameter identifiers as their parameters. The "XXX" stands for parameter type.

This aspect contains advice that replaces the occurences of member variables in class SampleClass by pointers that points to the parameter database. Other advices add parameter database variable declaration and initialization code to the base code. Yet another advice adds necessary #include preprocessor directives. This aspect program uses pointcuts defined in file PointcutLibrary.xml. It also defines two additional pointcuts targetParameterUsage and targetParameterDeclaration.
Author:
A. Pasetti, O. Rohlik
See also:
PointcutLibrary
Includes:
PointcutLibrary(PointcutLibrary.ax)

Pointcuts

unittargetClassDeclaration
 
expranySampleClassExpr
 
classtargetClass
 
nametargetParameterUsage
  Points to occurrences of member variables used in expression within methods, constructors and destructors of the target class
nametargetParameterDeclaration
  Points to declarations of member variables of the target class

Advices

addaddConstants
  Add constants to the class declaration
addaddIncludesToDeclaration
  Add the #include preprocessor instructions
addaddDatabaseReference
  Add declaration of pointer to parameter database to target class
begintargetFloatVarInitialization
  Initialize float* pointers to the parameter database by value returned by the method pDB->getParameterPointerFloat(PDxxx) where "xxx" is member variable name in upper case
begintargetIntVarInitialization
  Initialize int* pointers to the parameter database by value returned by the method pDB->getParameterPointerInt(PDxxx) where "xxx" is member variable name in upper case
beginaddDatabaseInicialization
  Add code fragment that initialize the parameter database
replacereplaceParametersByPointers
  Replace occurences of member variables with the dereferences of pointers to the parameter database
replacereplaceParameterDeclarationsByPointers
  Replace declarations of member variables with the declarations of pointers to the parameter database

Pointcut Documentation

unit targetClassDeclaration (source)
expr anySampleClassExpr (source)
class targetClass (source)
name targetParameterUsage (source)
Points to occurrences of member variables used in expression within methods, constructors and destructors of the target class. Member variables are identified as identifiers that starts with underline character ( _ ).
name targetParameterDeclaration (source)
Points to declarations of member variables of the target class. Member variables declarations are identified as identifiers that starts with underline character ( _ ) but does not appear in the methods, constructors or destructors of the target class.

Advice Documentation

add addConstants (source)

Triplet: unit add declaration

Add constants to the class declaration. Constants represent the parameter identifiers of all the entries in parameter database that are used in the target class. The name of every constant is derived from the member variable name and is constructed as PDxxx where "xxx" is member variable name in upper case. For example constant PD_WIDTH is the parameter identifier of the member variable _width.

Refers to global pointcut: unit targetClassDeclaration (PointcutLibrary)

add addIncludesToDeclaration (source)

Triplet: unit add include

Add the #include preprocessor instructions. Declaration of class TD_DatabaseId is needed in order to define parameter identifiers, this data type is defined in header file GeneralInclude/BasicTypes.h. The pointer to parameter database has to be defined in the class definition. Therefore the header file Data/DC_BasicDatabase.h has to be included as well.

Refers to global pointcut: unit targetClassDeclaration (PointcutLibrary)

add addDatabaseReference (source)

Triplet: class add declaration

Add declaration of pointer to parameter database to target class. The pointer is of type DC_BasicDatabase* and is named pDB. It is declared as private.

Refers to global pointcut: class targetClass (PointcutLibrary)

begin targetFloatVarInitialization (source)

Triplet: constructor begin codeFragment

Initialize float* pointers to the parameter database by value returned by the method pDB->getParameterPointerFloat(PDxxx) where "xxx" is member variable name in upper case. Note that the parameter of the method represents the parameter identifier used to uniquely identify the parameters stored in the parameter database.

For example member variable _flt is initialized to value returned by the method call pDB->getParameterPointerFloat(DB_FLT) where the substring _FLT is automatically generated from the variable name.

It is important to initialize all pointers to the parameter database defined in the target class. This advice initializes all pointers of type float*. All float* pointers are accessed using two construtcs of the XSL language: xsl:for-each and xsl:value-of. Variable filename defined in the code modifier contains the name of the current unit (without extension). The filename is later used to define the path to the file where the target class is defined. The set of all float member variable names defined in the target class can be then obtained using (relatively complicated) XPath expression with doc() function of XSL language: doc($path)//src:class[src:name=$filename]//src:decl_stmt/src:decl[src:type/src:name='float']/src:name.

Local Pointcut: constructor (source)

begin targetIntVarInitialization (source)

Triplet: constructor begin codeFragment

Initialize int* pointers to the parameter database by value returned by the method pDB->getParameterPointerInt(PDxxx) where "xxx" is member variable name in upper case. Note that the parameter of the method represents the parameter identifier used to uniquely identify the parameters stored in the parameter database.

For example member variable _width is initialized to value returned by the method call pDB->getParameterPointerInt(DB_WIDTH) where the substring _WIDTH is automatically generated from the variable name.

It is important to initialize all pointers to the parameter database defined in the target class. This advice initializes all pointers of type int*. All int* pointers are accessed using two construtcs of the XSL language: xsl:for-each and xsl:value-of. Variable filename defined in the code modifier contains the name of the current unit (without extension). The filename is later used to define the path to the file where the target class is defined. The set of all integer member variable names defined in the target class can be then obtained using (relatively complicated) XPath expression with doc() function of XSL language: doc($path)//src:class[src:name=$filename]//src:decl_stmt/src:decl[src:type/src:name='int']/src:name.

Local Pointcut: constructor (source)

begin addDatabaseInicialization (source)

Triplet: constructor begin codeFragment

Add code fragment that initialize the parameter database. The database has to be initialized before it is first used. The initialization code is discussed in documentation of the TestCaseBasicDatabase_1 class (a part of the OBS Framework). Purpose of the initialization is to:
  1. initialize the data structure to simulate the default table
  2. initialize the data structure to simulate the operational table
  3. instantiate the basic database object (pDB)
  4. set the parameter database length
  5. set the default and operational tables of the parameter database
  6. reset the database

Local Pointcut: constructor (source)

replace replaceParametersByPointers (source)

Triplet: name replace codeFragment

Replace occurences of member variables with the dereferences of pointers to the parameter database. Each member variable is replaced by the code (*_pXXX) where XXX stands for the name of the variable being replaced. For example member variable _width is replaced with (*_p_width).

Refers to global pointcut: name targetParameterUsage

replace replaceParameterDeclarationsByPointers (source)

Triplet: name replace codeFragment

Replace declarations of member variables with the declarations of pointers to the parameter database. Each member variable declaration is replaced by the code *_pXXX where XXX stands for the name of the variable being replaced. For example the declaration of member variable _width is replaced with the declaration of *_p_width.

Refers to global pointcut: name targetParameterDeclaration