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
-
- # Ifndef my_struct_h
-
- # Define my_struct_h
-
- // Begin section for file my_struct.h
-
- // Todo: add definitions that you want preserved
- // End section for file my_struct.h
-
-
-
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Struct my_struct
-
- {
-
-
- // Begin section for my_struct
-
- // Todo: Add attributes that you want preserved
-
- // End section for my_struct
-
- PRIVATE:
-
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Double m_dbl;
-
-
-
-
-
- Public:
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
- Int * m_func (long arg_in );
-
-
-
-
- };// End struct my_struct
-
-
-
-
- # Endif
My_struct.cpp:
[CPP] View plaincopy
- # Include "my_struct.h"
- // Begin section for file my_struct.cpp
- // Todo: add definitions that you want preserved
- // End section for file my_struct.cpp
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
- Int * my_struct: m_func (long arg_in)
- {
- // Todo auto-generated method stub
- Return 0;
- }
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
-
- # Ifndef my_struct_h
-
- # Define my_struct_h
-
- // Begin section for file my_struct.h
-
- // Todo: add definitions that you want preserved
-
- // End section for file my_struct.h
-
-
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Struct my_struct
-
- {
-
- // Begin section for my_struct
-
- // Todo: Add attributes that you want preserved
-
- // End section for my_struct
-
-
- PRIVATE:
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Double m_dbl;
-
-
-
-
-
- Public:
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Int * m_func (long arg_in );
-
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Static int do_nothing ();
-
-
-
-
- };// End struct my_struct
5. Check the CPP implementation file:
[CPP] View plaincopy
-
- # Include "my_struct.h"
-
- // Begin section for file my_struct.cpp
-
- // Todo: add definitions that you want preserved
- // End section for file my_struct.cpp
-
-
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Int * my_struct: m_func (long arg_in)
-
- {
-
- // Todo auto-generated method stub
-
- Return 0;
-
- }
-
- // @ Generated "UML to C ++ (COM. IBM. xtools. Transform. uml2.cpp. cpptransformation )"
-
- Int my_struct: do_nothing ()
-
- {
- // Todo auto-generated method stub
-
- Return 0;
-
- }
Everything is so beautiful, haha.