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

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

[复制链接]

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

2470

主题

1275

回帖

8万

积分

管理员

PLM之家站长

积分
82166
QQ
发表于 2015-2-3 09:18:14 | 显示全部楼层 |阅读模式

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式2 ~0 a, I8 f1 n3 T( Z

! ~( R3 J" H7 v5 s; q
% b" M) j* X& g
1 变量声明. o4 V! F* `1 A# z3 ~; b7 J
1 L, Z' Q; H6 U+ [" C2 D

& G5 f9 \  m( j  l! Lo Old way
+ m2 i; \. s9 X8 ]( k// Declare pointers for an Item, Form and vector of ModelObjects
6 V. p; s$ L1 D) [// initialize to NULL: ?  C7 D' H0 r$ |
Item *theItem = NULL;3 u" s" m/ z6 `% F2 s; V  }
Form *theForm = NULL;
0 I# P4 J) ~1 \2 m4 r- \vector< ModelObject *> objects;
- j' y; }3 g# c4 \7 r" Z- R' R! j...
* w3 {0 r; I4 f: C2 E// Use the Item
5 V2 n  A2 b# d9 D0 mtheForm = theItem->get_item_master_tag();4 ~: j8 `) y; q9 n& X) t8 x
objects = theItem->get_revision_list();2 ~. L+ Z) ?* g4 v
o New way
2 c0 a% E4 M/ X. Y! p- m- T6 f// Declare AutoPtr for an Item, Form and vector of ModelObjects
$ L: i8 K! x. j; ?: O// all AutoPtrs are instantiated as NULL4 A$ L" {/ I4 m  ]8 ~
Teamcenter::Soa::Common::AutoPtr<Item> theItem;. m8 t9 x  o- R
Teamcenter::Soa::Common::AutoPtr<Form> theForm;' t% O! U- T+ T. J
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;* a1 I1 x' ^: d6 E/ Z
// Use of the ModelObject variables remains unchanged
; T" X' b) L  W% h5 c3 D+ k0 ptheForm = theItem->get_item_master_tag();
1 \% ]- F" f1 _objects = theItem->get_revision_list();, J: m/ X2 s, O- Y$ v' j" {4 a

3 n* ?/ t- Z/ e- M  l; z: [
9 J: o( _# C: ^2 类型转换
: \, M5 O9 @) @* J* K, [! G3 d6 i
, c3 c) }1 ]. M0 {o Old way
9 @  P8 \6 b# E; [/ C// Declare the variables
5 U. J/ X% N3 Q3 S2 f* E: OUser *user;) c" w0 B- {1 ]+ }" U# Q3 V
ModelObject *anObj;5 s. R% i5 }- ?- S& C. ?
Folder *folder;, D/ q' B; |7 W& U+ `, R0 q
user = sessionService->login(name,pass, “”,””, descrim ).user;' n- u, n* B* G- @
// Cast to the base ModelObject class* S3 b1 X4 W! s  U% _" Q. E
anObj = (ModelObject*)user;
* O0 Y% d7 a- m' f, }, b// Cast to a speicfic sub-type, if not NULL8 W! m0 t2 O( J" m2 q& T; N, j
// do something with the new pointer1 S7 r6 s4 a+ \8 ?& |  M. d- B& K
user = dynamic_cast<User*>(anObj);+ `1 }0 `2 F  q+ E2 j
if(user != NULL)
' u3 ]3 w7 K/ H3 K4 ^0 P{
2 O6 [7 ]! u1 g! ?( ]1 n( z8 wfolder = user->get_home_folder();
7 r0 }/ c4 t$ `+ j}
7 @4 C, O5 F" L2 |' Ko New way' Z' v1 k  k4 U# d& V; ^
// Declare the variables1 E$ o* Y' V) D
Teamcenter::Soa::Common::AutoPtr<User> user;
2 N, Y& Y/ [' R' u: t. WTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
' |" O8 q" o" h' B) F/ d, F/ u9 @6 qTeamcenter::Soa::Common::AutoPtr<Folder> folder;
' t0 p6 O" j3 E3 Nuser = sessionService->login(name,pass, “”,””, descrim ).user;
/ u5 |* {7 M: e8 d4 p0 t# X3 r// Cast to the base ModelObject class! n0 y& \1 o: m' x
anObj = user.cast<ModelObject>();
) J9 q4 \; f- j1 d// Put the cast to a speicfic sub-type, in a try/caTCh block
7 ^) r& M9 c4 J3 ^- _1 x7 a// if std::bad_cast not thrown, then cast was successful" n  N8 F' Y4 [
try
5 w, B2 @% p: x  {1 X/ b{0 h$ l3 I; C% h3 R1 `
user = anObj.dyn_cast< User >();+ [: t0 @! e" ]* A
folder = user->get_home_folder();
7 a& ?' u1 u: x) y* k}# ]# }) R9 {; O
catch(std::bad_cast&){}
5 o8 O$ v( H- D& B- H0 [& ?& f2 \7 U$ f$ r

) T- F8 X/ u7 C+ J- {3 关于NULL 赋值5 \+ o' N* h# b: Q, J- E

$ i# _8 h2 r$ O5 x* s, q( yo Old way- ?; ~8 k1 ~7 R3 `7 n7 r
// Declare the variables
5 r" x% l1 a- E: fLoginResponse response;
; k' N# k9 S9 Q1 W8 ~- JUser * user;
9 Q* g$ u3 N4 W; t+ I, s2 f9 z// Call a service that returns a ModelObject (User)
+ M9 q' \; g7 j$ V" I9 ~1 h; S1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
6 I9 X: ^  X" m" L6 o/ x( ]user = response.user;" z  R, A; B: p" \* ~  C3 y# u
// Test that instnace against NULL
: B8 J0 t; w* w& q6 x5 dif( user == NULL)  E4 I9 W2 A" c4 L
{
' G2 C9 z' I2 t) Y  K0 ^...) _+ j$ d' t8 j
}
" {  }& {$ }. e" \' x; ~- gelse
) D# L7 p3 i9 e5 D; j1 c{
% q) B( F1 ]* \// Assign NULL to the pointer
# c& d, |7 b; ?4 H0 T0 S; Wuser = NULL;' r+ \- n# ~. x
}( Y7 N5 @' t, A- ]; v+ j0 ~7 U* t
o New way, I. A5 L! N  ]4 i' H( s
// Declare the variables
/ v( ]4 ]6 t. P# i) D+ j// The service data structures do not change, only
* a# L2 G9 M  h9 y+ {// references to ModelObjects
9 W. ]3 S* h) K- @9 a- z& w; FLoginResponse response;
7 o3 B: ]# l2 V( r: @0 TTeamcenter::Soa::Common::AutoPtr<User> user;
1 H: _, F" `9 o! P; M+ g// Call a service that returns a ModelObject (User)& o, C9 Y0 H8 I& K, |2 m: g6 g
response = sessionService->login(name,pass, “”,””, descrim );+ `: \) ?# n6 x, ^- E
user = response.user;2 H2 i0 [- K! r, \
// Since we are not dealing directly with pointers,
6 h0 ?2 ?9 K6 D3 [// NULL does not make sense here, use the isNull method from the
1 R! B  b# E2 n. y// AutoPtr template class.  ^; b; c  [  o# O4 a1 @
if( user.isNull())' y8 I! [' x* E$ W1 P; E  X! k2 _
{* H# Q! M6 ~1 e
...9 v. R, h. `; g7 E* s
}5 @& I5 ?; L. s
else2 ~, d0 I9 a$ }6 K2 F. a8 ]
{. U! n" s3 B+ C$ `5 V/ l
// Release the instance and3 H7 `( G& M9 u9 U9 C
user.release();" O1 H; q5 i0 {2 j
}
; }: ~! D. g4 D6 T2 h
: O4 ]" q3 R2 M& _4 W

0 t+ T5 @  s* G2 g
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了