Book a Demo

Author Topic: C++ Code Template help  (Read 3385 times)

redklyde

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
C++ Code Template help
« on: April 01, 2009, 09:37:22 am »
Hello all.  I just downloaded EA for a 30-day trial ... so I don't have an immense time to experiment or I would do more.  I have a question regarding custom code generation templates.

I have a massive native C++ project, and we use many class creation macros.  Obviously the reverse engineering process doesn't recognize these macros automatically.  So, I'm trying to add some new class declaration macros to help the process along, and I'm pretty confused as to what I'm actually trying to output in these templates.

For example.  In my C++ I have something simple like this:

#define DEFINE_ABSTRACT_CLASS(className, baseClassName) \
class className : public baseClassName

class CBaseClass {
};

DEFINE_ABSTRACT_CLASS(CChildClass, CBaseClass) {
};

I assume I need to edit the Class Declaration template and add my macro definitions to the template such that when the DEFINE_... line is parsed I will translate that line into an output that EA knows how to handle.  However, I'm not certain at all how to access the information I need nor how to format the appropriate output.

Anyone have any help or links?  I'm looking, just not finding exactly what I'm expecting.

Thanks,
redKlyde
« Last Edit: April 01, 2009, 09:37:55 am by redklyde »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: C++ Code Template help
« Reply #1 on: April 02, 2009, 05:51:09 am »
Hi there!


Let me welcome you to EA, first off. You won't be disappointed, in fact in a few weeks I predict you'll go running to your boss going hey look at what we can get for the cost of one engineering hour.

Secondly, I'm not sure what it is you are trying to achieve here. I thought I did, but then you got to that preprocessor macro and I kinda went huh?

It looks as if you're after changing the reverse-engineering behaviour by changing the code generation templates. If so, that won't work.

The EA code generation templates are forward only. You cannot script the reverse-engineering process (not that I haven't asked for it, but it didn't get a heap of votes). You could write your own using EA's API, but I wouldn't recommend that if all you've got is a month.

Basically, if what you want is a reverse-engineered UML model of some truckload of C++ code, and that code has preprocessor macros which affect the structure of the code (as in class generation rather than "#define PI 3.13" or "#define MAX(x, y) (x>y)"), then the simple way to get where you want is to run the code through the preprocessor before you import it into EA.

Hope this helps. If not, please don't hesitate to say so. We really are here to help.

Cheers,


/Uffe
My theories are always correct, just apply them to the right reality.

redklyde

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: C++ Code Template help
« Reply #2 on: April 02, 2009, 08:45:54 am »
Aah, ok.  Yes I was confused and your explanation makes a lot more sense now.

I assumed the class generation templates were for reverse engineering ... a way to get complex-defined objects into UML.  Which looking at it from that perspective ... it also makes sense why I was completely confused how to make it work :)

My example was a simple one, but it illustrated the point.  What I have is an architecture that uses a preprocessor to parse these macros and generate code for an objects editable properties, networked properties, etc.  So going beyond this (and without getting into too much proprietary stuff), there are even macro's for describing a class data member.  I would need to pretty heavily edit the reverse engineering process, or like you say use a preprocessor to expand and save out the classes.

Since I've already got a preprocessor to do some heavy lifting, this wouldn't be too bad, it's just going to be a whooooole lot of headers to duplicate.  It's unfortunate that there isn't support for this ... so you can add my vote to your meager heap ;)

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: C++ Code Template help
« Reply #3 on: April 02, 2009, 03:58:14 pm »
Contact Sparx Systems support to get this imported.  We can do this without patching EA, but it's not as simple as the code templates so we haven't exposed it to users.

A quick note on code templates being used for reverse engineering.  I don't believe it is possible.  There isn't enough information in the templates.  They specify one possible way to represent the model as code.  The code can come in, in any number of formats may not be exactly the same.  (eg. Keywords in different order.)  What you need is a grammar.  Unfortunately, the learning curve to modify a grammar the complexity of any of our code languages is significantly higher than to modify code templates.