[aspectc-user] Aspect templating

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Tue May 3 11:41:04 CEST 2005


Hello Miguel,

Miguel Almeida wrote:

> Hi.
>
> I’d like to know if there’s a way to decide which classes will work 
> with an aspect non-explicitly…
>
> Like some kind of aspect templating:
>
> Ex:
>
> template <typename T>
>
> aspect Xpto {
>
> pointcut test( ) = “% T::some_method( )”;
>
> };
>
> I would like to decide which classes are going to be affected by the 
> aspect but not explicitly in the aspect…
>
> Is there any way to do something like this?
>
> Thank you
>
> Miguel Almeida
>
Template aspects are a nice idea. However, aspects are instantiated 
implicitly by default and therefore the programmer doesn't have a chance 
to pass the template parameter.

The AspectC++ mechanism to postpone the decision which joinpoints should 
be affected by an aspect is based on aspect inheritance and pure virtual 
pointcuts:

// this aspect defines WHAT shall be done
aspect XptoWHAT {
pointcut virtual my_target_classes () = 0;
advice within(my_target_classes()) && execution("% ...::some_method()") 
: ...
};

// a derived aspect defines WHERE it should be done
aspect XptoWHERE : public XptoWHAT {
pointcut my_target_classes() = "T";
};

With this solution you can not achieve everything that would be possible 
with your aspect template idea, but separating WHAT and WHERE works 
quite well. Although it wouldn't be very difficult to allow aspect 
templates, we don't support it yet, in order to avoid redundant mechanisms.

-Olaf




More information about the aspectc-user mailing list