C++ Code Generation

General discussions about code engineering

Moderator: Moderators

C++ Code Generation

Postby yuriv » Sun Sep 05, 2010 4:34 am

Hi!

In my project I have class with "C++Global" stereotype (it's reverse engineered), which has some global functions declarations and definitions. When I am trying to generate source code, I get error:
"Model contains the following errors:
Error: Illegal class name found""."
I have changed class name from unnamed to "a", and get error:
"Model contains the following errors:
Error: Class core::ints::a: Global class should be unnamed."

What I need to do? I need to have global declarations and definitions in my project.

Thanks a lot!
yuriv
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Sep 05, 2010 4:27 am

Re: C++ Code Generation

Postby bhoomchai » Mon Sep 06, 2010 4:26 am

Please try to remove name of the class (leave it empty) and try to generate code again.
It should solve the problem.
bhoomchai
Customer Support
Customer Support
 
Posts: 36
Posts Rating:5
Joined: Thu Jan 21, 2010 12:38 am

Re: C++ Code Generation

Postby yuriv » Tue Sep 07, 2010 12:08 am

Hi!
Read exactly, I can't generate code with "C++Global" stereotype. I have a class (class name is empty) with "C++Global" stereotype, during code generation, I get the error:
1. "Model contains the following errors:
Error: Illegal class name found""."

When I change the class name to 'something', I get another error:
2. "Model contains the following errors:
Error: Class core::ints::something: Global class should be unnamed."

In both cases I can't generate code for this class, what I need to do?

>>>Please try to remove name of the class (leave it empty) and try to generate code again.
>>>It should solve the problem.


At this case I get error #1 (see above).

Thanks
yuriv
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Sep 05, 2010 4:27 am

Re: C++ Code Generation

Postby bhoomchai » Tue Sep 07, 2010 3:57 am

Seem like you create a class and put it to a code engineering set before applying <<C++ Global>> stereotype to the class. When you put the class to code engineering set, it is realized as a normal class.

To fix your model, just remove a realizing component in File View and then add the <<C++ Global>> class to code engineering set again.
bhoomchai
Customer Support
Customer Support
 
Posts: 36
Posts Rating:5
Joined: Thu Jan 21, 2010 12:38 am

Re: C++ Code Generation

Postby yuriv » Thu Sep 09, 2010 5:24 am

Hi!

OK, I have attached the project file, try to generate C++ code for package 'core::ints' (it has unnamed class with 'C++Global' attribute). And second question: How I can generate code for declarations and definitions into .h file only (template classes and functions)?

Thanks.
You do not have the required permissions to view the files attached to this post.
yuriv
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Sep 05, 2010 4:27 am

Re: C++ Code Generation

Postby bhoomchai » Fri Sep 10, 2010 4:12 am

Hi Yuriv,

You didn't attached the mdr file, so I cannot investigate to see whether you have any problem using code engineering set or not.
Anyway, you can take a look at the zip file I've attached. I took your project file and create a C++ code engineering set. Then I set the working directory to <project.dir> and add all classes under core::ints to the set. I also generated code and attached within the zip file.

For the second question, MagicDraw does not provide any option to do so. For newly generated file, the declaration will go to .h and definition will go to .cpp
You do not have the required permissions to view the files attached to this post.
bhoomchai
Customer Support
Customer Support
 
Posts: 36
Posts Rating:5
Joined: Thu Jan 21, 2010 12:38 am

Re: C++ Code Generation

Postby yuriv » Sat Sep 11, 2010 4:25 am

Hi!

Your decision unusable, I need to put all definitions and declarations into one .h-file (component by MagicDraw), because it's template definitions and must be available for instantiation in any place of sources. And second: for large projects I don't like to generate bunch of files for elementary code fragment. Try to generate code for attached project, you will get described errors.

Thanks
You do not have the required permissions to view the files attached to this post.
yuriv
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Sep 05, 2010 4:27 am

Re: C++ Code Generation

Postby yuriv » Fri Sep 17, 2010 5:40 am

Hey guys, Are you alive? Have you any news for me?
yuriv
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Sep 05, 2010 4:27 am

Re: C++ Code Generation

Postby bhoomchai » Mon Sep 27, 2010 6:03 am

When you add a class to code engineering set, you will get .h component with Realization relationship to your class and .cpp component with Realization relationship to all operations in your class. This is the default behavior, however, if you don't want .cpp and would like to have method definition generated to .h instead, you can remove .cpp component from File View and create Realization relationship from .h component to operations that you want to have method definition generated.
Image
You do not have the required permissions to view the files attached to this post.
bhoomchai
Customer Support
Customer Support
 
Posts: 36
Posts Rating:5
Joined: Thu Jan 21, 2010 12:38 am

Re: C++ Code Generation

Postby yuriv » Tue Sep 28, 2010 5:10 am

I have tried it. It's works, but it is workaround, it's not decision. Suppose, I have ten methods in each of ten classes and I need to make 'realization' relation from component to each method of each class manually. I need to do it manually, because I can't drags group of operations and drops it to the component on the 'Containment' panel, I need draws relations on the diagram (or inside tab of specification dialog) one by one. And other question, How I can generate method implementation in the class scope? There is Component Specification/C++ Language Properties, why you can't append one property like 'inline code' for component, one property 'inline code' for class and one property 'inline code' for method of class? If 'inline code' property of component is true, you need to generate all classes of the component and his method's implementation in the file scope, If 'inline code' property of class is true, you need to generate all method's implementation of the class in the class scope, if 'inline code' for method is true, you need to generate this method's implementation in the class scope. If class or method of class has template parameters you need to set 'inline code' to true automatically for class or method respectively. It's simple. But it is lyrics. Whats about project sample from my previous message (core-ints)? I still need to generate global scope template functions and data.
yuriv
Forum Newbie
Forum Newbie
 
Posts: 6
Posts Rating:0
Joined: Sun Sep 05, 2010 4:27 am

Next

Return to Code engineering

Who is online

Users browsing this forum: No registered users and 0 guests