Book a Demo

Author Topic: Generating Non-Member Functions  (Read 3255 times)

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Generating Non-Member Functions
« 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
« Last Edit: July 12, 2013, 08:15:50 am by dgeorge83616 »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8098
  • Karma: +118/-20
    • View Profile
Re: Generating Non-Member Functions
« Reply #1 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).

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: Generating Non-Member Functions
« Reply #2 on: July 12, 2013, 09:49:53 am »
Just about there... how did you suppress the using statement in the impl file?

DanG83616

  • EA User
  • **
  • Posts: 180
  • Karma: +0/-0
    • View Profile
Re: Generating Non-Member Functions
« Reply #3 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