[aspectc-user] Some questions
Olaf Spinczyk
os at aspectc.org
Tue Jun 2 11:43:04 CEST 2009
Hi David,
David Come wrote:
> Hi all.
> I'm discovering Aspect C++ and I have a some questions.
> 1/ How to have poincuts in function of others pointcuts ?
> Exemple:
> aspect A
> {
> pointcut virtual who() =0;
> pointcut what()= "% who()::set%(...)";
> };
> aspect B : public A
> {
> pointcut who() = "Z"; //what() <=> "% Z::set%(...)"
> };
> Iv' tried "%"## who() ## "set%(...)", it compiles but it catches all things.
>
This can be done in a different way: AspectC++ allows you to use boolean
operators on pointcuts, i.e. "&&", "||", and "!". With the "&&" operator
you can calculate the intersection of two pointcuts. For example:
aspect A {
pointcut virtual who() = 0;
pointcut what() = within(who()) && execution("% ...::set%(...)");
advice what() : before () { cout << "setter function about to be
executed" << endl; }
};
> 2/ How to use tjp->that() ?
> I've tried something like this
> aspectC
> {
> pointcut who() ="What_you_want";
> advice execution(who()): around ()
> {
> tjp->that(); // it's a void*, how to use it without a ugly cast ? Does there
> are some kind of templates to avoid cast ?
> }
> };
>
No, the type of tjp->that() is *not* "void*". It should be a
"What_you_want*". If who() is "X%" and if there are two classes "X1" and
"X2" matched by the advice, then tjp->that() will be of the type "X1*"
for the first and "X2*" for the second class. If you want to use the
type of the object that is referenced by tjp->that(), use
JoinPoint::That from the join point API. This allows you to handle all
the matched join points in a generic way ("generic advice").
> 3/ I've not understood cflow. What it means ? How to use it ?
> Thanks.
> David Côme.
cflow lets you implement conditional join points. To understand it you
have to imagine the dynamic call graph. For example, main() calls foo(),
and foo1() calls bar(). After the control returns to main(), it calls
foo2(), which also calls bar(). With cflow you can, for instance,
declare advice for the execution of bar() that is only triggered if the
control flow came from foo1() (and not from foo2()):
advice execution("void bar()") && cflow(execution("void foo1") :
before() { ... }
Hope this helps.
Best regards,
Olaf
More information about the aspectc-user
mailing list