[isQuery=true] property on passive class function does not reflect on source file [message #1795449] |
Sun, 23 September 2018 00:15  |
Eclipse User |
|
|
|
Hi
While developing a project using Papyrus-RT, I have found a weird scenario in implementing a Passive class with readonly (const) behaviour. By looking into the properties panel, I came to know that there is a property named isQuery that can apply const modifier to the respective class/member.
First I tried on class then got compilation error saying member functions are not const type. Then I applied on member getter function. It works only in header file however the source *.cc file definition of that member does not match the declaration in header file, e.g.
I have a readonly class called Person with a member function getType() with isQuery set to true.
In *.h file getType() is generated with const modifier but in *.cc file the getType() function definition does not have const modifier.
Thats why I again got compilation error because getType() is not matching with header file declaration. Now I need to manually apply the const modifier on that getter function every time the Person class is generated.
Does anybody know any workaround to this problem?
Thanks in advance.
-Faisal
|
|
|
Re: [isQuery=true] property on passive class function does not reflect on source file [message #1795517 is a reply to message #1795449] |
Mon, 24 September 2018 11:54   |
Eclipse User |
|
|
|
Hi. I'm not sure what you mean by "isQuery" on a class. "isQuery" is an attribute of operations (i.e. methods) only. But you are right about the generated code being incorrect. In fact we already have a bugzilla entry for it: Bug 528160.
Unfortunately the only workarounds for now are:
1) Manually add the const to the method signature in the generated code, but this will be removed if you re-generate code,
2) Apply the PassiveClassProperties stereotype to the class and use one of the <X>Declarations properties (privateDeclarations, protectedDeclarations, publicDeclarations) to add the full method, including its signature with const
Note however, that the "const" qualifier applied to a method means that in the method's body the 'this' pointer is treated as const, and you can only call const member functions in theory, but being C++, you can always "break the law" and also call non-const functions with a const_cast [1]. So the const qualifier doesn't do all that much. It may be used by the compiler to do some optimizations, but not much else. So, as long as you are disciplined in the method's implementation, it shouldn't matter all that much. In general, one can live without it.
[1] https://en.cppreference.com/w/cpp/language/member_functions#const-.2C_volatile-.2C_and_ref-qualified_member_functions
|
|
|
|
Powered by
FUDForum. Page generated in 0.03480 seconds