Some issues with C++ code generation

Hi,

I’m using VP PE 7.2.

I try to generate ANSI C++ code from UML, but there some little issues that should be correct:

  1. Method modifies duplicates for each method:

class CorporativeCustomer: public ICustomer, public ICustomer
{
private: string _attribute;

public: void operation();

public: void operation2();

public: void operation3();
};

  1. include duplicates in each source and header files:

#include
#include
#include

  1. Adding code to source files, can’t be dumped with “reverse code”. Maybe there’s other approach to do this?

  2. Reverse from code UML, makes wrong UML, e.g. create both “Generalization” and “Implamentation” associations.

  3. Is there available some mechanism, to update code by it structure, but not at all. e.g. I create UML, dump it to C++ code, then
    made some changes in source code (for example, formating, some refactoring), reverse it again to UML.
    In UML I add only one method, and dump code again to source. But, in this case, all my changes (refactoring, formating) lost, because
    it was change not structure but all code at all.

  4. Is there available some option to manage namespacing? e.g. using namespace std met in each header file.

Thanks in advance,

Hi user,

Thanks for your post and the details. First of all, may I know did you run Instant Generator/Instant Reverse, or C++ round-trip engineering?

For the issues:
1+2. Would you mind to provide step-by-step procedure so we can try to repeat the problem?
4. Would you mind to attach a sample code which you reversed and have this problem?
Thanks in advance!

3+5+6. I’'ll check these issue to our engineers to follow-up. Once there is any feedback, I’ll come back to you.

Best regards,
Lilian Wong

Hi,

please check out attached file.

Hi Industral,

Thanks for the files. First of all, I would like to clarify that ANSI C++ round-trip engineering is available in VP-UML Professional Edition or above, and it’s not supported in SDE.
If you need more details about ANSI C++ round-trip engineering, please visit:
http://www.visual-paradigm.com/product/vpuml/provides/codedbeng.jsp#cpproundtrip

Please feel free to download VP-UML for evaluation from our website ( http://www.visual-paradigm.com/download/vpuml.jsp ).

Let’s get back to the issues you reported:

  1. Duplicated operations
    I’m sorry that I cannot repeat the problem, also there is no problem on operations in your flash movie in attachment. Please see “operations_in_code.png”, you have operations “operation()” & “operation2()” on class CorporativeCustomer and the code really reflects these 2 operations only.

However, I can repeat problem of duplicated class name shows in your flash, and our engineers are working on it. I’ll let you know once there is any further news of this issue.

  1. Duplicated include statement in each source and header file
    The include statements are part of ANSI C++ standard and there will not be compile problem.

  2. “reverse code” does not reverse added operations
    I’m sorry that I cannot repeat this problem. Could you please provide step-by-step procedures for me to repeat this problem? Thanks!
    By the way, I would like to clarify that Instant Reverse/Instant Generator are one-off engineering only, your existing models/code will be overwritten every time you run them. However, round-trip engineering only update your changes on code to models, or vice versa.
    By the way, Instant Reverse/Instant Generator are available in VP-UML/SDE Standard Edition or above, while ANSI C++ round-trip engineering is supported in VP-UML Professional Edition or above.

  3. Reverse from code UML, makes wrong UML, e.g. create both “Generalization” and “Implamentation” associations.
    I’m sorry that your files in attachment does not cover this problem. Would you mind to attach a sample for repeating this problem, or provide more information of this point? Thanks in advance!

  4. Update code by it structure, but not at all code
    From your flash movie you ran Instant Generator, so I believe you experienced the code loss problem with Instant Generator. As mentioned in point 4, Instant Generator is one-off engineering so that your existing code is overwritten, and you lost the code you entered manually.

  5. Is there available some option to manage namespacing? e.g. using namespace std met in each header file.
    “std” library is used in code engineering so you will have statement

using namespace std;

in generated code. You can manage your models with package for namespace management.

Hopefully my answer resolves some of your problems at the moment. And I hope you will try ANSI C++ round-trip engineering feature in VP-UML Professional Edition or above and will enjoy it! :slight_smile:

Best regards,
Lilian Wong


operations_in_code.png

Hi Industral,

Sorry that I did not answer your question in flash:
7. Right-click on class and Select in Code does not work
"Select in Code" is for Java round-trip engineering. As you ran Instant Generator so this feature won’t open the relative code file for you.

Best regards,
Lilian Wong

Hi,

many thanks for answers.

  1. Duplicated operations
    Not operators duplication, but modifies. Anyway, as you said, dev team working on that.
  1. Duplicated include statement in each source and header file
    The include statements are part of ANSI C++ standard and there will not be compile problem.

Of course, it will build success, but duplicating #include statements in both source and header files - unneeded and bad idea.

  1. “reverse code” does not reverse added operations
    Please take a look at attached screencast

There’s some one issue, that should be clarify.
Lets considerate C++ code.

Assume we have AbstractClass, that should be “abstract”. In C++, abstract class is class that has at least one pure-virtual method, e.g.

class AbstractClass {
  public:
    virtual method1() = 0;
};

But, we also have “interface” stereotype in UML. It’s most relative to Java, where this idioms present.
So, we can:

  1. Use “Java” approach:

a) “Abtstract” market class create as simple class, but if there’s added some methods, make them virtual
b) “interface” market with stereotype class, should make all methods pure virtual

  1. C++ aproach:

a) “Abtstract” market class create as simple class, but if there’s added some methods, make them pure-virtual
b) “interface” market with stereotype class has no affect it it.

VP-UML has very strange behaviour in this case. Try to play around abstract class, adding method to it, make this methods
abstract. They always will be regular methods or pure virtual.

Thanks,

Hi Industral,

Thanks for replying.

  1. Duplicate modifiers
    Thanks for your clarification. Our engineers are checking this issue and I’ll keep you posted for any news on this issue.

  2. Include statement in each source code and header file
    The declaration is in .h file, and it’s necessary to have the #include statements to tell the preprocessor where to look for the source file. It’s similar to import statement in Java.

  3. “reverse code” does not reverse added operations
    From your attached flash, you enabled “Reverse on demand” option when reverse the source code. With this option turned on during code reverse, it will not reverse the source to project (class repository) for you. You need to revere the classes you need from “C++ Round-trip” node in Class Repository - this is very helpful if you reverse large scale of source but not all source will be used in your project.
    Please right-click on the source code file you need (if you need all source in the source path, please right-click on the path node) and select Reverse to > Class Repository. Then you will see the changes made on the code is updated to models.

  4. Pure-virtual operations are generated from abstract operation
    Do you mean you want to have virtual operations instead of pure-virtual operations if they are abstract?
    If so, please check “virtaul” in Operation Code Details tab, then disable “Abstract” in General tab in Operation Specification dialog. Please note that you need to specify “C++” as programming language (Tools > Configure Programming Language) to have “virtual” as option in Operation Code Details tab.

Best regards,
Lilian Wong

reverse_on_demand.png

Hi Lilian,

thanks for answers!

  1. Include statement in each source code and header file
    Yes, you right. But I’m talking about the same #include statements in both .cpp & .h files, e.g.

Test.cpp:

#include <string>
#include <vector>
#include <exception>
using namespace std;

#include "AbstractClass.h"

and absolutely the same in
Test.h:

#include <string>
#include <vector>
#include <exception>
using namespace std;

if .cpp (source) file include .h (header) file, it’s unneeded to duplicate #include statements in both of them.
The good practice, is to move all include statement in .h files, and include only one .h file in .cpp file.

  1. “reverse code” does not reverse added operations
    From your attached flash, you enabled “Reverse on demand” option when reverse the source code

Yes, really, disabling this feature, works fine now. AFAIK, it was enable by default, so why I didn’t touch it :slight_smile:

  1. Pure-virtual operations are generated from abstract operation
    Confirm, disabling abstract in “General” and enable “virtual” in “Operation Code Details” works find now.
    It’s little bit confuse so coupling with two tabs… Anyway it works.

Thanks for your time,
Alex

Hi Industral,

Thanks for replying.

  1. Include statement in each source code and header file
    I’ve passed your comments to our engineers to remove excess include statements from .cpp files.

  2. Pure-virtual operations are generated from abstract operation
    We’ll enhance the UI of Operation Specification dialog so you will have clearer idea of how to generate virtual and pure-virtual operations.

Best regards,
Lilian Wong

Hi Industral,

I would like to notify you that we fixed issue 1. Duplicated modifies, please run “VP Suite Update” to update to latest patch (20100127j or later). You need to check “Group by visibility” in advanced options of Instant Generator (as shown as image).
Feel free to ask if there is anything I can help.

For your information, details about updating to latest patch are available at:

Best regards,
Lilian Wong


instant_generator_advanced_options.png

Hi Industral,

I’m sorry that patch 20100127j has a rendering model problem and referenced elements (from linked project) will be shown as “No Model Element”, we have fixed this problem and please run “VP Suite Update” again to update to patch build 20100127k (or later).
Details about updating to latest patch can be found from:

Best regards,
Lilian Wong