Shortcomings of C++ round trip engineering

I found VP quite helpful for creating UML diagrams. But sadly the C++ round trip engineering seems very limited. After two or three iterations of round trip engineering it typically fails for us and leaves the diagram and the code in a bad state.

It would be great if the C++ round trip engineering could be extended to better support common workflows.

Limitations we found in Visual Paradigm Enterprise 16.2 (in the first two hours):

  • Adding the statement = default for the class constructor or destructor breaks the C++ parser. The class is removed from the diagram
  • When using a namespace, and the namespace encapsulates multiple methods in the C++ source file, VP will add duplicate methods after the namespace. So the following syntax seems not supported:
namespace myNameSpace {
myClass::myClass() {
}
myClass::~myClass() {
}
}
  • The C++ parser seems to have problems when using method argument const <type> <name> compared to <type> const <name>. We encountered problems for example when using const std::string&. The problems went away when instead using std::string const&. It would be great if both syntax could be supported because they are both very common.
  • The C++ parser seems to have problems with class destructors. When parsing a class that has a constructor and destructor, the UML diagram will instead show two constructors and no destructor.
  • The C++ parser does not seem to respect method ordering. For example, all our classes have the contructor and destructor first (and this is very very common in C++ and Java). But when using the round trip feature to parse the C++ code, the method ordering seems to be randomized. This requires tedious re-ordering by hand.
  • Sometimes the code generator duplicates arguments in the method signature of the implementation file. The method signature is correct in the header file but has duplicate arguments in the implementation file.
  • Sometimes the code generator seems to completely re-generate a source file, which removes the formatting and include statements. We could not find a reason why this happened.
  • There is no good support for templates for source files. It would be very helpful if further templates could be defined.
    • Template for the file would help so that a common copyright header could be added by default. This could also help so that common includes (like stdexcept for exceptions) could be added by default.
    • Template for class declaration or method declarations would help so that common sections like doxygen comment blocks could be added by default.
  • The UML diagram editor allows to generate getters and setters along with an attribute. But the code generator does not contain valid getters and setters. Since getters and setters are very simple, it would be nice if they would contain valid code.
  • In C++, default getters should be const (so add a const after the method name).
  • In C++, base classes need to contain virtual destructors. If this is overlooked it can lead to incorrect code (resource leaks). It would be great if VP would automatically add constructors and destructors.
  • It would be nice if VP would allow to configure whether the class attributes come before or after the methods. Currently they come before the methods. In C++ it is more common to have them after the methods.
  • Last, not least, when the C++ parser fails to read a class, the errors should be more visible. By default, the errors are shown only in the bottom right corner in a tiny red number on top of a letter-icon. For an important problem like “the diagram just broke” this is not a suitable visualization. If the user overlooks the error, they may save a corrupted diagram to disk.

Hi emmenlau,

Thank you for taking the valuable time to share your opinion with us. We have reported the first and final four items to our engineering team. For the rest…

  • The C++ parser does not seem to respect method ordering…
  • Sometimes the code generator duplicates arguments in the method signature of the implementation file…

Sorry but we are unable to repeat these problems. Do you have any sample code for us to try?

  • Sometimes the code generator seems to completely re-generate a source file…

Are you able to repeat this problem? If yes, may I know your steps? In particular, what actions were done between the now and the previous generation?

  • no good support for templates for source files…

I will forward your suggestion to our team to study.

  • …the code generator does not contain valid getters and setters…

Do you mean to generate also the body of getters and setters?

Best regards,
Jick Yeung

1 Like

Just to add that we do not currently support C++ 11 in round-trip. The Instant Reverse feature supports it partially though.

Best regards,
Jick Yeung

Thank you for taking the valuable time to share your opinion with us. We have reported the first and final four items to our engineering team.

Thanks a lot Jick Yeung for your consideration! Its highly appreciated!

  • The C++ parser does not seem to respect method ordering…
  • Sometimes the code generator duplicates arguments in the method signature of the implementation file…

Sorry but we are unable to repeat these problems. Do you have any sample code for us to try?

I will send you the sources of the project and the project file. Is it possible to send it to a private email address instead of sharing publicly? Please PM me with the address if possible.

  • Sometimes the code generator seems to completely re-generate a source file…

Are you able to repeat this problem? If yes, may I know your steps? In particular, what actions were done between the now and the previous generation?

I will try to reproduce the problem. What I can say about the steps I did:

  • Create a new UML class diagram with 2-4 classes
  • Use the C++ round trip generator to generate the sources
  • Open the source files in VSCode
  • In VSCode: Apply clang-format to the sources
  • In VSCode: Remove the namespace from each method, and add a surrounding namespace for the full file
  • In VP: Import the sources into the diagram using the C++ round trip import
  • In VP: Perform editing of a few method signatures
  • In VP: Use the C++ round trip generator to generate the sources

I did this maybe two or three times. In this process, one source file was regenerated from scratch (or all manual formatting was lost).

But I will try to reproduce the issue.

  • no good support for templates for source files…

I will forward your suggestion to our team to study.

Thanks a lot. VP already has some support for method templates in the round trip code generator. It would be awesome if this feature could be extended significantly so that users can define a template for method declarations (for example with doxygen header), for method definitions etcetc.

  • …the code generator does not contain valid getters and setters…

Do you mean to generate also the body of getters and setters?

Yes. So for example, in the case of the following UML:

#mValue : bool
+getValue() : bool
+setValue(aValue : const bool) : void

Currently VP generates:

bool Class::getValue() {
    throw();
}
void Class::setValue(bool const aValue) {
    throw();
}

The following would be very good C++ code:

bool Class::getValue() const {
    return mValue;
}
void Class::setValue(const bool aValue) {
    mValue = aValue;
}

Maybe its possible that VP understands whether a method is a getter/setter? Then it can generate the body. If this is not possible, then it would already help if methods with a name prefix get and an actual return value could have signature const and have a return statement?

Also, it would be really great if C++11 could be supported. Nowadays almost everybody is using C++11 or newer, particularly for currently active projects.

Dear VP team,
VP was a great product.
I am using “was” because over nearly a decade of use, I find that “depth” of the product has not increased.
For example code generation.
Even export of activity diagram texts as comments is sufficient to begin with.
Also, the formatting capabilities for text in “note” element are still quite limited. Not expecting winword, powerpoint or excel but definitely something more.

Whereas the diagram types have increased.
I don’t understand the purpose of adding electrical schematics.
The library is so limited, nothing compared to so many free tools already available.
Also, most of the schematic symbols are for electronics, so export to PCB layout formats is necessary. Again, so many free tools already do it.
Can you please stay with UML and allied fields like SYSML etc?
regards,
Kalpak

I have tried to isolate this issue further. Here is additional information that may be relevant:

  • The C++ parser seems not to respect the method ordering when I import C++ code into an existing class diagram using Reverse C++ Code.
  • So here is what I do (and what I observe):
    • In VP: Create a UML class diagram with a class that has three or more methods.
    • In VP: Generate C++ code from a UML class diagram.
    • In VSCode: Open the C++ code in an editor like VSCode.
    • In VSCode: Add a new method, for example as the second method in the class.
    • In VP: Update the UML class diagram from C++ code with Reverse C++ Code.
    • In VP: See that the new method is at the end of the class, not at the second position.
      This is not what I would expect. I would expect that Reverse C++ Code would take the method ordering from the C++ code. If the user does not want to change the method ordering, they should not change it in the C++ code.

Does that make sense?

Dear @Jick ,
I found another important problem:

  • VP does not seem to support the override keyword for virtual functions.

The override keyword is an important of virtual inheritance in C++. And virtual inheritance is a key use case for UML class diagrams. So it would be relevant that VP can support virtual abstract methods and the override keyword.

Hi emmenlau,

Some updates…

About const <type> <name> VS <type> const <name>, it’s fixed.

About const getters, you can set in the Operation Code Details tab of the Operation Specification window. To open it, right click on the operation and select Open Specification… from the popup menu.
image

About virtual destructors in base classes, since the code should follow the model closely in a round-trip operation we should auto create the model instead of making change at the code side. We will keep investigating this issue…

About the problem related to namespace that encapsulates multiple methods, it’s fixed. The code will generate as myNameSpace::myClass::myClass() {}, but the update function will search for both syntax.

The fixes are available in the latest patch build of version 16.3. You can follow the steps in the article below to update to the latest patch build (16_3_20210431an or above).

I will let you know when there is any news on other reported items…

Have a nice weekend!

Best regards,
Jick Yeung

Dear @Jick ,
I think I may have found another issue with C++ round trip engineering. When I reverse the C++ code, I think the connections between classes are not updated, is that possible? I found the following behavior that indicates the problem:

  • In the UML class diagram, add two classes
  • In the C++ code, add an inheritance from one class to another
  • Use “Reverse C++ code” to update the classes in the UML diagram
    • Do not tick the checkbox on “Reverse source on demand”
  • In the diagram, the connections between classes remain unchanged, even though a new inheritance is added

A different behavior comes when using “Reverse source on demand”:

  • Remove the class that inherits from the other from the UML diagram
  • Use “Reverse C++ code” to import the classes into the UML diagram again
    • This time, do tick the checkbox on “Reverse source on demand”
    • Pull the previously removed class from the side panel into the diagram
  • The re-added class now has updated connections from the other classes. For example, inheritance is now shown correctly, when previously it was missing.

Therefore I think that without using “Reverse source on demand”, the connections between classes are not updated. Is that possible?
All the best and thanks a lot for your consideration!
Mario

This is very good and helpful, thanks! It would be even better if VP can deduce the const automatically. When using “Add attribute with Getter and Setter”, could VP make the Getter signature const automatically? This seems a good natural default.

Dear @Jick ,
I hope you are doing well and everything is good! I just wanted to kindly ask if there is already further progress with the C++ round trip engineering?
All the best, Mario

Hi Mario,

Sorry, the suggestions are still pending to be reviewed. Once I have got any reply from our developers, I will post here. :pray:

Best regards,
Jick Yeung

Dear @Jick,
Thanks again for your nice support. I wanted to kindly ask if there is further progress with C++ round trip engineering?
All the best, and be safe, Mario

Hi Mario,

Sorry but our team is still working on the other pending tasks. I will let you know when there is any update.

Best regards,
Jick Yeung

Dear @Jick,
I wanted to kindly ask if there is further progress with C++ round trip engineering? It seems that Visual Paradigm can only support pre-C++11-code, which nowadays almost nobody is using anymore. That is very sad!
All the best, Mario

Hi Mario,

Thank you for your reminder. There is no update on C++11 support yet. If there are any updates, I will post them again. In the meantime, I will share your concerns with our development team.

Best regards,
Jick Yeung