查看: 3952|回复: 0

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

[复制链接]

4

主题

3

回帖

48

积分

管理员

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

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

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

×
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
9 C+ e' v3 C) m/ x0 r3 _
, D3 ^& ^* t& g4 ?8 C

7 T/ C& w. G* T2 V) k. F/ V1 变量声明) O( \( @) `+ N# P$ P
' ]  {1 \8 v# R* v2 y' J8 w
' W5 `6 g; e, _) k" r  I
o Old way  ]. M  J1 ~- i
// Declare pointers for an Item, Form and vector of ModelObjects
: k' @+ q+ A) i7 V+ K// initialize to NULL, a  U5 G+ H/ F9 Y
Item *theItem = NULL;( |+ k" ?' p7 w" t2 y
Form *theForm = NULL;
( h/ M9 Y! y, U9 C" u; z0 wvector< ModelObject *> objects;
9 Y2 r5 y% m* x+ A: Z! j# J...2 {5 T1 i+ f* P
// Use the Item
6 s  r& f( c3 ]( h1 t7 B7 h& jtheForm = theItem->get_item_master_tag();
% `( Y" T, X9 \$ Z* L: H# W- ?objects = theItem->get_revision_list();
$ M; M) d5 |& x/ y9 po New way: h1 Y) l" q3 R8 K. G4 l" N# T
// Declare AutoPtr for an Item, Form and vector of ModelObjects4 P9 C3 P  u# M; Y4 ~2 t+ x$ T2 ?6 Z+ _
// all AutoPtrs are instantiated as NULL
; T& K  ~7 i- ZTeamcenter::Soa::Common::AutoPtr<Item> theItem;
7 D3 z! y3 r7 t6 _2 s. zTeamcenter::Soa::Common::AutoPtr<Form> theForm;
  E7 r+ v9 W* E1 ^# ^vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;+ G8 [' T7 b# s( R
// Use of the ModelObject variables remains unchanged
4 F( t  j8 t8 v1 ?theForm = theItem->get_item_master_tag();2 C8 |  g2 g' V. B
objects = theItem->get_revision_list();5 o, [9 W) G. F7 p* N. h9 b6 o3 w
! L9 s, c  e3 \# N6 s8 g) d
( K4 _  @$ Y/ H% R5 A
2 类型转换
) t& _6 x% l# Q: [0 o1 |( [) c  X7 G8 z" K4 ]# ^
o Old way
$ h4 o& u' a1 {5 m1 [# P// Declare the variables
" J  F* w! b4 z0 b/ Q5 k3 Q5 AUser *user;4 h" U( E1 P* i8 K
ModelObject *anObj;! o0 b7 S* W/ O4 \( s
Folder *folder;
5 N: C6 S% I, l; T; M' ruser = sessionService->login(name,pass, “”,””, descrim ).user;! v3 |; z2 Y+ r  P
// Cast to the base ModelObject class/ g* q. w+ t1 K) h+ ]
anObj = (ModelObject*)user;
+ [7 M0 F2 M( B6 u// Cast to a speicfic sub-type, if not NULL
5 y! f1 K! o5 L// do something with the new pointer- G9 B& a6 @: V1 \& j
user = dynamic_cast<User*>(anObj);+ d3 w6 K4 W6 T  ]2 H
if(user != NULL)
! Y3 K0 Y: P/ P{7 ?* R2 E, r/ c4 X5 f
folder = user->get_home_folder();7 u# q' k4 i' L
}
/ G: [; H2 W4 {. Uo New way
3 _+ E# ^/ F8 D// Declare the variables& M: T" E; J- [5 `
Teamcenter::Soa::Common::AutoPtr<User> user;* Y) j6 Y  x3 i1 w
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;& R$ j% S# w4 b  {% q! D0 w
Teamcenter::Soa::Common::AutoPtr<Folder> folder;
' M# D$ k& d+ p4 ]user = sessionService->login(name,pass, “”,””, descrim ).user;
8 f; v! E6 I* k# Z# L// Cast to the base ModelObject class
  w+ N0 M" n% w- R4 tanObj = user.cast<ModelObject>();
" `& J$ @2 |2 g// Put the cast to a speicfic sub-type, in a try/caTCh block& h) p5 ^+ R% B6 V* {- T0 n
// if std::bad_cast not thrown, then cast was successful- K  \  ]3 D0 E3 B' C% b% u. ~& R
try
7 Y) ^- Q6 e! j" e( N! v{
  v+ I' t; w$ B% kuser = anObj.dyn_cast< User >();$ m' v% q2 M! {: x) w
folder = user->get_home_folder();) }% E9 a* w# m! Q1 S- N6 c3 n6 ^0 m" E
}& g1 B4 q2 E5 Y
catch(std::bad_cast&){}
' y8 x5 c, Z8 ?' g# ]; h( s
* C( i+ B, y! h+ J9 K( g; z  T4 q/ O3 n( p7 X& `( k
3 关于NULL 赋值
! }3 [% Q. R: m1 N) Q( E" e  W
8 Z; Z( \' z8 ~; u" ho Old way
% B. h8 ?4 Q, O2 b$ M. R// Declare the variables
4 U# }/ i1 ^$ h6 Y" P1 GLoginResponse response;1 l1 T+ E. `: d9 \0 j- S
User * user;. \8 C0 p7 `: c( D8 `8 n7 l& R1 S
// Call a service that returns a ModelObject (User)0 A" y3 E5 {  m1 {, Z
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
/ Y! _! l& N1 z' z1 y0 \2 r# {) g' auser = response.user;/ c, Z. b, K  S: a. |8 d! c, L
// Test that instnace against NULL
# X. d+ e" R9 S" {( x# @1 z* f0 y- mif( user == NULL)% D3 ]0 O$ a2 l1 }  x0 K' Z) n. F
{
$ e4 p" v) ^; m# u5 G/ h. D( a7 }+ [...0 e$ V7 f% q" f7 [6 L
}
3 m3 o$ Y' i4 g2 A2 K2 Melse- x7 _0 \4 z7 {" U: X$ x. Z% b$ |
{
0 n  O/ o3 \. A$ s- T  d// Assign NULL to the pointer
- y) A& T* X7 `! i* @4 cuser = NULL;
" }$ ~/ }0 ~! m6 w0 R$ J4 {}, L# z& g3 O* w8 Y8 v* p( D
o New way6 ]/ ^& M: y  `+ u9 N
// Declare the variables# w- {3 e3 c8 _& a4 C: F
// The service data structures do not change, only+ c5 `" Z& U  m
// references to ModelObjects
0 i, [0 w; |/ k  s, w" ]% Q0 ]2 eLoginResponse response;
3 ~6 ^+ T2 G# p% t4 E5 }Teamcenter::Soa::Common::AutoPtr<User> user;
! A1 p  W; I" ?9 \: s// Call a service that returns a ModelObject (User)9 z$ Z' N) ~& a* C0 P8 d3 b# A, Y
response = sessionService->login(name,pass, “”,””, descrim );
& h0 v* {- `3 w; guser = response.user;
; E" X: Q6 }3 `3 {8 _$ o// Since we are not dealing directly with pointers,
: L2 Z4 e5 d! b; z# D; P+ k% U9 S// NULL does not make sense here, use the isNull method from the$ ~  h, {: a3 Q8 z
// AutoPtr template class.% O; j& Y2 k: n4 k- ?6 ?
if( user.isNull())
1 M/ I0 ?& O% D, g{
# \& N9 E4 h. {$ L- p# y/ L: ]& X9 s...
$ }4 }; }# m5 _% f. ~* U}
2 U: M' N0 J/ x: T9 z+ k4 _8 ]else
# k7 A1 ?- ~$ Y* Q) t" ^9 i{& u& L( D- j& s2 `8 i4 V6 v
// Release the instance and$ |& _" s- ?' E2 K9 w' E
user.release();
2 p2 g7 `5 l; M% ?& }" c2 j}
, Q3 j6 `3 a7 K! s3 _( J7 R) P: V' Y6 ~2 F' f; I5 ?
( G1 |2 i/ u5 q/ D" X0 T( ^
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

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

本版积分规则

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