C++ Code Generation and variable multiplicity [message #1803898] |
Wed, 13 March 2019 11:02 |
Yoann Farré Messages: 235 Registered: November 2017 |
Senior Member |
|
|
Hello everyone,
I'm trying to use variables with a multiplicity which is undefined (more than 1) and generate C++ code.
If the multiplicity field is set to 0..* , the code generator set an array. It's fine if the multiplicity is known and defined (for instance 3), but if 0..* is set, the code cannot compile.
As in C++, tables have fixed size, I propose that in the case where the multiplicity is set to *, the property would be generated as std::vector.
For example, if I defined a property like this in the model :
MyType prop[0..*]
The code result could be:
std::vector<MyType> prop;
Currently, the generated code cannot be compiled :
MyType prop[];
I know that I can create an external type which uses std::vector to type the property but I think this is a lack for the multiplicity management of a variable. Could you give your opinion and maybe other ideas ?
Regards.
Yoann.
|
|
|
|
|
Re: C++ Code Generation and variable multiplicity [message #1804011 is a reply to message #1803964] |
Fri, 15 March 2019 16:38 |
|
Hi Yoann,
I agree that some options for dealing with unspecified multiplicities are needed. The currently generated code works for method declarations (void f(MyType par[]) compiles) but not for attribute declarations. A low level option would be to declare a pointer, in other situations, std::list or std::vector would be more appropriate. As there is more than one way to do it, the generator needs to be configurable, but the configuration option must be stored within the model (since body code depends on it). I would prefer a stereotype on a package that defines a mapping of multiplicity elements instead of a stereotype on each parameter or property declaration, since this would favour an inconsistent use within a project - do you think that there is a need to use different mappings at different places?
Ansgar
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02146 seconds