PLM之家PLMHome-工业软件践行者

Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式

[复制链接]

2015-2-3 09:18:14 3794 0

admin 发表于 2015-2-3 09:18:14 |阅读模式

admin 楼主

2015-2-3 09:18:14

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
/ |) A: i& @% O, M: m6 ^2 p2 K( d' m' c) k0 _5 U
( @8 |8 c+ R$ L- O0 U/ p- |) A
1 变量声明
6 z3 ?4 S4 |$ d  b4 T& q- |
: W  Q' ~2 U3 C4 L" r$ K- `
7 h) H2 B% d% |6 r, l2 w
o Old way
" d4 s, F1 J# h) B* F( ^4 `# Z// Declare pointers for an Item, Form and vector of ModelObjects
/ z0 \/ u2 u7 P% c0 {// initialize to NULL
  c' H! e; p! H: yItem *theItem = NULL;
5 ?& n; D: t4 ~' g' l4 n1 qForm *theForm = NULL;
7 d0 k3 G) F* gvector< ModelObject *> objects;, F4 r# B, x0 x2 U
...
/ m# D* M) [' S1 b  G" X& G) ^// Use the Item
. Y* U7 Z+ E3 t3 R! I5 WtheForm = theItem->get_item_master_tag();
! }; d) k" D$ C" R" d2 g' f/ wobjects = theItem->get_revision_list();
- M9 q  |$ i: E# `- Eo New way
6 Z3 W/ {0 l) }  Y( O, M- n+ L// Declare AutoPtr for an Item, Form and vector of ModelObjects
- F7 ^; W0 D+ N* K1 _// all AutoPtrs are instantiated as NULL* O1 M: n* x% h7 w6 f$ w
Teamcenter::Soa::Common::AutoPtr<Item> theItem;) _( G* q& T- h
Teamcenter::Soa::Common::AutoPtr<Form> theForm;9 V* [' F8 b5 i
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;* i& h5 C; O1 X7 c
// Use of the ModelObject variables remains unchanged
, i; d$ W* M/ n) PtheForm = theItem->get_item_master_tag();
% d3 c5 o/ i+ O9 r5 |objects = theItem->get_revision_list();! n3 c+ o. a- {( o

- U7 q* k+ `4 s7 z* d
; E/ {- \& d9 {) Q: w2 类型转换   K5 u4 F7 ~9 t) Z

2 Y! F7 I; H- I' M: b, Y) Ao Old way8 J9 \) ^; }" \6 F$ y
// Declare the variables1 I! I" |  K9 v% d' x3 c+ c& g
User *user;
0 N0 }& C8 e# gModelObject *anObj;5 a. o& l! W+ X7 _& G$ [5 E
Folder *folder;: g$ P) b# H: w2 I0 r) s4 T  X! R
user = sessionService->login(name,pass, “”,””, descrim ).user;( I( l4 ?+ y; ^7 K0 y6 Y: ]. S/ m1 B
// Cast to the base ModelObject class/ v+ T" z' T! p: B5 ~% z
anObj = (ModelObject*)user;+ y5 t( |: Q5 V
// Cast to a speicfic sub-type, if not NULL
) b8 o9 v, S0 R- H0 H0 b# v// do something with the new pointer1 g$ i0 _2 b; W0 P# o' H8 Q
user = dynamic_cast<User*>(anObj);
  J" ~9 [6 r" m1 D4 @- U) r" Qif(user != NULL)' _0 f# {. x- \! }% _  K
{% @, f2 T1 ^; d7 ~, |
folder = user->get_home_folder();9 k- w3 N9 L- F2 N) Y+ t
}
, ^8 M. p* |0 c! s- ^2 to New way
/ E0 w! p9 D( y// Declare the variables7 H: R6 l0 l: b7 t5 K
Teamcenter::Soa::Common::AutoPtr<User> user;
: _7 o& P9 }5 G( ~. T% a+ vTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;6 I! S, f9 L: \, x& F  U) D
Teamcenter::Soa::Common::AutoPtr<Folder> folder;
7 Q" D; o2 y2 l0 ]# `user = sessionService->login(name,pass, “”,””, descrim ).user;
* _! H! ~9 @# B0 ^5 S1 t0 u% Q. Q// Cast to the base ModelObject class
0 I0 D9 m& m3 {7 @! ganObj = user.cast<ModelObject>();
* [. T7 n& k; u2 n( C9 q( ?) Z/ B: s// Put the cast to a speicfic sub-type, in a try/caTCh block
9 _) P1 H3 q9 [+ u+ A- @7 c6 a// if std::bad_cast not thrown, then cast was successful
8 D+ F: L, K5 M6 Wtry1 ?3 t0 {7 B6 j
{
/ c/ s9 N. |5 B( `& J9 quser = anObj.dyn_cast< User >();
- |+ l' G0 ~# |: B7 Vfolder = user->get_home_folder();) p9 a% R. v/ |( ?7 m0 f
}( H+ r. m. ~. n& x
catch(std::bad_cast&){}! H5 H0 b* T! L1 G: \7 W& ~0 ]; w/ L, X% O6 w

* W: M) D& \* W- z. [( o% {
4 n0 O4 X" p2 U2 a! q2 \3 关于NULL 赋值
5 y/ N: T0 {) t& o3 f' E4 R# I" D6 D
o Old way& ^8 N1 |& {: z/ ]4 z/ r4 g
// Declare the variables
' j; Y: Z4 E( G- j/ e8 Y3 ?# KLoginResponse response;
; O% M$ v7 N% AUser * user;
! R: t4 Z8 J/ Z0 x. H$ n1 s// Call a service that returns a ModelObject (User). y% O! J" p# ~, W. A( O3 x
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
" X( X# @% \; N+ X. O1 k8 buser = response.user;/ _) k7 r- r8 g. W8 w
// Test that instnace against NULL
' X$ s2 l$ n: U4 f0 Xif( user == NULL). [( B( K4 d& H0 {
{  _  `4 e2 V& e
...
8 |3 ?& @- S% |2 M; L}9 S* g) `: o/ `3 z8 \
else
/ O( Q! s$ ^* ?; W4 B1 `/ R5 n{# T) n7 i5 O% {
// Assign NULL to the pointer
! z) [/ i/ Y/ ?& p. @user = NULL;
0 f: x) Z' j+ _! i, K% Z}. v4 A: s$ r6 ^/ H' H! p$ x
o New way) h1 h9 o3 ~. X0 E/ p' c
// Declare the variables0 S8 V9 i' J- }' k( I9 o( z- s' x3 W
// The service data structures do not change, only" d8 q, R# [  H$ }# u. y+ X4 D
// references to ModelObjects! \& K. _: B( d4 B  ?; O
LoginResponse response;
: [7 S9 ^  l$ k: G3 @8 ]  j( lTeamcenter::Soa::Common::AutoPtr<User> user;' r% A: n; _  X
// Call a service that returns a ModelObject (User)) `0 V3 D$ f1 L+ B) b/ `
response = sessionService->login(name,pass, “”,””, descrim );! Q( l" G: V; I3 V* [$ O. b1 ]! i
user = response.user;6 t8 [  p: }4 j( Y  ~7 H' \6 X
// Since we are not dealing directly with pointers,7 u! ?' z1 j) ]
// NULL does not make sense here, use the isNull method from the
# Y" s. T* \6 F2 B// AutoPtr template class.
- D& }1 E- `6 A1 B$ b: r6 Bif( user.isNull())
2 m+ X0 d* r# M$ x{
; n3 n9 ^" X: e8 R...
2 R: @  b& N0 u$ c* J* a; U}
4 H) h; S6 s+ u( q# u+ S+ {5 e8 Welse# `0 ]& X- r/ ~' E5 P; L/ o% b
{
9 ?  P( G& b! ^// Release the instance and/ m7 a, }  s2 r9 _
user.release();
6 u7 l! S6 Y' n: w}' U# W6 e3 `0 o( H9 P

- u. A' T* b2 z) z

% t  d' \$ Y8 t) @  _. A$ m2 E
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 注册

返回列表 本版积分规则

  • 发布新帖

  • 在线客服

  • 微信

  • 客户端

  • 返回顶部

  • x
    温馨提示

    本网站(plmhome.com)为PLM之家工业软件学习官网站

    展示的视频材料全部免费,需要高清和特殊技术支持请联系 QQ: 939801026

    PLM之家NX CAM二次开发专题模块培训报名开始啦

    我知道了