Home » Eclipse Projects » Papyrus for Real Time » higher dimensional arrays?
|Re: higher dimensional arrays? [message #1783856 is a reply to message #1783835]
||Mon, 19 March 2018 15:05
| Ernesto Posse
Registered: March 2011
I'm afraid that in C++ the syntax is |
is a C++ syntax error.
Unfortunately using the AttributeProperties.type property won't be much help here, as the code generator simply puts whatever is in this 'type' property before the attribute name in the generated code.
As a workaround, you could use the 'privateDeclarations', 'protectedDeclarations' or 'publicDeclarations' properties of the CapsuleProperties stereotype, or the PassiveClassProperties stereotype, to add any C++ declaration.
However, it would probably be better to create a suitable abstraction for the multi-dimentional array: define a class called e.g. My2DArray, which provides suitable setters and getters (in C++ you can define them as operators so that they look primitive), and internally it can use the '*Declarations' properties mentioned above, or some alternative representation, like an array of lists for a sparse array.
|Re: higher dimensional arrays? [message #1783931 is a reply to message #1783856]
||Tue, 20 March 2018 13:59
| Juergen Dingel
Registered: January 2015
Ok, I think I get it: Suppose you want capsule 'C' to contain an attribute 'int myArray': |
1) select the capsule 'C' and the 'Properties' tab
2) ensure that stereotype 'CapsuleProperties' has been applied (if not, click the green '+', select 'CapsuleProperties' on left, click '->', and then 'Ok')
3) expand 'CapsuleProperties', select property 'privateDeclarations' (or, 'protectedDeclarations', or 'publicDeclarations'), and input 'int myArray;' in text field on right (see attached screen shot).
Now, 'myArray' should be visible and usable in the action code of capsule 'C', e.g., you should be able to write:
myArray = 0;
loggerP.log("[Switcher] myArray = %d", myArray);
in the action code of any transition of the state machine of 'C'.
While this should work, the not-so-nice thing is that the 'myArray' attribute
is 'hidden', i.e., it is not directly listed as an attribute of capsule 'C' in the
Model Explorer, meaning that (1) one may forget or not realize it is there, and
that (2) it is cumbersome to look up, e.g., the precise name or dimensions, etc
To avoid this, wrap the array into a passive class, e.g., 'MyArray' that holds the
array and offers the required access methods.
To create this passive class, right-click 'C', then 'New UML-RT Child', then 'Class'.
Call that class 'MyArray', and apply the 'PassiveClassProperties' stereotype. Use
the 'privateDeclarations' property as before to create the array. Then, define
the desired operations for the class (right-click 'MyArray', select 'New UML-RT Child',
then 'Operation', and then use the 'Properties | UML' and the 'Code Snippet' tabs).
Current Time: Sat Jun 06 09:04:47 GMT 2020
Powered by FUDForum
. Page generated in 0.07333 seconds