PLM之家PLMHome-工业软件与AI结合践行者

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式. I- U' b6 O5 i3 g, s

0 a- L6 V+ I1 P2 M0 x% v. p

2 W4 z' c8 C) N1 变量声明$ k+ e" t7 Z  J' T6 Y# f* u" k" B: P

6 ]: I# ]0 @. a6 f6 H( g9 o
$ X3 X# D3 y; H" E9 o
o Old way
, \2 f' E* X2 G2 k0 R6 I- G% m// Declare pointers for an Item, Form and vector of ModelObjects
+ B7 [( N! M. W// initialize to NULL7 B$ t9 F8 E7 l- [" K+ @0 _" M  M
Item *theItem = NULL;! G  ~2 l9 l7 q. O+ i/ A
Form *theForm = NULL;# b# r+ C1 W# Z! D+ U
vector< ModelObject *> objects;
) B) l9 s5 J; U% R2 U5 ~...
' D2 B3 |) t, ?3 K8 O// Use the Item. s& U) U2 y) d( F2 q
theForm = theItem->get_item_master_tag();
8 Y" ]: b2 Z! @8 }1 O$ I8 M" p! oobjects = theItem->get_revision_list();
: v% A7 H! _" ?& T; J" x0 [1 j+ to New way1 S! n4 O+ L- `- _7 B( m) c
// Declare AutoPtr for an Item, Form and vector of ModelObjects
# Y, p, G. {, |. Q) t// all AutoPtrs are instantiated as NULL
" t  j9 v- ?) c6 B# s' ~Teamcenter::Soa::Common::AutoPtr<Item> theItem;$ C. J- D- H; y' t- I6 M
Teamcenter::Soa::Common::AutoPtr<Form> theForm;
& m2 C- {& @; |1 n; uvector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;9 c  h: R: J7 t  q. t0 p* T
// Use of the ModelObject variables remains unchanged
8 G# Y; }2 ~! ltheForm = theItem->get_item_master_tag();
/ N% V3 d2 x, V, z( n0 Gobjects = theItem->get_revision_list();
' Z8 \" ?% i9 b/ u) j! R! H& ^
+ e" W) J; l* `; H7 N  F
& l/ s& t: K5 h) e1 o1 g2 类型转换 . v% S2 j0 @) p: \: E6 e! {
0 h- j# f  V% f9 H
o Old way6 b8 C4 P) I, y- B6 s
// Declare the variables1 J0 l) x( J0 W& L7 H9 K
User *user;( P) d3 m5 y( q, @1 p  o; s
ModelObject *anObj;
  }9 I: V3 X  P% @' z  w# iFolder *folder;9 a5 Q2 z" z! I6 q
user = sessionService->login(name,pass, “”,””, descrim ).user;! I0 y' X. M; T$ J
// Cast to the base ModelObject class! B0 Z* n7 [& Z) F2 T; D1 X+ l
anObj = (ModelObject*)user;* p) S$ `% q1 Q) |2 g% D% m
// Cast to a speicfic sub-type, if not NULL
* }7 F+ ^. G. P% T! r& A// do something with the new pointer
# E# V1 j! x5 H; xuser = dynamic_cast<User*>(anObj);5 H6 M9 z# U6 _6 E7 E# f( D, O
if(user != NULL)! O/ C( V  m8 e+ @
{
8 ]3 y6 f8 p/ ]( k* ]- rfolder = user->get_home_folder();+ C& n0 `( W0 C! W2 e5 `& ]
}
% c" G7 c0 V" q$ R8 ^8 l* ao New way* A0 b. F1 ~; e# f7 x9 @6 n
// Declare the variables/ B7 H- R8 r& V' i
Teamcenter::Soa::Common::AutoPtr<User> user;
) x5 g. @& _( Y7 `' @" mTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;! s* Y. G9 r7 D
Teamcenter::Soa::Common::AutoPtr<Folder> folder;. O+ q6 P( r  L! ]: f% {* E' n
user = sessionService->login(name,pass, “”,””, descrim ).user;: ]" H  C. Y( M8 M' I
// Cast to the base ModelObject class0 D5 b0 S- u+ ]  C! n3 Y( q
anObj = user.cast<ModelObject>();
; D) K" D4 j; S% y& p! ~9 |9 e+ G// Put the cast to a speicfic sub-type, in a try/caTCh block
% ]/ ]; M+ R  F& [  M) H7 b- G// if std::bad_cast not thrown, then cast was successful0 E9 b/ ~; p) [
try/ S' T! k4 A3 @8 Q5 y8 C2 S+ @1 N
{
  f; L' f3 @7 Y1 [# O& f# yuser = anObj.dyn_cast< User >();, Y1 I; J$ S: f! k9 y
folder = user->get_home_folder();
7 x+ i4 x2 c/ n( T5 p}
& T' u4 i  N$ ~8 e9 ?7 X6 Q2 Gcatch(std::bad_cast&){}
% F5 Y- j9 b9 h9 |# J& c. ^* {1 J; p( P! a
% L) B( x- U) }  G" y1 x- R
3 关于NULL 赋值
$ z0 n* |. B8 G7 U- X) x  W9 N4 E( u; M& t
/ H) l+ J! N$ f' Oo Old way
& Y2 l8 o2 \: A. [0 ^; T// Declare the variables
2 ^. I/ e2 G' y" j1 Q: @LoginResponse response;
' g, {4 O' |; X6 A% w+ JUser * user;
  Z! J6 V* I2 }4 y* C; W7 G; C* w// Call a service that returns a ModelObject (User)
6 c1 m- w, Y- ?- {6 [1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );7 I/ F" ~8 }% l
user = response.user;
7 y5 z' g6 X1 j$ z1 d// Test that instnace against NULL
+ N( M! C0 p, z! ^6 v( Wif( user == NULL)
/ v& R8 l0 a8 X; z" \( a{. O$ z/ k8 H% R1 [" n' ^  @" d! ?
...
( l' w3 P/ M4 C1 C1 n/ U}
4 x: {% c* y" k* x: A4 ~else
  Y0 ]% U3 E" H' p8 \# q{- r1 Y0 C' @# A! S" x- P
// Assign NULL to the pointer
  Y3 S; Q1 Q1 Iuser = NULL;
1 N# H1 p- a1 X) T}7 B# k! D6 d8 g! E0 g& \6 x& j
o New way  P: Y7 k/ ]( A) }( K! B0 n1 x
// Declare the variables
; Y% M- ?+ o3 ^// The service data structures do not change, only9 E* E% }5 Q- M* C* ?0 ~. l, e
// references to ModelObjects- G& i4 G5 c+ {) Z
LoginResponse response;! l4 ~: O, T9 o/ G8 x$ H1 n
Teamcenter::Soa::Common::AutoPtr<User> user;
+ C2 z0 W: q6 S4 t, f5 z4 P// Call a service that returns a ModelObject (User)! w) V; y2 |, C$ C) k0 x9 ^0 M
response = sessionService->login(name,pass, “”,””, descrim );
" @8 t. r/ [2 {" ^5 s8 y& \. Y% Guser = response.user;
9 `6 U7 ], l$ \0 v9 B// Since we are not dealing directly with pointers,
2 C8 G. r+ [8 U4 \" B// NULL does not make sense here, use the isNull method from the
, F$ A) L; f- N( a4 {. K: N// AutoPtr template class.
* q+ c3 d% c+ L1 Dif( user.isNull())
. O5 M% v' w: `; b{! s/ T7 O: v8 Q" ^! u4 _' T
...$ G; x. d, _7 o+ k# ?
}
3 }% a/ u9 L* selse
% }/ B. `7 o6 J% i) P0 i{
# d- h" p2 u7 a4 Z- F$ h// Release the instance and
9 Y- g8 ~0 E/ b7 puser.release();
8 J0 e+ \& Z! @6 C/ X4 T}
7 f4 r1 p( P( j" h1 [+ Z
5 E+ L2 p- [) F/ d
$ [' b; t( a9 z4 s/ R* p
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了