PLM之家PLMHome-国产软件践行者

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
) B  Z$ B/ d6 a1 F$ ]2 x
% j* m% ^6 l5 x( ~4 E, s4 A

) g. b4 ?6 J( w, W; }8 B% R1 变量声明, q( S9 Q/ T7 P
7 B$ F* O! p' A( I# o( }" v0 e
2 W5 d0 c3 Q0 r9 E1 ^
o Old way2 L+ j) ]; r. `: ]7 j# d
// Declare pointers for an Item, Form and vector of ModelObjects2 R" z2 M: N/ Z: |. ^/ [
// initialize to NULL
6 Z" c: `* ]" Y% O- rItem *theItem = NULL;
9 X4 a9 E' r1 G% E# A8 fForm *theForm = NULL;
+ P0 B% V) D8 l) j" Zvector< ModelObject *> objects;. K+ h% l, c; h+ ]6 ?; X
...) U5 s* L( p3 ^! b( o) M
// Use the Item, E+ T. ]  _' u
theForm = theItem->get_item_master_tag();: g- b% t! ^2 ?
objects = theItem->get_revision_list();
  D# b" }1 b6 Xo New way
" D2 I  t% @' _// Declare AutoPtr for an Item, Form and vector of ModelObjects; \5 Q7 T  `# W- q7 ~% E- X
// all AutoPtrs are instantiated as NULL
, s9 y* A/ K# j+ ^' j+ UTeamcenter::Soa::Common::AutoPtr<Item> theItem;
0 u% g' ^' I  ?1 oTeamcenter::Soa::Common::AutoPtr<Form> theForm;6 D! }5 W" t' B. B& T( p3 K# t
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;  i7 K; _2 T" F. k: I7 ~& E* Z% Z: }
// Use of the ModelObject variables remains unchanged
4 n# G* b% I, a% x& E" BtheForm = theItem->get_item_master_tag();
1 o' a4 ?8 C- ?objects = theItem->get_revision_list();  O. f+ E0 F. c1 b
- e3 x4 x+ c, e1 F' |7 A5 M
! n, ^+ V& y& [
2 类型转换
( A. V6 {' `( F
  D% X9 a* w6 V1 J- I  V. ?o Old way, z; p& P/ c" \$ Z. f/ k0 Y8 c, C
// Declare the variables
7 T" l  b9 f; uUser *user;
( B! t5 Q; N* \, \: gModelObject *anObj;+ g4 d0 j( B1 o
Folder *folder;
0 ?6 o8 T* S4 Q: euser = sessionService->login(name,pass, “”,””, descrim ).user;
, _4 a: g& b' E& @% b// Cast to the base ModelObject class
/ K4 m5 v" ], o. O+ _4 manObj = (ModelObject*)user;
7 |" j. @7 Z. K7 k9 P3 O9 w// Cast to a speicfic sub-type, if not NULL
  W! Q; m# P2 D# [) L// do something with the new pointer: [8 \* L  a* Z' c0 Q
user = dynamic_cast<User*>(anObj);# K/ R5 M* y+ M  v" y
if(user != NULL)
/ O' {. N0 F) \1 e{  ~# t: Q6 D1 i2 B
folder = user->get_home_folder();
+ d$ X: M6 d' x: [1 F' a* J}/ ^) Q' N+ c% p+ d  {
o New way
8 y3 d( ?0 l) g& d) l0 w$ D// Declare the variables) E4 {9 X: N5 r  P0 @
Teamcenter::Soa::Common::AutoPtr<User> user;
0 }, c$ [) F" T8 r% X* T* DTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;6 O+ p, M- I# j: j  Z2 K
Teamcenter::Soa::Common::AutoPtr<Folder> folder;# y, C9 n4 b- H; l! a9 e& V5 _
user = sessionService->login(name,pass, “”,””, descrim ).user;
  o( ]( f. W# a  u! Q% n) U2 `// Cast to the base ModelObject class3 k% m  S' v- p9 C4 e- |& w9 F
anObj = user.cast<ModelObject>();
; v5 V- L* }) }- Z// Put the cast to a speicfic sub-type, in a try/caTCh block
4 ^) ~+ _0 ]( G' H0 l4 n3 @// if std::bad_cast not thrown, then cast was successful
- O* ?$ z' x% S9 a, Q/ stry
' V# a( m- S2 Z! g6 y+ F( E{
. \: ^' \" d* F! Ouser = anObj.dyn_cast< User >();5 X: d( E6 x0 |. B
folder = user->get_home_folder();
* B; B( a3 ?" s' T1 p' Q4 ]* o! M" u& s}: ~! {, g- j5 S1 T
catch(std::bad_cast&){}
( U  e. d( y4 a/ x% x+ M1 V  h- R& E6 T- x& {* [

& q  Y% T  ?1 S# ~2 I9 B. [3 关于NULL 赋值
+ }1 G, i1 K1 h; C, @% u4 j8 Q' [4 {2 _/ y5 g
o Old way
* F4 y& {# G, }// Declare the variables
% b1 S5 X! M9 r8 p+ U4 yLoginResponse response;' g# z$ x& O) T  V) \; t0 d
User * user;
& S: d6 b4 C- C' W2 z0 `/ L3 h// Call a service that returns a ModelObject (User)
$ q6 D/ o4 D5 L( [, O% I- T3 c1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
6 X9 u+ D0 h# Vuser = response.user;- M  u# g2 J: u& c, v% ^9 C
// Test that instnace against NULL
4 w% y; z% @( R( `" gif( user == NULL)6 n* w+ _/ {1 s. ~
{
# h1 O( ?3 B/ z, p; `1 t...
* {' m6 ~4 h4 Z: b( c" M9 i% W}
8 z% J8 r' g, Yelse
* O0 q2 n: E! d6 Z& J2 C{
3 ]$ z% h' z+ D% _, ~% a# K// Assign NULL to the pointer' o3 l% i- o4 S9 u9 Q5 l4 n& `' f; h
user = NULL;
' d3 \) M& F2 P7 a" \7 B}
+ X! T8 w: y. n$ k) B  Zo New way
0 K1 R3 D8 A) T4 H) K// Declare the variables9 |( g$ v3 h: j( K
// The service data structures do not change, only
3 {& H. \. P) ]& c) i$ C( @2 v0 L// references to ModelObjects
- E) @0 }+ S+ R: b; P. n# X3 [" NLoginResponse response;
& n4 D; |8 X0 O4 g1 eTeamcenter::Soa::Common::AutoPtr<User> user;* u4 G+ c/ f2 q9 @* c
// Call a service that returns a ModelObject (User)
( ?7 \2 C) w3 U8 Uresponse = sessionService->login(name,pass, “”,””, descrim );
7 d7 o. C; s. G7 M6 p7 ^1 S; i6 \user = response.user;
$ r5 L/ g5 f* e// Since we are not dealing directly with pointers,
1 f# L( C& e+ T$ I2 ~3 z// NULL does not make sense here, use the isNull method from the8 X- D$ f) v* |& t9 m
// AutoPtr template class.2 I0 }3 G" P( w) }" j1 P$ W
if( user.isNull())$ U2 z- l  h& T7 G
{
/ r* l8 ^; y, e& h...
9 X& W; b# b3 ?+ u2 z8 R) u}
/ h/ p/ m8 D$ jelse3 T* e% f& Y4 n& G) V$ m0 o, W; b7 E
{$ W5 w8 K; `% |2 `" H/ `  }2 O4 x
// Release the instance and$ R( Q- G3 |# t! j
user.release();. }7 K; c4 H5 n' r* w4 G6 q& t0 A
}
# ]2 H+ Y9 Y" Q5 k/ ?' J/ M' U% @( m2 I3 u

. a8 E; K/ I' c+ x0 e2 X0 h
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了