[aspectc-user] Bidirectional Relationships

Bob Ollerton spam_dumpster2 at cox.net
Thu Mar 24 23:33:07 CET 2005


I am trying to use aspectC++ to develop an approach to increase source code
portability of simulation model components between simulators.  To achiever
this, I have be able to establish bidirectional relationships between
component models and software architecture elements from different
simulators.  I would like to do this in aspects but I haven't succeeded yet.
I've condensed the problem into a C++ example that works but is non-protable
and an aspectC++ that does not work, but would be portable if it did.

I can think of a way to do it in aspectC++ if I use typecasts and extra
classes, but it would be more cumbersome. Any suggestions?

- Bob

---------------- BEGIN C++ Version ----------------
// a.h
#ifndef __A_H__
#define __A_H__
class B;
class A {
public:
    A (void);
    ~A (void);
    B * other;
};
#endif // __A_H__

// a.h
#ifndef __B_H__
#define __B_H__
class A;
class B {
public:
    B (void);
    ~B (void);
    A *other;
};
#endif // __B_H__

// a.cpp
#include "a.h"
A::A(void) { }
A::~A(void) { }

// b.cpp
#include "b.h"
B::B(void) { }
B::~B(void) { }

// cppbd0.cpp
#include "a.h"
#include "b.h"
int main(int argc, char *argv [])
{
    B * b = new B ();
    A * a = new A ();
    b->other = a;
    a->other = b;
}

---------------- END C++ Version ----------------


I can compile the AspectC++ version with either addb2a.ah or adda2b.ah, but
not both. If I try to compile with both addb2a.ah and adda2b.ah I get the
following error message: [addb2a.ah(6): error: invalid member declaration
near token `*'].  However, the error will refer to "adda2b.ah" vice
"addb2a.ah" if I reverse the order of the files in the compilation list.

---------------- BEGIN aspectC++ Version ----------------

// a.h
#ifndef __A_H__
#define __A_H__
class A {
public:
    A (void);
    ~A (void);
};
#endif // __A_H__

// b.h
#ifndef __B_H__
#define __B_H__
class B {
public:
    B (void);
    ~B (void);
};
#endif // __B_H__

// a.cpp
#include "a.h"
A::A(void) { }
A::~A(void) { }

// b.cpp
#include "b.h"
B::B(void) { }
B::~B(void) { }

// addb2a.ah
#ifndef __ADDB2A_AH__
#define __ADDB2A_AH__
#include "b.h"
aspect AddA2B {
public:
	advice "A" : B *other;
};
#endif // __ADDB2A_AH__

// adda2b.ah
#ifndef __ADDA2B_AH__
#define __ADDA2B_AH__
#include "a.h"
aspect AddB2A {
public:
	advice "B" : A *other;
};
#endif // __ADDA2B_AH__

---------------- END aspectC++ Version ----------------




More information about the aspectc-user mailing list