Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Dynamic Storage(Changing Multiplicity of Attributes within Code Snippets)
Dynamic Storage [message #1768905] Mon, 24 July 2017 19:13 Go to next message
Christopher Won is currently offline Christopher WonFriend
Messages: 11
Registered: July 2017
Junior Member
I was wondering if there is a way to change the multiplicity of attributes within code snippets allowing me to expand and contract arrays as required by my program. In addition to this it would be helpful to know how to access individual attributes as this would let me dynamically expand and contract my array and fill in or clear the contents of that array as the size of it is changing

Thanks in advnace
Re: Dynamic Storage [message #1768997 is a reply to message #1768905] Tue, 25 July 2017 14:05 Go to previous message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member

The short answer is that this is a target language issue, rather than a UML-RT issue, so it's up to whatever you can do in C++.

It is possible, but not with a direct link to the attribute's multiplicity. When you declare the multiplicity of an attribute to be greater than one, the code generator will declare an array (not a vector), which in C++ is always of fixed size, i.e. it's size must be known statically by the C++ compiler. You can actually declare the multiplicity of the attribute to be a symbolic constant (e.g. SIZE) but this symbolic constant must be evaluated at generation time and its value obtained from the same class, an enclosing namespace or another namespace if the constant is given with a fully qualified name (e.g. Model1::Class1::SIZE). It can even be an arithmetic expression, but in any case, this expression must be evaluated at generation time, and therefore it is static and not useful for dynamic allocation.

Nevertheless, there is a way to get dynamically allocated arrays, i.e. vectors. Instead of declaring the attribute as having multiplicity greater than one, leave it to the default value. Then in the Model Explorer, select the attribute, then in the Properties view select "Profile", and in the "Applied Stereotypes" field click the plus icon [+] to add the "AttributeProperties" stereotype. When you add it, unfold it and you should see several properties, including one called "type" of type String. Select it and in the type text box, declare the type you want to use. For example "std::vector<int>", where in this case, you can use the 'vector' class from the standard library. Aside from this, you must add the header where this class is defined. To do that, select the class or capsule that contains your attribute, then in the Properties view select "Profile" and click [+] in the "Applied Stereotypes" field. Select "CapsuleProperties", or "PassiveClassProperties", unfold it and select "headerPreface". In the headerPreface field add the include statement:

#include <vector>

Then you can generate code which should compile. The attribute will be a vector with storage automatically managed.

If you want your own class for manage storage, you can do that and follow steps similar to the ones above but with your own class name and header.

Previous Topic:Not able to create Plug-in Project in Papyrus-RT Tester version
Next Topic:Papyrus-RT v1.0 is available
Goto Forum:

Current Time: Sat Apr 20 17:47:55 GMT 2024

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

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

Back to the top