IBM RSA (IBM rational software architect ) V8 學習之四 C++類圖轉換成c++代碼

來源:互聯網
上載者:User

原文http://blog.csdn.net/ztz0223/article/details/7596025

 

前一講:

RSA建模 c++類圖

已經說過了,如何產生一個結構體,新增成員變數,添加帶參數的成員函數,那麼如何看到效果呢?

這就是本文要說的了:變換->UML to C++

回憶一下,之前建立的模型--c++類圖。

 

現在要用這個類圖類產生相應的代碼:

步驟一,選擇建模檔案example_uml,右鍵,快顯視窗選擇變換-》建立配置:

 

步驟二,輸入配置名:

 

步驟三,建立目標容器:

 

步驟四,建立產生的c++工程,輸入example_cpp作為c++的工程名:

 

步驟五,點擊完成,轉換配置自然就完成了,最後結果了:

 

可以點擊視窗中 UML to C++屬性,定製需要的一些操作。

步驟六,點擊運行便可產生C++代碼了:

 

最後產生的程式碼工程如下:

 

我們再看看代碼,和上一講所說如何?

 

ok,雙擊 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.   
  7.   
  8.   
  9.   
  10. //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  11. struct my_struct  
  12. {  
  13.   
  14.     //Begin section for my_struct  
  15.     //TODO: Add attributes that you want preserved  
  16.     //End section for my_struct  
  17.   
  18.     private:  
  19.   
  20.   
  21.         //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  22.         double m_dbl;  
  23.   
  24.   
  25.   
  26.   
  27.     public:  
  28.   
  29.         //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  30.         int * m_func(long arg_in);   
  31.   
  32.   
  33.   
  34. };  //end struct my_struct  
  35.   
  36.   
  37.   
  38. #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.   
  6.   
  7. //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  8. int * my_struct::m_func(long arg_in)   
  9. {  
  10.     //TODO Auto-generated method stub  
  11.     return 0;  
  12. }  

 明顯可見了,上一文章說的,建立的類成員變數和類的成員函數都和建模一致了。

 

如果我們修改了之前的類圖設計,代碼也可以跟著一起變化的,操作如下咯:

1、我在之前的結構體裡面添加一個靜態函數,static int do_nothing();

 

 2、儲存整個工程,在工作區選擇變換設定檔tc1.tc標籤欄,點擊運行

3、會提示你,新的修改要寫入之前的檔案,確定就是了:

 

4、我們再看看代碼,標頭檔 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.   
  7.   
  8.   
  9.   
  10. //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  11. struct my_struct  
  12. {  
  13.     //Begin section for my_struct  
  14.     //TODO: Add attributes that you want preserved  
  15.     //End section for my_struct  
  16.   
  17.     private:  
  18.   
  19.   
  20.         //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  21.         double m_dbl;  
  22.   
  23.   
  24.   
  25.   
  26.     public:  
  27.   
  28.         //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  29.         int * m_func(long arg_in);   
  30.   
  31.   
  32.   
  33.         //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  34.         static int do_nothing();   
  35.   
  36.   
  37.   
  38. };  //end struct my_struct  

5、看看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.   
  6.   
  7. //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  8. int * my_struct::m_func(long arg_in)   
  9. {  
  10.     //TODO Auto-generated method stub  
  11.     return 0;  
  12. }  
  13. //@generated "UML to C++ (com.ibm.xtools.transform.uml2.cpp.CPPTransformation)"  
  14. int my_struct::do_nothing()   
  15. {  
  16.     //TODO Auto-generated method stub  
  17.     return 0;  
  18. }  

一切都是如此美好,哈哈。

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.