Book a Demo

Author Topic: c++ code generation - include file statements  (Read 7491 times)

OilyRag

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
c++ code generation - include file statements
« on: July 30, 2007, 03:04:01 pm »
Hi,

I am using the 30-day trial version of EA, and I set up an experiment with 2 c++ header files, class1.h and class2.h if you like. In class1, I added an operation that takes a reference parameter of type class2. I added an include statement in class1.h to include class2.h (this is just one way of keeping the compiler happy, a forward declaration of class2 in the class1.h file may also have been ok).

I then imported the source directory into a class model within my EA test project. Sure enough, it created the two classes, but the class diagram did not show any relationship between the two classes. Furthermore, when I generated new source from the model, the generated class1.h file failed to include the class2.h file.

I have tried everything obvious to establish that relationship diagrammaticaly in order to get the generated source code correct, but have failed. Nothing works.

The only thing I did find that worked, was to manually type in the include statement into the "Generate Code" dialog box that comes up when you select class1 on the class diagram and hit F11 (or select it from the context sensitive menu after a right mouse button click).

Surely, EA should know that class1 has a dependency upon class2? It is there in the parameters of an operation in class1. How can EA miss it? Why do I have to manually ensure that the generated source for class1 is correct? This problem has got quite a few other people in my office scratching their heads.

Any help would be appreciated. Thanks in advance.
The things I make may be for others, but how I make them is for me.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: c++ code generation - include file statements
« Reply #1 on: July 30, 2007, 03:58:40 pm »
Try enabling Tools | Options | Source Code Engineering | Create dependencies for operation returns and parameter types.

This should create the relevant dependency.  However, even with that there I don't think the default code templates for C++ create #includes for depencencies anyway.  However, they can be changed to do this.  As an example see http://wiki.eausergroup.org/index.php?title=CPP_Forward_Declarations_Templates where I've shown how to generate forward declarations.  (With some limitations)

OilyRag

  • EA User
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Re: c++ code generation - include file statements
« Reply #2 on: July 30, 2007, 06:18:56 pm »
Thanks for the reply simonm.

Dont take this the wrong way - I am just curious,....why doesn't EA work correctly (subject to opinion ofcoarse) in this regard straight out of the box? Is this intentional? Was what I was trying to do in my experiment so strange or unusual that sparxsystems felt they need not support it as standard behaviour? Or do all purchasers of EA have to accept that they must embark on a process of tailoring/customization of the tool to achieve the outcomes they want?
The things I make may be for others, but how I make them is for me.

SF_lt

  • EA User
  • **
  • Posts: 216
  • Karma: +1/-0
  • The Truth Is Out There
    • View Profile
Re: c++ code generation - include file statements
« Reply #3 on: July 30, 2007, 11:17:06 pm »
beware, that dependency stuff isn't strict UML - there is no way from the plain dependency (without stereotypes) know, how it should be treated - is it for method parameter or method attribute. However in either cases include is needed ;)
registertm everything to SparX

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: c++ code generation - include file statements
« Reply #4 on: July 31, 2007, 05:06:43 pm »
It doesn't work the way you want out of the box because there are a lot of users out there who want different (read contradictory) things out of EA.  We try to make our defaults the best for as many people as possible, but whenever there are options there are people who will want it another way.  (That includes generating includes from dependencies or not.)

sl@sh

  • EA User
  • **
  • Posts: 85
  • Karma: +0/-0
    • View Profile
Re: c++ code generation - include file statements
« Reply #5 on: August 06, 2007, 07:21:33 am »
I've worked with EA for a couple of months now and I found that the process of first writing code (or taking some already existing files), importing them into EA, and then generating new code out of the resulting class diagram virtually always misses something important. (actually, most of the time a *lot* of things - until I find the obscurely hidden options to somewhat improve my results)

Apparently C++ is to blame, since it has a lot of hooks and requirements that are not really based on the purpose it serves (i. e. writing object oriented code), but on it's procedural programming language legacy. Most of the newer languages EA supports are not weighed down by such a legacy and thus the default settings often behave ... curiously ... in the eyes of a C++ programmer.

EA is an UML tool, so everything in your model *needs* to be an object of some kind. So, when importing existing (as in: not generated) C++ code the model is bound to misrepresent some of the less object oriented aspects of your code. (such as 'using' statements, as I have learned recently)

Still, EA claims to "support" C++, so if you experience problems like this, be sure to report it. Sometimes changing a setting might help. And sometimes you'll find a bug.