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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式, C; c0 p- G6 d; t/ M# v$ g* ]4 e3 Z0 o
0 X0 z8 L5 e  k/ e2 m7 D

) e0 u* k& x( L5 C1 变量声明- ~. }  n/ u+ l3 A- i5 H

- ^# U- n/ N/ s, @  g# Y7 N5 a

3 n. O" R4 Q( H7 zo Old way+ u" m. `& r- m- g. \' u6 K
// Declare pointers for an Item, Form and vector of ModelObjects6 K& z) ?/ d1 D- S. s5 z0 e
// initialize to NULL
* \* i7 k" d0 n/ S/ J% I; F4 |9 Q7 fItem *theItem = NULL;( j7 ]3 [0 }% n% S5 F/ Q) T
Form *theForm = NULL;4 X! G$ l& d+ w: @) }% p: y
vector< ModelObject *> objects;
# K; h- \; V, r0 F% P" Y9 X...
9 J" R$ W! B: m2 X  v& C// Use the Item3 w/ A4 s& x# o: A
theForm = theItem->get_item_master_tag();' l& G2 m- g- J) h  ?5 T+ ?% I7 W
objects = theItem->get_revision_list();
; D5 S4 A  R) ^o New way/ T# N  T$ L% P% O
// Declare AutoPtr for an Item, Form and vector of ModelObjects- m2 v# `  u( y
// all AutoPtrs are instantiated as NULL
2 B7 B* R3 E  U/ LTeamcenter::Soa::Common::AutoPtr<Item> theItem;' a- `! u/ p& s& m4 ?5 d, L
Teamcenter::Soa::Common::AutoPtr<Form> theForm;( C$ D  A. C+ K& D; I! z+ r
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
( W' f5 v$ F1 l1 ^// Use of the ModelObject variables remains unchanged
' u+ d8 m# q1 t$ L& JtheForm = theItem->get_item_master_tag();: A* Z4 F$ R3 ?0 M) H8 X6 M# g+ l3 Q
objects = theItem->get_revision_list();
# M2 D) }$ Q8 t4 X' W7 f
; `5 m% @9 l* [7 j, M5 N# a; E
( u7 X: H0 }7 o8 _4 U- U% T+ _2 类型转换
9 H- j: X+ S6 r
: t5 g8 ]% m9 X$ |& vo Old way
3 O1 H  J6 Y; Q# R3 _// Declare the variables* ^7 y. _$ _% Z; o0 w
User *user;2 s' Q0 m- @. r
ModelObject *anObj;! g4 X/ ~# D& U
Folder *folder;
6 ?3 e1 n5 U) D( u8 A# huser = sessionService->login(name,pass, “”,””, descrim ).user;# p; z+ C, E2 W( E% O, ~) W& |
// Cast to the base ModelObject class+ v3 M$ R) m+ D  H3 g; F0 R" q9 S
anObj = (ModelObject*)user;; B2 ^+ p) a2 ~% k- C
// Cast to a speicfic sub-type, if not NULL' m1 n6 C2 d% I' V- J3 e
// do something with the new pointer
: I; f5 N! L  m& `2 U7 Buser = dynamic_cast<User*>(anObj);$ D: v! _" i; C$ N# s0 @
if(user != NULL)8 J# {2 Z' s  y; [1 c( Q" w7 Z* O
{+ s  x! L7 O' n' }( z+ U! W/ {
folder = user->get_home_folder();4 b8 W; \  j- l4 S: o
}- S! o# P. }: D8 R  R
o New way
; y( {" F" c$ s% y5 h  K7 ^. t// Declare the variables- j1 v- c6 Z4 @1 p  @* {( _8 V: N6 ^
Teamcenter::Soa::Common::AutoPtr<User> user;
, V  P$ \" a+ G9 }$ E* l" }  WTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;% i% u; G( l1 v! s  X; @+ f: {  K
Teamcenter::Soa::Common::AutoPtr<Folder> folder;
& f& K2 f8 w# y# y: quser = sessionService->login(name,pass, “”,””, descrim ).user;
  v2 z1 f' M+ d' @// Cast to the base ModelObject class6 g8 f. R: v- u! p* N* J+ e+ m
anObj = user.cast<ModelObject>();5 y$ y, n/ G1 C: u( F7 c
// Put the cast to a speicfic sub-type, in a try/caTCh block
# D4 K: J+ u$ A// if std::bad_cast not thrown, then cast was successful
0 ~4 c0 |/ Z3 V& stry
8 ]' G8 p6 e1 J: e; C. b" a  d{
. E( I/ d7 c. N: }user = anObj.dyn_cast< User >();
" J1 @6 \8 N+ z( M  zfolder = user->get_home_folder();9 o6 X; \9 T5 z% h
}' [% {/ U6 ]# U& G* w; A1 ?
catch(std::bad_cast&){}' M# f6 }0 ^5 b1 c
9 @" y, T" \& ]0 n5 E
2 a! G: `1 e* r( ^# a8 D; W: n
3 关于NULL 赋值
) d7 N3 v, G8 @6 k3 J- S4 }/ G) w) |1 Q" T/ H
o Old way
* O; w9 A3 T% T. |2 v) d) g// Declare the variables( r6 `( Y0 Z6 D
LoginResponse response;# l& L0 ?* d1 T4 r9 i: O
User * user;
' V. L' O& o  g0 b0 M2 Z// Call a service that returns a ModelObject (User)1 B( J0 ]- S) N+ T  H" t2 L
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );* t  o( c0 Q/ u' f
user = response.user;! K& I9 Y: \) N* l% h7 s/ B
// Test that instnace against NULL3 z; S% H9 d& j5 t9 n# {1 `) ]
if( user == NULL)
" o; W" \0 J' T; @8 L{4 [1 p5 ]" t. S- Q+ G" x0 G
...
7 r: w4 N) K8 \9 I% |}
8 F& y; E5 z" |% t2 Y0 J/ felse
3 Z' z- O6 a* O. @. \1 a# x{5 ^. ?2 R4 p% s3 ^
// Assign NULL to the pointer! \" R8 F/ D+ ^# A6 F0 Z* k
user = NULL;
' s3 j8 }4 j, f9 d- @: ~9 d}
, p5 `* y8 s2 V+ c- uo New way
  L* I5 ?: a0 G// Declare the variables: d- i( P6 [6 Q/ e
// The service data structures do not change, only% C2 B1 y3 i7 s' G3 Y
// references to ModelObjects3 @! c8 h& C" _5 T0 k: ^1 K
LoginResponse response;3 M% \8 u& @6 I  G, T; U
Teamcenter::Soa::Common::AutoPtr<User> user;
. X) }1 o( b& F// Call a service that returns a ModelObject (User)
% ~  B9 P' E9 O4 q% \# uresponse = sessionService->login(name,pass, “”,””, descrim );
. i& E( ?; n& Nuser = response.user;7 I. s" V- F# m2 Q
// Since we are not dealing directly with pointers,( o4 k8 K( M9 X$ d/ K
// NULL does not make sense here, use the isNull method from the
8 N: m. A# ^+ ~( p// AutoPtr template class.; }9 d, z6 q0 T0 p, `2 n7 c$ Q
if( user.isNull())% v& t- C$ ^/ k8 b2 x
{: `! r9 b: H% h7 X& R8 c
...3 y& }# j; o7 D2 W5 I
}
* h9 k$ @+ r3 j' x3 j9 `0 ]3 Oelse) D9 S) \% |, C  {0 k7 h. C0 ?
{
$ E& r5 G/ y7 c9 t1 Y// Release the instance and
1 g* S% w1 p% ouser.release();& F- C/ G: j5 h# T& @
}8 D$ ?3 [( k. s2 e

3 X$ D- e! N- s7 t

- J# w3 A- H' B
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了