<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="AddAllGetterMethods">
        
<description>Sample aspect program to add getter methods for all member variables of
            a given class. The getter methods offers
                observability over an internal variable of a target class. 
        
<p /> This aspect is implemented through two advices. The first advice modifies the
                comment of the target class to include a statement that the class has been modified by an aspect
                weaver. The second advice adds set of inline method definitions (inclusive of their comment).
                
<p /> The name of the target class is
                
<code>Derived</code>. The variables over which observability is given by the aspect program are 
                assumed to be defined in the target class itself (as opposed to one of its superclasses).
                
<author>A. Pasetti, O. Rohlik</author>
        
</description>
        
        
<pointcut name="targetClass" type="src:class" constraint="src:name='Derived'">
                
<description>Points to the target class to which the getter method should be added.</description>
        
</pointcut>
        
        
<pointcut name="targetClassComment" type="src:comment">
                
<description>Points to the comment of the target class where the getter method should be added.
                        that must be modified. The comment that must be modified is the comment that is followed by
                        the 
<code>targetClass</code> pointcut. </description>
                
<restriction type="followedBy">
                        
<pointcutRef type="src:class" ref="targetClass" />
                
</restriction>
        
</pointcut>
        
        
<advice name="addClassComment" type="end">
                
<description>Add a comment at the end of the comment of the target class. The comment thus
                        inserted states that the class was modified by an aspect program and describes the nature of
                        the modification.
</description>
                
<pointcutRef ref="targetClassComment" type="src:comment" />
                
<codeModifier type="comment">
                        
<text>
The implementation of this class has been modified by an aspect program.
The aspect program adds a getter methods for all member variables defined 
in this class.
</text>
                
</codeModifier>
        
</advice>
        
        
<advice type="add" name="addMethodDeclaration">
                
<description>Add the inline getter methods. Note that the code modifier must include
                        a public 
<code>accessModifier</code> subelement to specify the access protection level of 
                        new methods. 
                        
<p />
                        The member variable names are obtained using two constructs of XSL language: 
<code>xsl:for-each</code>
                        and 
<code>xsl:value-of</code>. Member variables are located by
                        
<code>xsl:for-each</code> instruction 
                        and transformed to string using 
<code>xsl:value-of</code> instruction.
                        
</description>
                
<pointcutRef ref="targetClass" type="src:class" />
                
<codeModifier type="declaration">
                        
<accessModifier type="public" />
                    
<xsl><xsl:for-each select="src:block/*[self::src:protected or self::src:private or self::src:public]/src:decl_stmt/src:decl/src:name">/**
 * Getter method for the 
<xsl:value-of select="." /> member variable.
 * This inline function was automatically generated by an aspect program.
 */
inline 
<xsl:value-of select="../src:type/src:name" /> get<xsl:value-of select="." />() const { return <xsl:value-of select="." />; }
</xsl:for-each></xsl>
                
</codeModifier>
        
</advice>
        
</aspect>






































v