查看: 4045|回复: 0

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

[复制链接]

6

主题

4

回帖

60

积分

管理员

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

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

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

×
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式: i8 k3 a6 ~" V* k# Q* T8 v) N# r+ a
7 }, j5 v* G* J" l4 L
$ o7 j  ^/ p& X; O& A" _
1 变量声明6 ], I* F& S' k6 d; `

( F( J3 ?/ m% ~3 m. u- E  o* ?+ m
3 g, |% G6 P; W# U
o Old way# Z5 C, h( q0 v4 M$ p* o
// Declare pointers for an Item, Form and vector of ModelObjects
( N8 x) Z" ]6 f// initialize to NULL
: q2 z6 c1 o5 b8 cItem *theItem = NULL;
$ C; [8 F% S. b7 \Form *theForm = NULL;
" Y& x+ Y1 u, ]) A0 _vector< ModelObject *> objects;! V; e, T+ k' Y" }. A3 E% U4 ]
...: x1 y; H! @2 x0 l7 v) n; M" @
// Use the Item, C8 \. T! Y+ E
theForm = theItem->get_item_master_tag();
2 b8 _& q0 U& f0 Q/ Xobjects = theItem->get_revision_list();7 D4 u- p* S2 p) g5 Q9 P7 _; U
o New way! z: t0 O' e4 H2 j
// Declare AutoPtr for an Item, Form and vector of ModelObjects6 m6 T4 M6 P6 x2 Z) Q0 }+ _
// all AutoPtrs are instantiated as NULL' q# J; L7 }; M# l; ^
Teamcenter::Soa::Common::AutoPtr<Item> theItem;2 S9 A9 r7 p) O) n" {! Q% ]
Teamcenter::Soa::Common::AutoPtr<Form> theForm;: x" M! p7 ?" T, m8 M0 r/ ~. e5 F+ t
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
) \$ @; p5 |" `" |// Use of the ModelObject variables remains unchanged) O7 K2 t6 ^- k
theForm = theItem->get_item_master_tag();
/ \/ \  N: q8 U2 L2 W* b& Vobjects = theItem->get_revision_list();7 Z$ e4 @! ?- _/ N; F4 X
2 K6 u: m/ a' c6 S

  R( b' [/ c$ [2 g, j) U2 类型转换
4 a5 n: H$ R- j6 K) J: r! z- }( F; p1 k% O' u0 J' f
o Old way
* J* G, S1 q( w2 V# o// Declare the variables: E9 s- i8 @2 A& T
User *user;% W* A% Y0 ^% j/ @( G
ModelObject *anObj;+ X) O; p* ?  L) T) @" Y! y* h
Folder *folder;
3 Q# P* |9 n* b$ cuser = sessionService->login(name,pass, “”,””, descrim ).user;( b. z/ }; q: z% x4 s
// Cast to the base ModelObject class
2 }7 j+ g$ w6 N! Q5 ganObj = (ModelObject*)user;
* o8 ^" G5 E$ Q: L& ^' T. I$ B// Cast to a speicfic sub-type, if not NULL5 j$ a$ q3 A2 P0 F  t
// do something with the new pointer
% F9 n! M! m% r" l7 \' ?user = dynamic_cast<User*>(anObj);8 T1 X; w5 Y; u: O
if(user != NULL)+ {! x+ }, X: T* r6 ^8 N. u
{
: G4 N; c5 d: }  s5 ~0 F. b4 xfolder = user->get_home_folder();
5 K! I( Z) @: \2 A1 t}; c) V6 w5 ^5 D! V* k
o New way. N+ z4 ~0 `! c# g6 q
// Declare the variables! w+ S/ P! W. q$ x, ?: d# A
Teamcenter::Soa::Common::AutoPtr<User> user;% n7 W, W+ \. w! f) l4 d, I
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
& |3 k7 S( G, HTeamcenter::Soa::Common::AutoPtr<Folder> folder;
1 Q  Q0 J9 [/ q2 \* Vuser = sessionService->login(name,pass, “”,””, descrim ).user;6 a5 }8 G' Y( I3 k
// Cast to the base ModelObject class
5 d% w) E8 H; N% _, ZanObj = user.cast<ModelObject>();  n' T1 ^. @. s" H, f
// Put the cast to a speicfic sub-type, in a try/caTCh block) }( }5 Z# A  m
// if std::bad_cast not thrown, then cast was successful
9 ~  G. v( b) \& ^8 y0 F7 r$ F7 D% Ctry/ S+ A. Q  o$ d# G, X
{
. v, G3 A8 D0 R" }: I1 ]9 L) S! G( Fuser = anObj.dyn_cast< User >();1 x! }1 ]7 l2 o! N7 z1 r% h
folder = user->get_home_folder();. }. n. d, X0 y- r6 X, _! @
}% L& I4 ~& u. [/ b
catch(std::bad_cast&){}
& Z9 Y/ x( k4 ]& ~4 n0 Z6 L* Q9 n2 r; F0 Z

* i# q* Z0 y& Y2 ?5 Z3 关于NULL 赋值6 n) k/ q! w; o

% `* Y" e3 s: z: Ao Old way
' Z  w( @8 ^0 v( ?- }, n// Declare the variables
0 ^( c2 ^0 k7 J! Q" i) DLoginResponse response;3 M" r5 @7 V% D2 M! `
User * user;
% @1 B2 m  s7 _2 c( g$ w2 M// Call a service that returns a ModelObject (User)8 t( ]; e! o' O, f$ P- [
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );" P0 [$ n4 N4 z" q1 H
user = response.user;. Z& n8 f' r; B3 `$ O2 P
// Test that instnace against NULL" y. [* X# J+ O
if( user == NULL)
$ A3 q5 M% X$ N% G( l* z) U{+ S3 s5 e5 X6 }5 {& h- l5 O
...
  l3 S9 c0 b) ?1 W3 X1 f6 L0 Q}
) b5 G  t$ g: {5 ~; H$ f9 Uelse
, v+ _4 o! s1 v{7 z4 }& a2 Y- E, m
// Assign NULL to the pointer  K. A( u$ F$ @) {( u1 p
user = NULL;0 [1 z; Z3 C5 ], v
}- X( {8 ~0 a& V! S
o New way1 m  F2 k# h7 }5 j8 `
// Declare the variables
" }9 M; s) d% ]+ k// The service data structures do not change, only3 q( R/ g7 I6 g- P4 f2 }
// references to ModelObjects4 R$ e, s( K% Q* Y7 x0 u3 F) a- X9 g
LoginResponse response;9 Q! K) T3 f8 p+ e6 K6 i0 e
Teamcenter::Soa::Common::AutoPtr<User> user;, ], p9 A$ J# M, L2 h0 ?
// Call a service that returns a ModelObject (User)
  O2 e- G/ C( p3 P  t, H3 Oresponse = sessionService->login(name,pass, “”,””, descrim );
( ^% [- R  J) ~, ?user = response.user;' t4 }9 o5 @3 B+ e4 P0 J
// Since we are not dealing directly with pointers,
- n8 A7 _5 n3 n1 V9 B  X// NULL does not make sense here, use the isNull method from the
8 r! w0 g/ Y8 a) e, K// AutoPtr template class.8 a! K8 B. q! Y2 b
if( user.isNull())
; J9 F( q5 ]7 F% X; _{. Q+ t4 k3 j. i) `: F" P8 w
...
5 m3 v3 E- p/ B2 s7 d$ S/ a  a}- O1 }* e" S( M% d3 B6 Y9 w! z9 ^
else
- u  l# @& E& T$ H0 V6 n6 V$ o, U{
. U1 y4 [4 s0 L" h' F7 P// Release the instance and+ B; d& r: O4 }
user.release();6 ?: l. c6 R2 C6 z2 D, q* w
}
( Q, [, Y. e/ u9 e
5 G: c9 j# c5 O$ F, {% t% o
2 a; d0 M) ~! U! _4 Y  p1 |+ Q. r
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

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