<
aspect xmlns:cpp="
http://www.sdml.info/srcML/cpp"
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
xmlns="
http://control.ee.ethz.ch/XWeaver/AspectX"
xmlns:src="
http://www.sdml.info/srcML/src"
xsi:schemaLocation="
http://control.ee.ethz.ch/XWeaver/AspectX ../../../../src/xsd/aspectX.xsd"
name="
BaseParameter">
<
description>
Inserts code that initializes the parameter database.
One of fours sample aspect programs that modifies the component to access all its parameters from
a <
i>
parameter database</
i>
.
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 <
a href="
http://www.pnp-software.com/ObsFramework/doc/ParameterDatabase.html">
Parameter
Database Design Pattern</
a>
).
<
p />
The
<
a href="
http://www.pnp-software.com/ObsFramework/doc/doxygen/html/classDC__BasicDatabase.html">
<
code>
DC_BasicDatabase</
code></
a>
is used as a component that stores the parameter data of target class.
The <
code>
DC_BasicDatabase</
code>
class extends the abstract class
<
a href="
http://www.pnp-software.com/ObsFramework/doc/doxygen/html/classParameterDatabase.html">
<
code>
ParameterDatabase</
code></
a>
.
Both classes are defined and implemented in
<
a href="
http://www.pnp-software.com/ObsFramework/">
OBS Framework</
a>
.
<
p />
These aspect programs replace all three member variables in class <
code>
SampleClass</
code>
by respective method calls <
code>
setParameter()</
code>
and <
code>
getParameterXXX()</
code>
of class
<
code>
DC_BasicDatabase</
code>
. String <
code>
XXX</
code>
stands for data type of member variable being replaced.
In this example it is assumed that member variable names starts with underline (<
code>
_ </
code>
)
character.
For each member variable there is as <
i>
parameter identifier</
i>
woven in the base code.
Parameter identifier is a constant in the form <
code>
PDxxx</
code>
where
"xxx" is member variable name in upper case. Parameter identifiers are used
to uniquely identify the parameters stored in the parameter database.
Methods <
code>
getParameterXXX()</
code>
takes the <
i>
parameter identifiers</
i>
as their parameters.
Methods <
code>
setParameter()</
code>
have two parameters. The first one is
the <
i>
parameter identifier</
i>
, the second one is the new value of the parameter
that is to be stored in the database.
<
p />
<
i>
This aspect</
i>
contains advices that adds parameter database variable declaration
and initialization code to the base code. It also adds necessary <
code>
#include</
code>
preprocessor directives.
This aspect program uses pointcuts defined in file <
code>
PointcutLibrary.xml</
code>
.
<
author>
A. Pasetti, O. Rohlik</
author>
<
see>
PointcutLibrary</
see>
<
see>
GetParameter</
see>
<
see>
SetParameter</
see>
</
description>
<
include href="
PointcutLibrary.ax" />
<
pointcut name="
targetClassDeclaration"
type="
src:unit" />
<
pointcut name="
targetClass"
type="
src:class" />
<
advice name="
addConstants"
type="
add">
<
description>
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 <
code>
PDxxx</
code>
where "xxx" is member
variable name in upper case. For example constant <
code>
PD_WIDTH</
code>
is the parameter identifier of
the member variable <
code>
_width</
code>
.
</
description>
<
pointcutRef ref="
targetClassDeclaration"
aspect="
PointcutLibrary"
type="
src:unit" />
<
codeModifier type="
declaration">
<
text>
const TD_DatabaseId PD_WIDTH = 0; // added by aspect</
text>
<
text>
const TD_DatabaseId PD_HEIGHT = 4; // added by aspect</
text>
<
text>
const TD_DatabaseId PD_FLT = 8; // added by aspect</
text>
<
text />
</
codeModifier>
</
advice>
<
advice name="
addIncludesToDeclaration"
type="
add">
<
description>
Add the <
code>
#include</
code>
preprocessor instructions.
Declaration of class <
code>
TD_DatabaseId</
code>
is needed in order to define parameter identifiers,
this data type is defined in header file <
code>
GeneralInclude/BasicTypes.h</
code>
. The pointer to
parameter database has to be defined in the class definition. Therefore the header file
<
code>
Data/DC_BasicDatabase.h</
code>
has to be included as well.
</
description>
<
pointcutRef ref="
targetClassDeclaration"
aspect="
PointcutLibrary"
type="
src:unit" />
<
codeModifier type="
include">
<
text>
#include "Data/DC_BasicDatabase.h" // added by aspect </
text>
<
text>
#include "GeneralInclude/BasicTypes.h" // added by aspect </
text>
</
codeModifier>
</
advice>
<
advice name="
addDatabaseReference"
type="
add">
<
description>
Add declaration of pointer to parameter database to target class. The pointer is of type
<
code>
DC_BasicDatabase*</
code>
and is named <
code>
pDB</
code>
. It is declared as private.
</
description>
<
pointcutRef ref="
targetClass"
aspect="
PointcutLibrary"
type="
src:class" />
<
codeModifier type="
declaration">
<
accessModifier type="
private" />
<
text>
DC_BasicDatabase* pDB; // added by aspect</
text>
</
codeModifier>
</
advice>
<
advice name="
addDatabaseInicialization"
type="
begin">
<
description>
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
<
a href="
http://www.pnp-software.com/ObsFramework/doc/doxygen/html/classTestCaseBasicDatabase__1.html">
TestCaseBasicDatabase_1</
a>
class (a part of the <
a href="
http://www.pnp-software.com/ObsFramework/">
OBS Framework</
a>
).
Purpose of the initialization is to:
<
ol>
<
li>
initialize the data structure to simulate the default table</
li>
<
li>
initialize the data structure to simulate the operational table</
li>
<
li>
instantiate the basic database object (<
code>
pDB</
code>
)</
li>
<
li>
set the parameter database length</
li>
<
li>
set the default and operational tables of the parameter database</
li>
<
li>
reset the database</
li>
</
ol>
</
description>
<
pointcut type="
src:constructor"
constraint="
src:name='SampleClass::SampleClass'" />
<
codeModifier type="
codeFragment">
<
text>
// Initialize the parameter database (this and 14 lines below were added by aspect)</
text>
<
text>
// Data structure to simulate the default table</
text>
<
text>
double* shadowDefaultTable = new double[3];</
text>
<
text>
unsigned int* defaultTable = (unsigned int*)shadowDefaultTable;</
text>
<
text>
// Data structure to simulate the operational table</
text>
<
text>
double* shadowOperationalTable = new double[3];</
text>
<
text>
int* operationalTable = (int*)shadowOperationalTable;</
text>
<
text>
// Instantiate basic database</
text>
<
text>
pDB = new DC_BasicDatabase();</
text>
<
text>
// Set the table length</
text>
<
text>
pDB->setTableLength(12);</
text>
<
text>
// Complete configuration of the database</
text>
<
text>
pDB->setDefaultTable((char*)defaultTable);</
text>
<
text>
pDB->setOperationalTable((char*)operationalTable);</
text>
<
text>
pDB->reset();</
text>
</
codeModifier>
</
advice>
</
aspect>
v