Book a Demo

Author Topic: Help with code generation with template, thx!  (Read 3710 times)

rogeryin

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Help with code generation with template, thx!
« on: May 15, 2006, 09:50:08 am »
Hi all.
Ive searched the whole site but didn't find any useful information regarding this matter.

I am using EA corp edition (c++) and one of the requirements was to have different comments on class methods. That is, they want to see brief comments in the .H file but detailed comments in the .cpp file. I noticed EA template supports IF-ELSE flow control, can this be used to realize this?

Thanks for your helpful hints in advance.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Help with code generation with template, thx!
« Reply #1 on: May 15, 2006, 03:55:15 pm »
You can do it without needing extra if-else constructs.

First you'll need to decide what field you want to use for the second notes.  (I'll use the Behaviour field for the implementation note)

Then make sure that your C++ options specify that C++ method notes should be generated to both.

Now edit the Operation Notes Impl template so that it uses the opBehaviour field.

Code: [Select]
%if genOptGenComments != "T" or genOptCPPGenMethodNotesInBody != "T"%
%endTemplate%

%WRAP_LINES(opBehaviour, genOptWrapComment, "// ")%

That should get you on track.

rogeryin

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Help with code generation with template, thx!
« Reply #2 on: May 16, 2006, 11:18:18 am »
Thanks for your reply Simon.
However, this solution seems that any changes I do to the comments corresponding to behaviour field will not be Synchronized. Is there anyway that I can also synchronize it?

Thank you!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Help with code generation with template, thx!
« Reply #3 on: May 16, 2006, 03:36:39 pm »
It is for me, although I tripped over not having 'Method Notes in Implementation' set to true like I advised you.

I'd recommend double checking your options and also if you copy and pasted the template code out of my previous post make sure it hasn't added spaces on the end of each line.

rogeryin

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Help with code generation with template, thx!
« Reply #4 on: May 16, 2006, 06:07:01 pm »
Sorry for any confusion, but it seems that I didn't express myself clear enough.

The code you gave me makes sense and works perfectly.

However, I realized that behavior field will not be considerred when code synchronization is carried out. (according to the user guide, only note field is coverred).

Based on this, I came up with an idea. for the brief comments I needed in header files, I modified template operation notes to this :

Code: [Select]

%if genOptGenComments != "T" or genOptCPPGenMethodNotesInBody != "T"%
%endTemplate%

$comment = %CSTYLE_COMMENT()%
%LEFT($comment,80)%


My idea is, I will make the first 80 characters in the notes field to be a brief comment, then extrat only those 80 characters into the header file. But it didn't produce anything with this code. I tried %LEFT($comment,"80")% and it's still the same. Please tell me where did I do wrong. Thanks.


Thank you
« Last Edit: May 17, 2006, 09:57:54 am by rogeryin »

rogeryin

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Help with code generation with template, thx!
« Reply #5 on: May 17, 2006, 10:15:15 am »
I found another way of doing this and it works
Code: [Select]
%if genOptGenComments != "T" or genOptCPPGenMethodNotesInBody != "T"%
%endTemplate%

%PI=""%
%LEFT(opNotes,"80")%


and I guess this is what meant to be for taking out notes.

My other question is, is there anyway we can detect the end of line (\n character) when reading in comments?
In another way, can we just read in the first line of the note field?
« Last Edit: May 17, 2006, 10:15:47 am by rogeryin »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Help with code generation with template, thx!
« Reply #6 on: May 17, 2006, 03:31:56 pm »
You can find the first newline by using find.

Code: [Select]
$pos=%FIND(opNotes,"\n")%
%if $pos != "-1"%
$comment=%LEFT(opNotes,$pos)%
%else%
$comment=%opNotes%
%endIf%

However, I'm somewhat concerned about your stated reasons for not using the behaviour field.

Forward synchronisation calls the Operation Notes and Operation Notes Impl templates.  (And this is how I read the documentation)  Therefore regardless of whether you split the notes field, use the behaviour field, get it out of a tagged value or use an addin to calculate what each note should be it should work.

On the reverse engineering (and synchronisation) only the notes field will be set, and it will only be set to the note found before the declaration.  (Actually this depends on the options for where method notes should go).

So the synchronisation (with reverse engineering being the only problem) won't work any better for your solution, in fact it will actually be worse because you'll lose part of your documentation instead of not having it updated.