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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式% g1 ?9 n7 I/ H- Y. E& u
' o* L* M6 h+ m0 A& Y

3 s# o( t3 y! p1 A& L' W* @1 变量声明1 x7 y7 r" v- v
- q" @7 Y* I1 c! X! f+ V/ O. W; d

4 X3 J6 c/ u2 j+ J' W: jo Old way( \2 Q% c+ m0 x
// Declare pointers for an Item, Form and vector of ModelObjects8 }, d* c7 ~9 ?, H
// initialize to NULL
. O! F% c$ a3 b! ]1 uItem *theItem = NULL;& i/ L1 |1 Q. i9 A1 x1 K# T
Form *theForm = NULL;4 Y5 v% {; X" K6 r' g0 S/ {
vector< ModelObject *> objects;* [, U1 d7 u3 u) Q( p) t- Z8 ]
...: Y5 m) s+ N. ^# ~/ B6 [
// Use the Item8 }) j1 `* o& K8 [0 h
theForm = theItem->get_item_master_tag();/ y1 d1 ]: t8 P9 i
objects = theItem->get_revision_list();
5 ]) O. u! @' i- G& L7 ho New way
# G( q, q# _& o/ p. ^5 V; Z, Z" h// Declare AutoPtr for an Item, Form and vector of ModelObjects! A# b& Q7 E. F4 `. A
// all AutoPtrs are instantiated as NULL
7 d& l( b5 `, `  a$ \' x8 @Teamcenter::Soa::Common::AutoPtr<Item> theItem;
* Y6 {+ @% M) }. a; h6 {Teamcenter::Soa::Common::AutoPtr<Form> theForm;- r2 E! r# }- K- z
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;4 R8 \! n% t2 |1 j( q- a
// Use of the ModelObject variables remains unchanged( k) H5 w1 E. \' F3 ^
theForm = theItem->get_item_master_tag();
  J9 z! a2 C* B# qobjects = theItem->get_revision_list();
6 I" W* X2 x/ f: S3 R4 d/ ~( O7 }( a, o2 u$ Q( J

1 Q! _/ s9 D( V! R9 [( B0 y2 类型转换
4 F' |% q9 ]+ e: q* W& x, J5 Q  ~, h+ ~0 s
o Old way3 U9 J7 K$ \& A  r- v: ~/ _
// Declare the variables7 @& l9 I& G1 X7 ]
User *user;
: G) ^. A2 I$ H5 e+ xModelObject *anObj;
8 r4 X! o+ H' t3 [Folder *folder;
, t4 q! Z4 l7 F1 l0 p8 W1 uuser = sessionService->login(name,pass, “”,””, descrim ).user;) s9 t1 G+ B7 R4 _0 A/ b
// Cast to the base ModelObject class& c; d6 _, c, L5 u/ h; ~6 K4 r: m
anObj = (ModelObject*)user;+ L* l+ ]  @9 Q( M! M; Q9 z
// Cast to a speicfic sub-type, if not NULL
1 X5 J% z) N1 L7 c/ r. M// do something with the new pointer- t+ f& M7 G9 b. K. J
user = dynamic_cast<User*>(anObj);+ n- S% e, i% o' m$ p
if(user != NULL)2 s, X  O+ i: }" s+ q6 e1 a( S
{6 a% E+ T+ u- ^6 G6 j
folder = user->get_home_folder();
' b6 `1 k* S! r  p7 S}
) a. i' C8 Z2 Q1 i* `) ~o New way# G( [# D" h, k# e" p
// Declare the variables
$ [" a. r2 s3 n# h0 BTeamcenter::Soa::Common::AutoPtr<User> user;0 o5 y5 [) U+ r6 D0 e9 W- V
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
1 _) y( x6 m& a6 A. XTeamcenter::Soa::Common::AutoPtr<Folder> folder;
% i* D9 M) |$ g" Euser = sessionService->login(name,pass, “”,””, descrim ).user;9 K* q7 S2 k: Q' y8 o$ c7 b" M
// Cast to the base ModelObject class$ [, y5 R1 k, f3 `( Y7 ~2 |4 D
anObj = user.cast<ModelObject>();
( I: r% `- u: Z5 S// Put the cast to a speicfic sub-type, in a try/caTCh block
1 `, J  \( q3 E// if std::bad_cast not thrown, then cast was successful
, K- z- b7 Y- I7 e0 ]# Ptry
5 {4 [+ C8 N, D9 j0 _7 {/ ?6 t{# @& Q2 m& i0 X) ^) f: n! F' [
user = anObj.dyn_cast< User >();
  i# U$ A: b: Vfolder = user->get_home_folder();" I0 w# Y( _- S% n1 i  P$ Q7 X# E% V
}
. B4 E/ {7 g9 Y4 \; C8 n$ b& Ycatch(std::bad_cast&){}! l. ]2 f; G% ^+ l( G
# r% J1 I4 u9 Y- d
4 F- T) K; @9 s1 _6 `$ x
3 关于NULL 赋值( a4 a% E, ?! Z4 o

- g  B* l( s/ y$ Lo Old way
- n8 Z& W) z% i1 c9 s( H// Declare the variables
5 T' G5 L) k) ILoginResponse response;
* D" }) J# k' R: c# bUser * user;
" s* C' B' ^2 v! F' ?* M// Call a service that returns a ModelObject (User)
2 H  m3 T6 ?# v1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
5 l! U* I& l; c/ X! p' Quser = response.user;
6 Q; _* c- X% M  O( t0 O( t// Test that instnace against NULL" n+ ~5 Y& c% l  K7 f$ M
if( user == NULL). h; k! ~! b, e
{. ^1 [- Q5 A# \9 i, s. i7 x
...6 }$ N* }# k' t7 s2 [
}7 P) Q6 E$ w5 Q- x4 R/ K, z
else
8 }8 g) p& U; p% f4 c3 q{3 ]- v2 Y1 @# W8 d' e) Y, L5 i$ u
// Assign NULL to the pointer  |* p! ~) y! L/ Z  i. u
user = NULL;
# y3 L$ ]- R% Q4 l# y}
$ T3 o/ S/ B, @1 U2 A5 Uo New way5 U3 q& b0 R( }5 j. a  l8 e
// Declare the variables
; P" ]. q& P* w9 W- f' ?// The service data structures do not change, only; K. }' ?" ~, ]1 X
// references to ModelObjects/ d9 j% \+ U) e  C  p: x
LoginResponse response;
$ {  [6 ~  F3 R% \9 N( f' a( uTeamcenter::Soa::Common::AutoPtr<User> user;
3 q* G) n% X4 Z" q// Call a service that returns a ModelObject (User)
, ~5 x4 p) ]0 Q- uresponse = sessionService->login(name,pass, “”,””, descrim );/ ~$ y6 b; A# W6 I( x/ w  N0 Y
user = response.user;
4 _# m& H6 k# ?$ `// Since we are not dealing directly with pointers,
- [  B) j2 I3 g$ ~% u3 {, E// NULL does not make sense here, use the isNull method from the
& a! \+ g% z5 H) \// AutoPtr template class.4 W/ R8 {8 g" E0 T
if( user.isNull())
7 ~* R$ W" k  t$ r$ g. O{
* j: N3 b8 m( |: g- `: S...% p4 j6 v$ }- u- {
}: f0 |& k0 a$ z4 i* v
else
7 s3 d6 H( {/ h{, C, U7 {: V% }6 ]8 |% H. H
// Release the instance and* r3 T4 f0 }/ X6 `9 W
user.release();
3 k5 \. Q# E. C& Q}
$ ]- h1 I8 Q) s& }8 t* v0 L/ M6 k
3 \' r! O" ^7 t. B9 B
3 T$ q3 E. a5 j3 v8 Y
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了