[aspectc-user] recognizing different object of the same class

Hans VB hans.vanbroeckhoven at telenet.be
Fri Feb 4 17:55:20 CET 2005


Hello,

for my project I need to differentiate between 2 objects of a class, say 
class Collection, objects CollectionA and CollectionB.
I do this by keeping a vector in my aspect which holds the addresses of 
the Collection-objects and later comparing these addresses with the 
current address of a method call, say add().

aspect LoggingAspect {
private:
    pointcut collectionConstruction()=construction("Collection");
    pointcut collectionAdd()=execution("% Collection::add(...)");
    vector<Collection*> usedCollections;
public:
    advice collectionConstruction() : after() {
       usedCollections.push_back( tjp->that() );
    }
    advice collectionAdd() : after() {
       int i=0;
       while( tjp->that() != usedCollections[i]) { i++ };
       cout << i << "th collection performed an add" << endl;
    }
}

The biggest disadvantage of this is I can't get the names of the real 
objects (e.g. CollectionA, CollectionB, ...), I only have a number (the 
order in which the collections were constructed) to distinguish between 
them.
My question is if it is überhaupt possible to get these names now, or in 
some future version of AspectC++. Maybe I'm missing some AC++ constructs 
that would be more appropriate here ? Any ideas greatly appreciated!

Greets,
Hans




More information about the aspectc-user mailing list