PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
6 x( p/ m' Q; z& B2 N
4 F$ [' x3 u+ O, o0 m
# u- o% e; J$ X& S
1 变量声明
( S0 I" O( o8 Z9 s- v
7 H- l4 B2 X% b
' e. `  j, `8 w: A
o Old way9 @' a9 ?( |# F! u1 D; _
// Declare pointers for an Item, Form and vector of ModelObjects7 X, a4 [7 f9 r6 O! ]/ a1 l) q
// initialize to NULL
, e: A% P; J& O* v% ?Item *theItem = NULL;. }" {1 E, ~% i5 z+ \' }  f$ ?
Form *theForm = NULL;/ t7 s1 {: I$ x8 }- X6 B, P
vector< ModelObject *> objects;! I' G! W) c: T
...
: q( ^, I, O0 ]9 y/ R4 `0 j// Use the Item* O; ^5 a* c' T* t: s
theForm = theItem->get_item_master_tag();
9 W- O% Y* T9 p  zobjects = theItem->get_revision_list();9 r5 J5 t+ e: [7 ]
o New way
6 X+ a6 e1 f0 ]% q3 }8 J# _; x- t" B// Declare AutoPtr for an Item, Form and vector of ModelObjects0 V$ o. T) e. @. r8 D
// all AutoPtrs are instantiated as NULL1 }1 z4 E- D' S2 P' U
Teamcenter::Soa::Common::AutoPtr<Item> theItem;1 K* i0 m7 s. \3 w
Teamcenter::Soa::Common::AutoPtr<Form> theForm;
5 O1 O) D: h: e' W+ h( bvector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
9 R# q3 S$ J% o$ i( B  U// Use of the ModelObject variables remains unchanged
4 b, B0 z! C# vtheForm = theItem->get_item_master_tag();' ?7 T$ o" r) g9 U* I" c$ p
objects = theItem->get_revision_list();2 F2 K7 Z8 ~2 G

2 g% l% q5 v& w/ D5 T/ `( P7 i+ R& w' B& e* O" n* ?/ \
2 类型转换
2 _# V  s* |+ x8 M2 N
1 O5 j" u& l' d* U& vo Old way
' I. y. j5 E; B  B+ ~, ]// Declare the variables+ S! F7 e  C2 N2 Q- ^. A
User *user;
1 I2 |- _! ~2 J" g3 |ModelObject *anObj;: O0 I1 M3 G& V, x* d5 H2 |( `' H/ K
Folder *folder;) X7 o7 P+ f& o- w" d7 V1 w
user = sessionService->login(name,pass, “”,””, descrim ).user;# i- s; _# v1 c9 I5 i% B
// Cast to the base ModelObject class
& s+ N* t9 L6 ?. M. W! ]* @anObj = (ModelObject*)user;
6 [* D. @# J8 T3 m8 g; ]! I; ^2 Y// Cast to a speicfic sub-type, if not NULL! a  H3 r: E/ L, i' t. z8 Z4 L
// do something with the new pointer
' @) t+ s" ~* d1 R  }$ _) xuser = dynamic_cast<User*>(anObj);2 P5 `2 A3 ?. p9 s+ H
if(user != NULL)% D' T# X" f' c6 k8 }
{$ J: ?; j& j* ?8 n2 r& r2 W
folder = user->get_home_folder();
8 E, }( X9 [. d}
1 i9 D* i4 [& U/ J1 Go New way
1 }5 A/ N" u! r5 g5 S0 r3 K' d# o// Declare the variables
, A3 Y1 P' q6 n% u8 Q* dTeamcenter::Soa::Common::AutoPtr<User> user;
3 p+ s/ ?$ [- U) b7 ]5 ]Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;% k. ?( f. D* J- I% r" Z* s
Teamcenter::Soa::Common::AutoPtr<Folder> folder;
9 \9 U/ j! _8 O: e" m" ~1 D# ?user = sessionService->login(name,pass, “”,””, descrim ).user;
2 F- Q. t+ o* S4 x; q// Cast to the base ModelObject class% t1 Y4 a+ ?9 l' Q7 p
anObj = user.cast<ModelObject>();4 [7 j6 ^5 r7 D0 ~% x
// Put the cast to a speicfic sub-type, in a try/caTCh block3 J! A: V( C# K$ d7 n8 v
// if std::bad_cast not thrown, then cast was successful# Z. ^" h+ Z4 P3 k0 d
try
( Z/ S! s- O% M5 N$ p7 ^% i{2 U1 Z( Z% F; i+ I. ~) Y+ A
user = anObj.dyn_cast< User >();
7 J* e8 Y# f6 l* \folder = user->get_home_folder();0 @; Q3 {7 _& p2 s4 l0 ~' B' P
}$ d7 ?, f! Q" u( R% t0 U- l
catch(std::bad_cast&){}
9 B) x; X) D4 I  o/ E) C$ j2 U5 C2 U8 B* Y& \' F' b. v, f. g8 f
0 |$ F/ {  a- P; V! U9 t
3 关于NULL 赋值# p- m1 K1 p& _9 U
' N2 Z3 {- D( x2 }
o Old way
" F- n( _& `/ u5 A+ S1 }. S// Declare the variables
! A9 y3 C# g2 w( tLoginResponse response;
$ E4 x. m5 P; Z+ `User * user;- q! `( M) q' ^7 G' C0 \0 c8 p: @: I0 ?
// Call a service that returns a ModelObject (User)
* Z' K. O9 [! c2 H) ~1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );5 `  Z1 Q' U4 j+ \
user = response.user;7 }/ W6 A$ S; C9 a9 `3 \6 c
// Test that instnace against NULL
- Z3 V% V1 [. [; ^! J! J; `/ Eif( user == NULL)8 l- ]% G+ J2 e8 U, K& g
{
$ _5 ~& A+ y) T9 p...0 z5 R& w* A3 |, V7 x
}
, ^! Y. l) M' Z# i5 Lelse
+ W( F' z3 O( N  p* }' A{
* l/ B- ~8 z7 ?9 Q; x  z1 |/ w// Assign NULL to the pointer2 Z4 w0 n' O0 n# W( O4 z+ ?% n
user = NULL;5 q+ z5 a; J& T( p5 r2 [
}
/ H6 {, d+ `" v; y/ o1 Q& A" c8 A5 Lo New way
4 d, o+ N) S4 F& ~// Declare the variables2 S: c" f: s5 c; N
// The service data structures do not change, only
& }  {' O6 n5 ^3 i  V( O' m// references to ModelObjects
9 ?& _/ {6 {9 d' J+ XLoginResponse response;
; g& ]: X) X! LTeamcenter::Soa::Common::AutoPtr<User> user;% ]" u' W: O$ t9 f6 d3 s
// Call a service that returns a ModelObject (User)
3 C, S# ?  W: r  S+ oresponse = sessionService->login(name,pass, “”,””, descrim );4 u4 M2 o5 B4 Y( R( H
user = response.user;. R, f1 m" i2 L( ^, h
// Since we are not dealing directly with pointers,) E9 k1 M" H- \/ `  ?+ _
// NULL does not make sense here, use the isNull method from the
( Y( M3 c7 s  q// AutoPtr template class.4 r3 K) N1 ]6 B' \
if( user.isNull())
" G8 X& C8 u/ D% R: D{
  F( {3 j7 y/ ^% p- \/ m+ o...
/ ?3 Z  Y) ?7 K6 d# _, E1 u}5 i5 R/ B& t' Y" e! @& B
else
" T/ z. k% M# c5 |2 u0 N{" c# ^( J5 X, S: f$ L: Q
// Release the instance and" f6 |5 t4 P4 O8 o
user.release();
' s' N) \) Y; |}
* @6 M- L) b0 T# S0 a& }2 k  A
4 f6 ]+ _: i% U# v

- J. v4 h( P+ _$ |$ k! \) L: O+ i
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了