Hello everyboby
I would like EA takes care of attribute initial values during C++ code generation.
For exemple, I want to set the 4 attributes of this class to 1:
class Class1 {
public:
Class1();
virtual ~Class1();
private:
static const int stat_const_att;
static int stat_att;
const int dyn_const_att;
int dyn_att;
};
So I would like EA to generate something like:
// Class1.h
class Class1 {
public:
Class1();
virtual ~Class1();
private:
static const int stat_const_att=1;
static int stat_att;
const int dyn_const_att;
int dyn_att;
};
//Class1.cpp
#include "Class1.h"
int Class1::stat_att =1;
Class1::Class1() : dyn_att(1),dyn_const_att(1){
}
I search a solution on this forum and I found this post:
I did it sir,
So u need create new template Attribute__Implement
$COMMENT = "Its script implement initialization for constructors"
%PI=" "%
%if attStatic==""%
$COMMENT = "Not static initialization"
$type=%attQualType%
$type=%REPLACE($type,".","::")%
$qualType=%packagePath% + "::" + %attType%
%PI=""%
%attContainment=="By Reference" ? "&" : ""%
%attName%( %attInitial% )
%else%
$COMMENT = "Static initialization"
%attQualType% %className%::%attName% = %attInitial%;
%endIf%
Replace Class Body Implement template to following code
$templateArgs=%list="ClassParameter" @separator=", "%
%if $templateArgs != ""%
$templateArgs="<" + $templateArgs + ">"
$templ="template" + $templateArgs
%endIf%
$consPrefix=$templ + "\n" + %classQualName% + "::"
%if classStereotype != "struct"%
%PI=" "%
%if genOptGenConstructor == "T" and genOptGenConstructorInline != "T" and classHasConstructor != "T"%
$defaults = %list="Attribute__Implement" @separator=", " attInitial !=""%
$consPrefix%className%()
%if $defaults != ""%
: $defaults
%endIf%
\n{\n\n}
%endIf%
%PI="\n\n"%
%if genOptGenDestructor == "T" and genOptGenDestructorInline != "T" and classHasDestructor != "T"%
$destructor=$consPrefix+"~"+%className%+"()\n{\n\n}"
$destructor
%endIf%
%if genOptGenCopyConstructor == "T" and genOptGenCopyConstructorInline != "T" and classHasCopyConstructor != "T"%
$consPrefix%className%( const %className%& the%className% )\n{\n\n}
%endIf%
%endIf%
%list="OperationImpl" @separator="\n\n\n"%
%list="InnerClassImpl" @separator=""%
I checked - its works
Unfortunately, it doesn't work. It generates something like:
// Class1.h
class Class1 {
public:
Class1();
virtual ~Class1();
private:
static const int stat_const_att;
static int stat_att;
const int dyn_const_att;
int dyn_att;
};
//Class1.cpp
#include "Class1.h"
Class1::Class1() : int Class1::stat_att =1;int Class1::stat_const_att =1;dyn_att(1),dyn_const_att(1){
}
I am not confortable with code template editor. Is there is somebody for correcting the (nice) work of golyshkin?
Thanks for your help.