Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: DanG83616 on July 12, 2013, 08:13:58 am

Title: Generating Non-Member Functions
Post by: DanG83616 on July 12, 2013, 08:13:58 am
Is there a way to generate non-member operations in a model transform?

for example, I want to put something into a C++ PSM that will result in the following after code gen:
Code: [Select]
std::ostream& operation<<(std::ostream& out, foo& foo);The transform engine complains to find "Operation" outside of a Class.

Thanks,
Dan
Title: Re: Generating Non-Member Functions
Post by: Eve on July 12, 2013, 08:37:03 am
The last time that I wanted to model something like this I created a class with the stereotype of "namespace member". You could do the same from a transformation template.

I then created stereotype overrides in the code templates so that the class didn't generate anything for the declaration and only generated the members in the body (no braces).
Title: Re: Generating Non-Member Functions
Post by: DanG83616 on July 12, 2013, 09:49:53 am
Just about there... how did you suppress the using statement in the impl file?
Title: Re: Generating Non-Member Functions
Post by: DanG83616 on July 13, 2013, 04:32:00 am
I could not defeat EA's mission to place:
Code: [Select]
using <class>;into the impl file.

As a workaround, I made the stereotype override code template generate a forward decl into the header.
Code: [Select]
class %className%; // Just to make the compiler eat the "using" statement in the impl file w/o complaining
%list="Operation"%

I also modified the Operation Declaration Impl template like this:
Code: [Select]
%if classStereotype != "nonmembers"%
%classQualName%::
%endIf%

Thanks for the tip!

Dan