Book a Demo

Author Topic: Problems generating C++ code  (Read 2782 times)

AndreasWachowski

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Problems generating C++ code
« on: May 24, 2004, 09:30:19 am »
Hi all,

I am working with build 726, trying to adapt the C++ code generation templates, and hit some problems. Hope someone can help me out. Specifically:

I declared an interface with a const operation returning, say, an int. Furthermore, the operation has a fixed inout parameter of type T. In the generated code, I expected something like

virtual int initialize(const T& t) const =0;

As far as I understand, this would correspond to the documented behaviour. Alas, the method generated instead is

virtual const int initialize(const T t) =0;


[*]In order to make the operation (instead of the return value) constant, I modified the templates OperationDeclaration and OperationDeclarationImpl:

%opStatic=="T" ? "static" : ""%
%opConst=="T" ? "const" : ""%
%opReturnType%

[...]

%if opIsQuery=="T" or opStereotype=="const" or opConst=="T"%
const
%endIf%


[*] In order to get the reference, I added logic to the templates Parameter and ParameterImpl, as follows:

%if paramType != "void"%
%if paramKind == "inout" or paramKind == "out"%
&
%endIf%

%paramName%
%endIf%
[/list]

This generates

virtual int initialize(const T &t) const =0;

which is fine.

However, on subsequent generations (using method "Synchronize Model and Code"), the method is appended to the source an additional time, yielding several identical declarations. This seems to happen as soon as I alter the Parameter templates. The error does not occur when only modifying the Operation templates, or when leaving the Parameter templates untouched.

I am stuck and would appreciate if someone can give me a hint.

Many thanks,
Andreas

AndreasWachowski

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Problems generating C++ code
« Reply #1 on: May 24, 2004, 10:05:37 am »
Just installed build 727, and the one issue with the reference is solved: Without modifying the Parameter templates, the inout parameter type is translated into an ampersand.

This update came just in time.   :D

However, a question remains: To specify a const method, it looks the workaround is to specify it as "isQuery". It strikes me as odd that there should be a direct relationship between a database query and a const method. Or am I missing something?

AndreasWachowski

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Problems generating C++ code
« Reply #2 on: May 25, 2004, 12:12:25 pm »
> However, a question remains: To specify a const method, it looks the workaround is to specify it as "isQuery". It strikes me as odd that there should be a direct relationship between a database query and a const method. Or am I missing something?

Ok ok, sigh. I finally understood the meaning of "isQuery" - the object is queried - and hence not modified, which implies (or should imply) a const method ...  :D