[aspectc-user] reset tjp->that()?

Michael Gong mwgong at cs.utoronto.ca
Sat Dec 9 19:24:08 CET 2006


Hi, Daniel & Yan,

It brings an interesting question.

The template works fine for this case.

> I am afraid what you are trying to achieve is not possible.
> // Template, works for any class that offers a Release() method
> template< class T > void Release( T*& _this ) {
> _this->Release(); // destroy
> _this = 0; // invalidate
> }
>

But how about I want to do the "invalidation" for method "Release2" , 
"Release3", or etc ? Using template, you might have :

template< class T > void Release2( T*& _this ) {
 _this->Release2(); // destroy
 _this = 0; // invalidate
 }

template< class T > void Release3( T*& _this ) {
 _this->Release3(); // destroy
 _this = 0; // invalidate
 }

...


Looks familiar ? :-)

It is typical crosscutting concern, I think.

Since AOP is targeted to modularize crosscutting concern, can it be used 
for this case ? More specifically, can AspectC++ capture it ?

Regards,

Mike



----- Original Message ----- 
From: "Yan Mao" <maoyan at gmx.net>
To: "Daniel Lohmann" <daniel.lohmann at informatik.uni-erlangen.de>
Cc: <aspectc-user at aspectc.org>
Sent: Saturday, December 09, 2006 11:18 AM
Subject: Re: Re: [aspectc-user] reset tjp->that()?


Hello Daniel,

thank for the explation, it's very helpful.

regards,

Yan Mao



-------- Original-Nachricht --------
Datum:  Fri, 08 Dec 2006 17:06:02 +0100
Von: Daniel Lohmann <daniel.lohmann at informatik.uni-erlangen.de>
An: aspectc-user at aspectc.org
Betreff:  Re: [aspectc-user] reset tjp->that()?

> Hi Yan,
>
> I am afraid what you are trying to achieve is not possible.
>
> > //the C++ code
> > ClassA *p = new ClassA();
> > p->DoSomething();
> > p->Release();
> > //now i want to set p=NULL with AOP
>
> In C++ the object instance pointer (this) is always passed by-value.
> Technically, it is passed as a "hidden" first parameter:
>
> class A {
>    void Release();
> };
>
> becomes (technically) something such as
>
> void ClassA::Release( ClassA* this ) {
> // this is by-value parameter
> }
>
> The object reference inside some method (this) is a copy of the 
> original
> parameter. The same holds for the value returned by tjp->that()   in
> advice code, it is another value copy of the originally passed 
> instance
> pointer. It is not possible to affect the "original" from advice code.
>
> Side node:
> The common C++ idiom to invalidate the reference when destroying an
> instance is to use a non-member function:
>
> // Template, works for any class that offers a Release() method
> template< class T > void Release( T*& _this ) {
> _this->Release(); // destroy
> _this = 0; // invalidate
> }
>
> //the C++ code
> ClassA *p = new ClassA();
> p->DoSomething();
> Release(p);
> // now p == 0
>
>
> Daniel

-- 
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: 
www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's 
Cup-Yacht!
_______________________________________________
aspectc-user mailing list
aspectc-user at aspectc.org
http://www.aspectc.org/mailman/listinfo/aspectc-user




More information about the aspectc-user mailing list