查看: 4055|回复: 0

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

[复制链接]

2477

主题

1280

回帖

8万

积分

管理员

PLM之家站长

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

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

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

×
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式( V  U# z: |) n! _2 c4 y7 y: M
3 {  j1 C: B' E

: k; E7 q4 v( F! T1 变量声明" @+ A; X$ g3 Z8 |+ n
9 Y) w6 i( ?: V! _! N; h+ V
7 A" @  p8 h2 |1 X$ c, I
o Old way
; N' h, `! j! k// Declare pointers for an Item, Form and vector of ModelObjects" A# p5 Q" P, _; n: S* P" J  m
// initialize to NULL; m: _6 x0 R+ P% c9 G; Y
Item *theItem = NULL;* |2 G4 a5 n) m5 C6 R, g
Form *theForm = NULL;
% [% a) C; z) n8 m7 t; B8 x  B2 X; ^vector< ModelObject *> objects;5 J  ?: m0 D: E
...3 I! F; b) R. t9 [: R; ]
// Use the Item# V3 P# @) R6 Y
theForm = theItem->get_item_master_tag();- b2 t" p9 r; Y# q0 \' F! S
objects = theItem->get_revision_list();
& S  w4 s" L6 {2 z% zo New way* _! Y( b4 H) |* u
// Declare AutoPtr for an Item, Form and vector of ModelObjects6 l- q$ L8 F* k# z  o
// all AutoPtrs are instantiated as NULL5 ~; h% h) J  D; C
Teamcenter::Soa::Common::AutoPtr<Item> theItem;
4 n6 _% o& }- g# M/ lTeamcenter::Soa::Common::AutoPtr<Form> theForm;% v& l/ j$ l4 \9 |- u9 b5 @  d
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
4 o1 y. U+ T  d" E& S// Use of the ModelObject variables remains unchanged, u0 b9 c; S6 m& _  L% f: c6 E) L3 u6 y5 f
theForm = theItem->get_item_master_tag();
# P: S# x  i/ Wobjects = theItem->get_revision_list();* Z$ o) W3 N- ]% ?: K

3 A8 w+ d: v8 f* r
7 M4 ]5 m" V6 V9 z% c8 B5 D% r2 类型转换 3 {; G* N1 ]6 @: {4 t/ ^
% T3 z& t4 d3 f: i% N  n
o Old way
7 X, l( A0 j9 A// Declare the variables
6 n, T1 r0 G1 q6 O, [  eUser *user;" o( g" ~2 }" d5 A9 @/ i
ModelObject *anObj;
: v- f" U4 s6 H8 r. BFolder *folder;, g4 A; C* \( v* b. X: ]
user = sessionService->login(name,pass, “”,””, descrim ).user;3 `' k4 ~* Q# y: O; b+ ~, ]
// Cast to the base ModelObject class  J/ ?9 R, ^5 U: E8 |1 A
anObj = (ModelObject*)user;6 }0 X/ b$ y, \+ H( ?# j6 `/ v
// Cast to a speicfic sub-type, if not NULL, t( h+ h  Z5 y' G/ g
// do something with the new pointer
4 ^# w! g$ m7 T$ r. R/ c! ruser = dynamic_cast<User*>(anObj);4 o# h" q/ r" V- {5 n7 p
if(user != NULL)
* m: v& H1 @' S' Y2 ]. s4 e  B{" ^/ m7 W7 w! {
folder = user->get_home_folder();/ z! G/ Q: e( \/ l% f( ~
}: E1 I7 M& |. z5 [! M& u
o New way
$ {6 B3 \1 t+ H6 L+ Z) D7 i) X// Declare the variables4 ]5 L/ U8 M8 d# d: L
Teamcenter::Soa::Common::AutoPtr<User> user;" n6 K! |- @7 ^# w3 q. v
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
9 {& ?( o( V8 W1 Z8 T/ f6 oTeamcenter::Soa::Common::AutoPtr<Folder> folder;. w, c' [! h7 }1 @! a0 y. |
user = sessionService->login(name,pass, “”,””, descrim ).user;( Q6 P0 M9 P" v% g2 O
// Cast to the base ModelObject class
4 e$ E, Z. ?# G6 u0 g; ?4 L# Z& ~anObj = user.cast<ModelObject>();
) G2 L: a1 ?5 q# B- n" F/ [// Put the cast to a speicfic sub-type, in a try/caTCh block
' d1 D# `4 ]3 t3 ~' l/ Q% k6 w& h9 z// if std::bad_cast not thrown, then cast was successful
/ Q9 Y7 q! Y, ctry
( a. R% X1 Y3 L' n- B2 t{
  {# I( I. C9 Xuser = anObj.dyn_cast< User >();( m1 l( ?* f9 m8 O# w" o7 ^5 J
folder = user->get_home_folder();
7 X' m" b0 X3 s1 g}* R- d1 q+ d* f: ]$ b3 Q) Z
catch(std::bad_cast&){}' P. `1 p* n. N' U* M, y

" I* a% @7 f+ }8 a( B& U; {/ q2 n8 j1 B4 R# t( O
3 关于NULL 赋值
3 m' V2 K' b/ j4 d* F- s# W+ p" R7 k3 u7 s* T- u
o Old way8 v) y* m1 y; u* [/ U
// Declare the variables
$ @# V# j* Z9 i0 _. ~. ?LoginResponse response;
- E. K3 M& j/ \% q) k6 E$ TUser * user;& p2 V5 m/ N$ O  K0 m* B. X3 N- O
// Call a service that returns a ModelObject (User)1 }- H1 W" `: X8 u! t# \
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );/ d: e  ?3 M% m# U
user = response.user;' i' T$ _! K9 \% t! B+ D$ S
// Test that instnace against NULL
- w7 w; s3 a: n( |0 o9 X  n* G+ {% z) N, fif( user == NULL)  m9 \! j7 A2 j% _
{! ^+ S, F0 o2 R6 ]4 p$ Z
...
1 a! H, j# I+ C1 G}1 p. y- G! i% g' X  K
else) G4 H/ a) H! J' H: s8 h4 j- l
{+ X! i; V! a, Z4 l4 U" o! V
// Assign NULL to the pointer! |, D2 \- c% M: d+ a- }
user = NULL;5 ^4 P/ a) g8 @* @, m1 G: ^4 T
}
0 D4 W+ W6 }$ u; Mo New way! L3 e  G4 x4 G5 w+ Q# @* H' m: W
// Declare the variables
4 F' |" \6 n# l7 N7 |% d// The service data structures do not change, only5 a1 p- A. d1 g& |. a8 P
// references to ModelObjects
. L  P3 c( J( A  C. SLoginResponse response;
# S3 O6 c" I0 b- |! a7 e7 dTeamcenter::Soa::Common::AutoPtr<User> user;" H/ T4 [0 O+ t$ O
// Call a service that returns a ModelObject (User)
: |, \4 l! b1 Z( e) k1 ?4 ?response = sessionService->login(name,pass, “”,””, descrim );2 z3 n1 [7 Y# T% M
user = response.user;
, D, y5 M3 I1 P/ M+ B// Since we are not dealing directly with pointers,& b7 K# G5 z; ^
// NULL does not make sense here, use the isNull method from the! w- W/ C* z: S
// AutoPtr template class.
* D; ~6 y* \/ g0 c1 D, Iif( user.isNull())
' s4 H; f/ {& d7 H/ |, l7 J{
6 d+ ]5 }0 y7 O# K- v# I" \: r...
2 s, @0 t% c  y! B5 @}
* g" Q  ~1 A  @6 F- l$ [% l; _! Telse( C% h: _9 k; E5 W+ A$ J
{: ]; G5 t* u2 s& {: u
// Release the instance and
4 d+ p* k' {( J/ s* Iuser.release();
4 ~$ |/ x& O; f$ i2 c}
' e" n& h, h/ P( g/ `
8 Z5 x% l) M. I
4 H/ _+ I' B0 h; c
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 doTeam.tech
回复

使用道具 举报

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

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部