Ibm rsa (IBM Rational Software Architect) V8 4 C ++ class diagram converted to C ++ code

Source: Internet
Author: User

Original http://blog.csdn.net/ztz0223/article/details/7596025

 

Previous Lecture:

RSA modeling C ++ class diagram

As we have already said, how can we generate a struct, add member variables, and add member functions with parameters? How can we see the results?

This is what we will talk about in this article:Transformation-> UML to C ++

Recall the previously created model-C ++ class diagram.

 

Use this class graph class to generate the correspondingCode:

Step 1: Right-click the modeling file example_uml and choose transform> Create configuration in the pop-up window:

 

Step 2: Enter the configuration Name:

 

Step 3: Create the target container:

 

Step 4: Create the generated C ++ project and enter example_cpp as the project name of C ++:

 

Step 5: Click Finish. The conversion configuration is completed. The final result is as follows:

 

You can click the UML to C ++ attribute in the window to customize the required operations.

Step 6: Click Run to generate the C ++ code:

 

The final Code project is as follows:

 

Let's take a look at the code. What do we say in the previous section?

 

OK, double-clickMy_struct.h:

[CPP] View plaincopy
  1. # Ifndef my_struct_h
  2. # Define my_struct_h
  3. // Begin section for file my_struct.h
  4. // Todo: add definitions that you want preserved
  5. // End section for file my_struct.h
  6. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  7. Struct my_struct
  8. {
  9. // Begin section for my_struct
  10. // Todo: Add attributes that you want preserved
  11. // End section for my_struct
  12. PRIVATE:
  13. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  14. Double m_dbl;
  15. Public:
  16. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  17. Int * m_func (long arg_in );
  18. };// End struct my_struct
  19. # Endif

My_struct.cpp:

 

[CPP] View plaincopy
    1. # Include "my_struct.h"
    2. // Begin section for file my_struct.cpp
    3. // Todo: add definitions that you want preserved
    4. // End section for file my_struct.cpp
    5. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
    6. Int * my_struct: m_func (long arg_in)
    7. {
    8. // Todo auto-generated method stub
    9. Return 0;
    10. }

Obviously, the previousArticleThe new class member variables and class member functions are consistent with those in modeling.

 

If we modify the class diagram design, the code can also be changed. The operation is as follows:

1. I added a static function in the previous struct, static int do_nothing ();

 

2. Save the entire project, select the tc1.tc configuration file in the work zone, and click Run.

3. You will be prompted to write the new modification to the previous file. OK:

 

4. Let's look at the code. The header file my_struct.h:

[CPP] View plaincopy
  1. # Ifndef my_struct_h
  2. # Define my_struct_h
  3. // Begin section for file my_struct.h
  4. // Todo: add definitions that you want preserved
  5. // End section for file my_struct.h
  6. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  7. Struct my_struct
  8. {
  9. // Begin section for my_struct
  10. // Todo: Add attributes that you want preserved
  11. // End section for my_struct
  12. PRIVATE:
  13. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  14. Double m_dbl;
  15. Public:
  16. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  17. Int * m_func (long arg_in );
  18. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  19. Static int do_nothing ();
  20. };// End struct my_struct

5. Check the CPP implementation file:

[CPP] View plaincopy
  1. # Include "my_struct.h"
  2. // Begin section for file my_struct.cpp
  3. // Todo: add definitions that you want preserved
  4. // End section for file my_struct.cpp
  5. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  6. Int * my_struct: m_func (long arg_in)
  7. {
  8. // Todo auto-generated method stub
  9. Return 0;
  10. }
  11. // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
  12. Int my_struct: do_nothing ()
  13. {
  14. // Todo auto-generated method stub
  15. Return 0;
  16. }

Everything is so beautiful, haha.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.