PLM之家PLMHome-工业软件践行者

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

[复制链接]

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

2471

主题

1276

回帖

8万

积分

管理员

PLM之家站长

积分
82191
QQ
发表于 2015-2-3 09:18:14 | 显示全部楼层 |阅读模式

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式$ h8 ~+ |$ r+ @7 c( Z1 X
2 T- Q/ j* |6 w5 K4 {$ @) a
- l/ y) r/ v$ ~7 G
1 变量声明7 _- ?7 b# s0 p! J1 G
4 d' {, c7 H. z$ s( ]4 X+ F8 j

7 \9 V: n+ a! x0 a9 Q6 Qo Old way! V# ]3 \& X; N( r* C+ }
// Declare pointers for an Item, Form and vector of ModelObjects
! z  j4 z, R8 q// initialize to NULL- L  X4 p# z( w2 D( P- l
Item *theItem = NULL;
8 \3 e( p3 d8 q% S$ s( GForm *theForm = NULL;
: h, y) Z% `0 {$ y& hvector< ModelObject *> objects;! ^6 X( A' ^3 A
...' i8 D+ g8 C8 p' M
// Use the Item8 h0 |- B. z/ v7 g1 L8 \9 H
theForm = theItem->get_item_master_tag();( E+ D% {2 ~0 w) I0 V2 ^) Q
objects = theItem->get_revision_list();
) B1 P. L1 @$ @( ~o New way
3 I4 f# q- Y( K2 H// Declare AutoPtr for an Item, Form and vector of ModelObjects
. a. T3 X0 r/ o7 a// all AutoPtrs are instantiated as NULL
( S7 o$ a: ?# t( O/ mTeamcenter::Soa::Common::AutoPtr<Item> theItem;
" ~2 R4 H2 X9 U+ d! e$ z$ V4 b0 r* HTeamcenter::Soa::Common::AutoPtr<Form> theForm;. q* l5 ~, o( ^- v/ Q" F# F5 N
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
" d; s& c: B0 H3 r& u// Use of the ModelObject variables remains unchanged- v0 T7 V# n  W
theForm = theItem->get_item_master_tag();, W$ f. ~7 b6 B" ^+ U6 y
objects = theItem->get_revision_list();% o5 m/ y1 Y5 K+ x
$ h+ s7 y+ F. d! a! t, U  C

0 r4 h% q8 `$ ^9 h0 _2 类型转换
: i1 l- e2 Q+ o: H
3 ~3 ]; {( _  w  s% j. t3 \o Old way5 d  P/ J# T& C& G$ T
// Declare the variables5 l" t1 Z# N1 n2 r' \
User *user;
( ^9 _* o9 p( L8 _; }! ?ModelObject *anObj;
8 B' w' P2 o: _Folder *folder;0 d0 A* k: m  c1 ~, Q; ^6 m
user = sessionService->login(name,pass, “”,””, descrim ).user;
, ^1 @6 {; S- i2 K4 j1 w) ?5 |// Cast to the base ModelObject class
2 y' I. u% J  O$ d* x! @anObj = (ModelObject*)user;
% M  T4 Z2 ~$ Q- d/ e( ]: J. [4 B// Cast to a speicfic sub-type, if not NULL
* i! F+ U/ _7 H8 @9 x! t( }// do something with the new pointer- c) [; {* m) C* k5 a4 v' Q! n
user = dynamic_cast<User*>(anObj);
" C& l$ n4 _; M8 }4 z" Aif(user != NULL)4 o) y6 Z) I/ I5 w( c0 \* J# b
{
9 [/ ?! K* B2 T1 V6 c2 @folder = user->get_home_folder();; R+ n5 ~0 T2 ~$ B! p( N3 f6 |
}' R" d/ z5 y, @
o New way
2 C/ [: }, R& r- j6 Z4 \+ R// Declare the variables
& @; [+ [# p) J6 Q) z1 i; d6 KTeamcenter::Soa::Common::AutoPtr<User> user;
, i/ y5 W+ f/ P: z$ }5 t0 aTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
& S7 R- B% }9 `$ sTeamcenter::Soa::Common::AutoPtr<Folder> folder;
$ K$ ~: p5 C! f: F: k; F; vuser = sessionService->login(name,pass, “”,””, descrim ).user;
4 F* o5 @2 _* `5 q1 y// Cast to the base ModelObject class
: t. V; j/ Z/ ?! zanObj = user.cast<ModelObject>();
, ^6 O  _7 f5 t// Put the cast to a speicfic sub-type, in a try/caTCh block6 n9 D' D; Y8 u; ~
// if std::bad_cast not thrown, then cast was successful
7 K2 \& r  B  U* c! }" I5 \try
) _% K( X1 ~" n5 p6 }. p{, _  h$ K6 j. {; i. R6 J# h) w
user = anObj.dyn_cast< User >();
" S- C6 R7 H4 Y0 e' _- O. v" w$ wfolder = user->get_home_folder();+ |& U% i- i. w( h* p2 s- u
}
5 R/ t1 u+ o/ p1 M. Gcatch(std::bad_cast&){}
4 _3 J# Q  {1 ^- v
: ^& d3 N4 r( x+ S# G3 B+ ?1 A
9 _8 Y( x) f- p1 J  _1 o* c' h+ J4 D8 x3 关于NULL 赋值
( [9 X* `; e# t! P' q. }
0 m& t$ ^- s/ r- S/ t1 Ao Old way% Q5 @( h% d1 F& W% N
// Declare the variables+ S# P+ b; ~* {0 l9 N4 I" _5 ]
LoginResponse response;3 u3 b/ N8 @  ~7 G2 z4 Q. U) W" p
User * user;
9 q3 O* N' O$ F& t0 m7 p// Call a service that returns a ModelObject (User)
6 }: U* W$ n* G' ]1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
, e1 g" E7 C- ?9 M3 Duser = response.user;& X4 b2 Y2 H7 b4 @- X
// Test that instnace against NULL
' `# x1 X" ~6 d* Iif( user == NULL)
# P9 P. @  H/ q1 ^* k+ _  w{- c& R  J$ U; d4 f
...
/ n8 X( r; A4 I# Q# _8 ~3 X}2 _  A0 q* m# p% O1 b" f
else
# f6 ?! H+ d! Q/ C{
4 X! x: K7 T/ V" A8 k// Assign NULL to the pointer. U& z+ H7 ~( `& ^
user = NULL;2 A% S% `1 f$ O) t
}2 @+ `- X6 @; j: _) p( }- I
o New way
; X# r) Q  C3 @3 b/ \// Declare the variables
% l9 l) T5 C' M// The service data structures do not change, only- F. G' h4 T1 z& j! ]
// references to ModelObjects6 j( z) T! Q5 J1 Z6 N5 U+ m/ n
LoginResponse response;
4 U7 o1 t, ]; f9 Q0 v* j$ o5 hTeamcenter::Soa::Common::AutoPtr<User> user;
# z3 x# I1 G2 x! `9 p( @// Call a service that returns a ModelObject (User)
4 B, e, q+ Z3 L7 y- Eresponse = sessionService->login(name,pass, “”,””, descrim );4 f9 A1 H( M8 v: X
user = response.user;/ Y) }6 W/ B4 u/ e8 y4 y7 |% A
// Since we are not dealing directly with pointers,
7 {1 J$ r# ]5 @% N/ a* r// NULL does not make sense here, use the isNull method from the
8 b4 a4 |% n7 m9 o// AutoPtr template class.8 M  R# F7 |$ W5 ^6 k+ g
if( user.isNull())7 `3 @4 O& \5 v
{
8 O2 P1 j% G' l6 y4 _3 q...* P7 e" L/ h$ q4 K: ~5 h: X
}
! g& ?9 ?; Z5 Z& D2 I* e, L3 Eelse
! ~; X3 d0 Z3 i7 y; e& x: M{
% y& B( F- b+ c: a6 m// Release the instance and' l- ]1 T4 M/ f/ A' C- G/ m5 F9 B
user.release();
. w7 Y. V" C6 B  {3 h3 a2 {$ c0 A}6 a, x2 `" R: u8 b
5 W0 q  g0 @9 s! O
5 G; K, f5 t3 I. V6 ~7 `
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了