Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Default Value and Code Generation
Default Value and Code Generation [message #1796113] Fri, 05 October 2018 10:05 Go to next message
Yoann Farre is currently offline Yoann FarreFriend
Messages: 116
Registered: November 2017
Senior Member
Hello,

I would know if the "default value" field in a property is used by the C++ code generator? If yes, how can I set it to initialize correctly a property?

Thanks.

Yoann.

[Updated on: Mon, 08 October 2018 06:42]

Report message to a moderator

Re: Default Value and Code Generation [message #1796195 is a reply to message #1796113] Mon, 08 October 2018 08:43 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 228
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi,

it is taken into account. What you need depends on the type of the attribute. If it is an integer (or variant thereof) you need to create a LiteralInteger (via "+" button in the default value field), if it is a float a LiteralReal and so on. A less evident choice is to use an InstanceValue to assign a specific enumeration literal.

Best regards

Ansgar
Re: Default Value and Code Generation [message #1796212 is a reply to message #1796195] Mon, 08 October 2018 11:58 Go to previous messageGo to next message
Yoann Farre is currently offline Yoann FarreFriend
Messages: 116
Registered: November 2017
Senior Member
Hi Ansgar,

Thanks for your reply.
I did like you describe, and even with an InstanceValue for enumeration literal. In the model, no problem. But the result of the C++ code generation was not in accordance with the model and I think I found the reason. The class I tried to generate has a "classifier behavior" and the state machine can be monitored. This brings that the constructor of the class looks like something like this (in .cpp file):

MyClass::MyClass() {
monitorSocket = socket(AF_INET, SOCK_DGRAM, 17);
monitorAddress.sin_addr.s_addr = inet_addr("127.0.0.1");
monitorAddress.sin_family = AF_INET;
monitorAddress.sin_port = htons(4445);
startBehavior();
}

But there is absolutely no trace of property initialization.

Now if I delete the classifier behavior of the class and retry to generate the code, I obtain a method like this in the header (.h file ):

MyClass() :
hello(Inactive), myInt(0), activeVariable(Active), Myvar(
Active), test(1) {
}

Here it 's ok for the default value.

I think there is an issue in the generation when using behaviored class ( or monitored state machine maybe) and the initialisation of properties in the constructor.

Yoann




Re: Default Value and Code Generation [message #1796253 is a reply to message #1796212] Tue, 09 October 2018 08:37 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 228
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi Yoann,

thanks for pointing this out. Looks like a side-effect of the correction of bug 422373. Can you please post a bug.

Ansgar
Re: Default Value and Code Generation [message #1796259 is a reply to message #1796253] Tue, 09 October 2018 10:00 Go to previous messageGo to next message
Yoann Farre is currently offline Yoann FarreFriend
Messages: 116
Registered: November 2017
Senior Member
It's done! Thanks Ansgar.

Bug 539952
Re: Default Value and Code Generation [message #1803066 is a reply to message #1796259] Thu, 21 February 2019 16:25 Go to previous messageGo to next message
Yoann Farre is currently offline Yoann FarreFriend
Messages: 116
Registered: November 2017
Senior Member
I'm coming back on this thread because I have an issue about default value.

I'm trying to set an enumeration literal as default value for a property (typed with an enumeration). To do that, I create an instance value and set the instance with the enumeration literal.

When I'm trying to generate the code, I obtain for example:

	::MyModel::Types::WeekDayType current_day = Monday;



But this code doesn't compile, the compiling code would be:

	::MyModel::Types::WeekDayType current_day = ::MyModel::Types::WeekDayType::Monday;



Is this the good way of modelisation for this usecase, and if yes, is it a bug or just a generic way to treat an instance specification?

Yoann.


Re: Default Value and Code Generation [message #1803106 is a reply to message #1803066] Fri, 22 February 2019 13:44 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 228
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi Yoann,

it's a bug in the context of C++ 11 scoping. Can you please post it.

Ansgar
Re: Default Value and Code Generation [message #1803116 is a reply to message #1803106] Fri, 22 February 2019 16:02 Go to previous message
Yoann Farre is currently offline Yoann FarreFriend
Messages: 116
Registered: November 2017
Senior Member
Hi Ansgar,

It's done : Bug 544726
Previous Topic:hiding multiplicity for cconnectors using CSS
Next Topic:Ternary connector in component diagram
Goto Forum:
  


Current Time: Mon Dec 16 02:21:44 GMT 2019

Powered by FUDForum. Page generated in 0.02458 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top