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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
- t4 x) d& q3 G. s, A/ d! |/ f( }* h

! ]1 k) W# _* L# e& R* t1 变量声明
* d( Z* u* F; p2 [7 v2 |1 K8 f# m- k7 I7 H# [7 K, {3 {$ `+ _
( c5 u  a( g- K! w4 O, b! T( H
o Old way; c! M2 \2 Q4 R! C' a$ s
// Declare pointers for an Item, Form and vector of ModelObjects
: J1 R/ k6 A/ M$ a5 F// initialize to NULL: O+ K3 i- z( |. F" \
Item *theItem = NULL;
* L/ c& V* p2 t" C2 m# l5 _Form *theForm = NULL;  i6 [' ?9 z' y  e) e
vector< ModelObject *> objects;5 `2 u& t3 @# q2 _9 Z, O. {
...
1 @  V) C6 G# p0 v$ u$ b; ]( E8 w// Use the Item
# X  k" p/ @/ A: ?9 @/ p! BtheForm = theItem->get_item_master_tag();2 S% U+ M) `4 `  v0 W
objects = theItem->get_revision_list();
, `' a) S, J, [9 Lo New way, t6 o% @9 r  k% w' n- p6 ~2 C
// Declare AutoPtr for an Item, Form and vector of ModelObjects6 E8 D4 O# |5 ?3 s
// all AutoPtrs are instantiated as NULL# Q( c- w% z1 E5 t. w/ N
Teamcenter::Soa::Common::AutoPtr<Item> theItem;
2 W0 b1 Z0 u, ]. h/ zTeamcenter::Soa::Common::AutoPtr<Form> theForm;# L, J) Q! @/ E( J9 ?
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
4 K9 V/ ^% l& O6 K) P) Y0 K3 _4 a/ V// Use of the ModelObject variables remains unchanged
% u/ p9 W' E- r3 n5 Z: x+ NtheForm = theItem->get_item_master_tag();" D1 Y# Q1 ~) ~! v
objects = theItem->get_revision_list();6 b1 _+ O# r' j( T+ W; U3 q

7 G$ A: M/ Z% I0 k# S' b6 w1 z1 {/ J# ]/ O0 ?4 s
2 类型转换 * ]/ p% t9 m: m; \

3 x2 W. |& \! n& l+ `  l2 J: M7 Zo Old way1 O% l& B# B; Z! m. n: Q
// Declare the variables1 o+ Y+ q/ h) s  _8 _; ]
User *user;
+ l, k# H/ z8 q/ K/ W$ ^$ U0 I8 fModelObject *anObj;2 m, A, Q, t; h5 u! {  p
Folder *folder;$ w$ s# e4 g$ S, V& B! ^5 Q
user = sessionService->login(name,pass, “”,””, descrim ).user;7 u/ s7 g) c0 t8 @& ~7 w
// Cast to the base ModelObject class2 ?9 Y; t" y* O5 h% {
anObj = (ModelObject*)user;
2 U  f. c* n6 {$ f. ^6 Z* R( p; U// Cast to a speicfic sub-type, if not NULL
% j' r. w2 O6 b2 P) H3 V// do something with the new pointer* O% f3 ^) e/ O) I4 j- |; T$ ^
user = dynamic_cast<User*>(anObj);
# V8 D1 j2 u  O# i. @/ ~8 [5 s  y; sif(user != NULL)1 q  I' T4 L& w7 @% _
{
! b: ?# `0 ^8 q/ x6 Afolder = user->get_home_folder();
% _8 T4 _  X4 D9 Z! i+ p3 a}
- h4 z8 j; d6 [. co New way$ P) l! Q; u9 q4 f1 y+ l2 \
// Declare the variables
9 L& I2 b# }8 C* H* X9 i1 wTeamcenter::Soa::Common::AutoPtr<User> user;2 Y( M8 D+ v! c3 o1 L
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;8 ]* W) X7 v/ X4 @6 w# c
Teamcenter::Soa::Common::AutoPtr<Folder> folder;
# h  O* I' j* G/ Guser = sessionService->login(name,pass, “”,””, descrim ).user;
6 h/ |- x. I9 d, j7 z0 n, u. B// Cast to the base ModelObject class4 d! }7 q' e, w- x0 D! {. ^
anObj = user.cast<ModelObject>();% W) n% d5 ^1 o, E4 }9 G3 t% U
// Put the cast to a speicfic sub-type, in a try/caTCh block6 Z" X# R4 I: I0 o
// if std::bad_cast not thrown, then cast was successful& B8 }1 R& j4 L# n3 @" z
try
6 T5 x# Z( `1 h7 X' C7 Z{
6 ?& Q4 X+ f0 \! y8 huser = anObj.dyn_cast< User >();9 s3 l% B0 P; h7 b
folder = user->get_home_folder();/ y4 q' W1 q0 n" F5 T9 R
}1 O6 e6 U( p. v' `; V
catch(std::bad_cast&){}- t) l7 M) G" G8 d9 ~" G
. v8 _* n' Z) F1 L
! N+ x- j" P$ P, Z/ w. ?
3 关于NULL 赋值6 m- c) \0 |/ o# X# k9 Y

4 Y$ B& ]- n3 |1 to Old way
3 @. x2 E: v2 ^* v# g// Declare the variables# b7 v: F: o% O
LoginResponse response;4 p8 X$ R' D3 |
User * user;& \! E* l! d' H' q" @5 ?
// Call a service that returns a ModelObject (User)+ r3 `# I% S: O' P: H; Y8 x7 j
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );: w; Y1 i. C. K! b1 _+ X% f+ X
user = response.user;
- G. l* O0 H& x% S- @0 P// Test that instnace against NULL
8 T/ [& \, _" O6 V1 ?1 rif( user == NULL); h' Y; f& U/ k) X- R& ?4 r
{, l! B5 J* d; o. q
...; W7 Q4 c6 [5 f
}* M6 c" K$ N& u0 K0 y$ o
else
9 J; r3 ]* C' e: [; P{
. M, X: q" a% a* H2 }// Assign NULL to the pointer3 c& y" I5 o% t: `
user = NULL;( {4 h' l- X  q1 v! \! A
}1 l, S+ k8 T6 |" y  q
o New way% B8 e7 w8 Q) d8 d/ z
// Declare the variables' C7 U4 B! l9 b8 `4 x- h' r
// The service data structures do not change, only
2 f, ^4 D2 Q8 S9 J# D1 O9 i// references to ModelObjects; U3 E2 a' D: ~3 d
LoginResponse response;
/ J+ J+ Z5 ^- t7 K- F, S8 x4 fTeamcenter::Soa::Common::AutoPtr<User> user;
' N% i$ ]6 x' H) l3 s$ V: P4 }// Call a service that returns a ModelObject (User)& ^  E: s, N7 k0 ?1 i' e% ~
response = sessionService->login(name,pass, “”,””, descrim );) O. S& G, f  c  l+ j* `& a
user = response.user;
! G% J; r& X8 t  s- f& @' z! i// Since we are not dealing directly with pointers,7 h' N) ?3 k% |9 g+ ]  `7 x
// NULL does not make sense here, use the isNull method from the
3 B- z1 T' j- n- |/ v5 u* ?/ _* W// AutoPtr template class.
  A) U, V9 S: c% x" iif( user.isNull())
; f. X; }/ q! a7 G{; p; S8 _" H8 N6 M2 e3 U
...
) P" j# T$ f2 ^% v" _3 M, E}) J2 c" C+ O* Y4 E, W# m% z- J- p
else1 J6 ]/ X! q' R: O% }
{6 n. K2 ^, w' D' g2 t; }
// Release the instance and
1 K5 S& B) F* o- D% @4 g& Wuser.release();
3 s3 Y+ y' [, E' O. }8 A- {}
% }/ x1 D; T/ H, n: l+ {( a) X% X" k3 q. I7 U. ^4 P' U

* K; E& Q! X, P% p/ Q
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了