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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
$ f1 l, a' u( W8 G! |3 t% ^$ y5 ?% h

; S; q  w3 E, `* U6 M1 变量声明' w% Q( e; P) \5 b$ `0 y
" H1 X' `+ I! V% I1 [; H$ m* x
+ o0 a4 H2 y9 L/ n9 Y# v
o Old way. A3 x0 {5 k3 O8 E1 E& ~) k
// Declare pointers for an Item, Form and vector of ModelObjects  x& \  x: M# ~5 D# }+ D  a$ R
// initialize to NULL
# p) D& K, z7 N& c5 v/ hItem *theItem = NULL;
/ U, I+ Y0 V: A  U0 D4 Q7 iForm *theForm = NULL;& Y: G3 G% R5 r! h( C
vector< ModelObject *> objects;% O4 D: `8 F2 N. ?" I2 l, F& q
...( N. |, {! I, d+ _; o7 D9 T* F: |. X
// Use the Item
9 _( V& A" |; `- c  E3 [* GtheForm = theItem->get_item_master_tag();# T2 z3 ?" z# S6 x; a. H& f6 [
objects = theItem->get_revision_list();
7 L$ _, l4 ?# Eo New way
/ |4 l* y$ F2 D: X! L3 N  H// Declare AutoPtr for an Item, Form and vector of ModelObjects. F; a; y! G0 A
// all AutoPtrs are instantiated as NULL
, R3 H0 ^6 \8 j0 {3 {Teamcenter::Soa::Common::AutoPtr<Item> theItem;
0 e4 N0 F- E7 X4 _Teamcenter::Soa::Common::AutoPtr<Form> theForm;; f! j# t/ Z+ Z6 H
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;  O3 A# q# r- _
// Use of the ModelObject variables remains unchanged
0 Y) ?1 o# g0 C1 ItheForm = theItem->get_item_master_tag();
! c& {! ~% d5 L% A6 Q8 W+ L- H$ S) I/ Q0 eobjects = theItem->get_revision_list();- F: v9 v  e3 a8 y

$ ]( E# k* b/ k8 T
0 ?2 s( M3 F# {+ e6 H: p/ @; F! W2 类型转换 $ Q6 x6 }& q# l* n+ h
- b7 I/ V4 A" }" |6 N& }- `3 W
o Old way* s0 \- v* m9 ~$ D2 k
// Declare the variables
; D7 m% {2 w$ SUser *user;
' Q6 [& f  G# _, ?( n8 @* rModelObject *anObj;% ?8 Y+ Y+ H3 C# E
Folder *folder;; D4 j7 @. X; T% v: J& }+ w8 C5 _
user = sessionService->login(name,pass, “”,””, descrim ).user;4 J5 Z. D. Z" R8 ~. f0 b* ^
// Cast to the base ModelObject class$ k9 A4 [5 k* M; m+ l
anObj = (ModelObject*)user;/ H1 N7 `5 `. P+ Z; z2 s9 }
// Cast to a speicfic sub-type, if not NULL
9 G* Q0 i$ z# i// do something with the new pointer
  v( L, m* E" R  f$ Q  Ruser = dynamic_cast<User*>(anObj);2 E) C4 _! n0 a1 ]) j. y
if(user != NULL); J+ J. r0 C0 N5 x( ?9 o
{$ z/ s& A9 r5 b0 \! c
folder = user->get_home_folder();
, c0 B) ]" D1 u6 J" T4 D2 X}& G0 r1 t7 c7 T1 o! g
o New way  v# Y6 X/ f; {( z
// Declare the variables
2 n' \+ [" S; Z: PTeamcenter::Soa::Common::AutoPtr<User> user;
8 C- ?8 Z* b( p! k& T! r2 a+ }% bTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
  F7 x5 V0 b. t5 _; @/ b  w5 mTeamcenter::Soa::Common::AutoPtr<Folder> folder;( l" l+ N$ `7 b/ L0 {3 ]! x
user = sessionService->login(name,pass, “”,””, descrim ).user;
& }0 T+ }; Q& U* H// Cast to the base ModelObject class/ g: J' [, ]. I1 v2 P
anObj = user.cast<ModelObject>();
0 Y; r1 j# N$ g// Put the cast to a speicfic sub-type, in a try/caTCh block3 W! h) j. K3 [$ a* e; f- }* y
// if std::bad_cast not thrown, then cast was successful( R( C6 v7 R/ J! K- h( r
try
- x' H  I: ]" m+ |0 Q5 D0 }0 ^{
2 x, D' F( w, suser = anObj.dyn_cast< User >();# ^2 B. O) w1 W/ h
folder = user->get_home_folder();
* i* e9 n. v: d; u}1 \9 L% r5 h$ f' S& f! z3 f
catch(std::bad_cast&){}9 ^  E# y: L5 }8 g. ^% L
+ G" u! V5 D" j4 B6 m2 L0 L+ g0 t
) \" h  u6 k+ U6 U" f
3 关于NULL 赋值
% R, S6 Q) J: f1 C! a5 y
! f) R8 `' E! C% V7 v1 No Old way' J- K0 C- N7 r
// Declare the variables: t( l7 j0 Q* h4 A/ l
LoginResponse response;' |/ _: e" z2 z8 ^$ e7 R5 k/ f
User * user;; u  d! u% H; h  |9 T$ x  d
// Call a service that returns a ModelObject (User)
- A) C% S& H+ o/ Z1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );8 m* H. L3 C- u
user = response.user;
. l$ j* @8 N7 Z( k4 u// Test that instnace against NULL/ G3 e$ p* K/ x) U: F
if( user == NULL)4 E) l& P1 s/ P: q+ W5 o
{
7 h  G& d+ {: q2 M...
, F5 T% P  a; F: ^; h}
( O( z4 q) q/ ]4 P* ]else. `" }; O" V- E9 B
{
9 m3 I8 d. o' G3 Q% y// Assign NULL to the pointer' P# J% N7 x% c, d$ ]
user = NULL;" B9 ]4 m: Q8 K/ X  w" M0 A
}
; g+ C4 S# o7 u0 `! r) xo New way/ w1 k/ n2 j& f2 K
// Declare the variables$ S7 F$ y  i/ p
// The service data structures do not change, only
6 i6 m# b. [. O// references to ModelObjects
) y& q( w. \5 H( D0 i) v1 a$ yLoginResponse response;
3 s1 Z. ~- Y/ o) u" @Teamcenter::Soa::Common::AutoPtr<User> user;
' a7 ?9 {: B. k2 K" q+ o/ C// Call a service that returns a ModelObject (User)
* j. c+ c3 I4 m3 B. L7 yresponse = sessionService->login(name,pass, “”,””, descrim );- ~" v: h) D7 _: G4 y
user = response.user;6 M) s2 p5 a3 R
// Since we are not dealing directly with pointers,) s" N5 J$ M4 |9 ^0 o
// NULL does not make sense here, use the isNull method from the: y3 P( I! D( K5 p0 Z( Y/ w
// AutoPtr template class.+ t9 G1 V" l; t7 o3 C8 h4 L: v
if( user.isNull())2 _  e& {* b5 Y8 Y1 K, ]  _
{& \+ u- I% U( y
...1 G1 [( v) l4 J! ?. e, O
}
. Z& Q. K" B& \' d9 N+ Aelse% w; ?6 C, r6 d; J/ j
{. O/ T: T$ s) j; [$ J7 C
// Release the instance and) J: x2 p8 g* o) H* X/ H
user.release();
, |2 ^: }2 r4 A( l1 w! n% S}, s1 H) c) {8 @  M- \

+ r7 Y, x  |' p+ M/ I- J$ [5 \

. m( Q  Q1 h& n" i! X1 ~7 N$ 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二次开发专题模块培训报名开始啦

    我知道了