<aspect xmlns:src="http://www.sdml.info/srcML/src" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cpp="http://www.sdml.info/srcML/cpp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://control.ee.ethz.ch/XWeaver/AspectX" xsi:schemaLocation="http://control.ee.ethz.ch/XWeaver/AspectX ../../../../src/xsd/aspectX.xsd" name="SetParameter">
        
<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 
<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 two advices. They replace member 
        variables with 
<code>pDB-&gt;setParameter()</code> method call.
        This aspect program uses pointcuts defined in file 
<code>PointcutLibrary.xml</code>
        
<author>A. Pasetti, O. Rohlik</author>
        
<see>PointcutLibrary</see>
        
<see>BaseParameter</see>
        
<see>GetParameter</see>
        
</description>
        
        
<include href="PointcutLibrary.ax" />

        
<pointcut name="targetIntExprSetter" type="src:expr" />         
        
<pointcut name="targetFloatExprSetter" type="src:expr" />         

        
<advice type="replace" name="targetIntExprSetter">
            
<description>
                Replace 
<i>integer</i> member variable with the <code>pDB-&gt;setParameter()</code> method call.
                Only those member variable occurrences are replaced where the value of the variable 
<i>is</i> 
                changed. Other cases, where the value 
<i>is not</i> changed, are covered by advice 
                
<code>targetIntNameGetter</code>.
                
<p />
                For example consider the assignment to member variable 
<code>_width</code>. The expression 
                
<code>_width = 2 * iRadius</code> is replaced by
                
<code>pDB-&gt;setParameter(PD_WIDTH, 2 * iRadius);</code>. The substring
                
<code>_WIDTH</code> is automatically generated from the 
                variable name. The second parameter (i.e. 
<code>2 * iRadius</code>)
                is extracted from 
<code>expr</code> srcML element as substring after the <i>equal sign</i>
                (
<code>=</code>).
                
<p />
                This advice assumes that assignments are not used in conditions 
                (e.g. 
<code>if (foo = 1) foo = 0;</code>) since the
            
<code>setParameter()</code> method does not have any return value.
        
</description> 
                
<pointcutRef ref="targetIntExprSetter" aspect="PointcutLibrary" type="src:expr" />
                
<codeModifier type="codeFragment">
                    
<xsl>pDB-&gt;setParameter(PD<xsl:value-of select="upper-case(current()/src:name[1])" />,<xsl:value-of select="substring-after(current(),'=')" />)</xsl>
                
</codeModifier>
        
</advice>
        
<advice type="replace" name="targetFloatExprSetter">
            
<description>
                Replace 
<i>float</i> member variable with the <code>pDB-&gt;setParameter()</code> method call.
                Only those member variable occurrences are replaced where the value of the variable 
<i>is</i> 
                changed. Other cases, where the value 
<i>is not</i> changed, are covered by advice 
                
<code>targetFloatNameGetter</code>.
                
<p />
                For example consider the assignment to member variable 
<code>_flt</code>. The expression 
                
<code>_flt = 3.14f * fRadius</code> is replaced by
                
<code>pDB-&gt;setParameter(PD_FLT, 3.14f * fRadius);</code>. The substring
                
<code>_FLT</code> is automatically generated from the 
                variable name. The second parameter (i.e. 
<code>3.14f * fRadius</code>)
                is extracted from 
<code>expr</code> srcML element as substring after the <i>equal sign</i>
                (
<code>=</code>).
                
<p />
                This advice assumes that assignments are not used in conditions 
                (e.g. 
<code>if (foo = 1.0) foo = 0.0f;</code>) since the
            
<code>setParameter()</code> method does not have any return value.
        
</description> 
                
<pointcutRef ref="targetFloatExprSetter" aspect="PointcutLibrary" type="src:expr" />
                
<codeModifier type="codeFragment">
                    
<xsl>pDB-&gt;setParameter(PD<xsl:value-of select="upper-case(current()/src:name[1])" />,<xsl:value-of select="substring-after(current(),'=')" />)</xsl>
                
</codeModifier>
        
</advice>
         
</aspect>






































v