[aspectc-user] Bidirectional Relationships

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Wed Mar 30 17:03:05 CEST 2005


Bob,

by affecting a.h and b.h with your aspects you indirectly make a.h 
include b.h and vice versa. The reason is that whenever an aspect 
affects a join point in a certain file, the corresponding aspect header 
file will be included. Therefore, a.h includes addb2a.ah includes b.h 
includes adda2b.ah includes a.h ...

You can avoid the parsing problems by adding forward declarations of the 
classes A and B in front of the #include directive in your aspect header 
files.

-Olaf

Bob Ollerton wrote:
> 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 ----------------
> 
> _______________________________________________
> 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