Book a Demo

Author Topic: C code include statements  (Read 5408 times)

tonyb

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
C code include statements
« on: January 28, 2016, 04:14:54 am »
I have yet another question about EA. When I create a dependency between two classes in the model, why aren't any #include statements generated in the .c files?

The only way I can get #include statements is to use an association instead of a dependency. However, I don't want the m_* member variable. (I could generate classes individually and place include statements in the code engineering dialog Headers field, but this isn't feasible for an entire project).

Regards

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: C code include statements
« Reply #1 on: January 28, 2016, 05:03:31 pm »
Hi,

usually a dependency is some kind of dependency which may or may not result in a C #include. EA couldn't know what you mean. An association means in essence that there is a pointer (real time relationship). Therefore it makes sense to generate an C #include for an Association and not for a Dependency.

Beside all. You can influence the generated C Code by means of
  • Code Template Framework
  • Defining your own grammar

Keep in mind:
- With Code Template Framework you may generate almost everything. But you are not able to influence Reverse Engineering from code. Not exactly Round Trip.
- Defining a new grammar is a lot of work.

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C code include statements
« Reply #2 on: January 29, 2016, 08:40:07 am »
By default C++ doesn't use dependencies.

The macro used in the import section in the default template does so without providing any user configuration. However, if you check how the PHP templates work ('Import Section' and 'Import') you can customize the #include generations based on the type of references found (including dependencies).

tonyb

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: C code include statements
« Reply #3 on: February 05, 2016, 04:52:26 am »
It looks like 'Import Section Impl' will work for what I want to do.

My next question is what is the macro to get the dependency information. If I open the class properties the following tree appears on the left side of the dialog. I think the 'Links' page has the information I need. What are the macro names corresponding to the fields on the 'Links' page? The fields I see are: Element, Element Stereotype, Type, Connection, and Stereotype.


+--- Properties
|    |
|    +--- General
|    |
|    +--- Templates
|
+--- Rules
|    |
|    +--- Requirements
|    |
|    +--- Constraints
|    |
|    +--- Scenarios
|
+--- Related
     |
     +--- Files
     |
     +--- Links


Regards

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C code include statements
« Reply #4 on: February 05, 2016, 08:22:41 am »
Code: [Select]
$imports = %classHeaders% + "\n"
$imports += %list="Import" @separator="\n" importFromMeth=="T" or importFromParam=="T" or importFromDependency=="T"%
%REMOVE_DUPLICATES($imports, "\n")%

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

#include %qt%$file%qt%

tonyb

  • EA Novice
  • *
  • Posts: 7
  • Karma: +0/-0
    • View Profile
Re: C code include statements
« Reply #5 on: February 05, 2016, 09:03:40 am »
Thanks Simon. Unfortunately I'm unable to get these working either.

Code 1
I like this method and have been trying something similar all afternoon, but the importFromDependency flag does not return "T" even if I have a dependency drawn on the class diagram. Is there something I have to do in addition to drawing the dependency on a diagram?

Code 2
The genOptCPPSourceExtension is always '.c', the other macros are empty. Therefore the conditions are always false and the %endTemplate% is not executed. I end up with

#include ".c"


Regards