Book a Demo

Author Topic: Customize the code generation template  (Read 3796 times)

pfsarli

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Customize the code generation template
« on: July 31, 2008, 06:45:09 am »
I wish to customize the code generation template in the following manner:
1. I am generating C++ code.
2. I need to modify the #include "classname.h" construct to look like this: #include "packagename/classname.h"

I spent several hours today struggling to achieve this result. I did a lot of experimenting with the code generation templates. My guess is that if I could edit the %fileImports% template I would succeed. I need some help on this because I found no way to do this.
Thanks in advance !

Paulo

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Customize the code generation template
« Reply #1 on: July 31, 2008, 08:32:01 am »
You can't directly edit the %fileImports% macro, but you could replace it with a list over "Import" objects.  I think the PHP templates have an example of this that would be useful for you.

pfsarli

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Customize the code generation template
« Reply #2 on: August 08, 2008, 04:00:19 am »
Hi Simon:

Thank you for the tip. I did try it out but unfortunately it didn´t work at all. I really do need a way change the way EA generates include path information in my C++ source code. Where could I go from here?

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Customize the code generation template
« Reply #3 on: August 08, 2008, 10:28:00 am »
You can do it by doing what I said, I have done it before.

Import template
Code: [Select]
$file = %importRelativeFilePath%
%if $file == ""%
$file = %importClassName ? value% + %genOptCPPHeaderExtension%
%endIf%
%if $file == "" or importInFile=="T" or $file==fileName%
%endTemplate%

#include %qt%$file%qt%

Import Section template
Code: [Select]
$imports = %classImports% + "\n"
$imports += %list="Import" @separator="\n" importFromAggregation=="T" or importFromAssociation=="T" or importFromAtt=="T" or importFromDependency=="T" or importFromGeneralization=="T" or importFromMeth=="T" or importFromParam=="T" or importFromRealization=="T"%
%REMOVE_DUPLICATES($imports, "\n")%

Is there anything wrong with that?

pfsarli

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Customize the code generation template
« Reply #4 on: August 09, 2008, 06:20:30 am »
Hi Simon,

I did manage to advance a good distance with your help. Once again, thanks a lot.

What I am trying to do right now is to perform a simple substitution; in the generated source path I wish to substitute all occurrences of the \ char with a / char because I am generating source code to be compiled  on a LINUX environment.
I tried to use the %REPLACE( ... )% template but to no avail...
Below is the code that I have been struggling with:


$file = %importRelativeFilePath%
%if $file == ""%
$file = %importClassName ? value% + %genOptCPPHeaderExtension%
%endIf%
%if $file == "" or importInFile=="T" or $file==fileName%
%endTemplate%

$output = %qt% + %REPLACE( $file, "\\", "/" )% + %qt%

#include $output


For some unknown reason (at least to me, sorry) this simply doesn´t work. What now?

Paulo