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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
/ U1 ^* M$ g/ [
. `7 I( q, F/ K1 U5 y' O4 |7 R4 Z

% }7 E  I' ~$ Z" a& K1 变量声明
+ [! I; s" O, P1 i& J$ }$ m8 C+ S' ~

) V# h: s  o1 ^. q3 a0 {' ~( R8 ~o Old way' i7 S4 ~) r) w4 f
// Declare pointers for an Item, Form and vector of ModelObjects" i3 ^" e& R* t' ?
// initialize to NULL1 i! z9 E5 v# V5 N& L& M
Item *theItem = NULL;- G. |& C# [9 f& c8 F0 O
Form *theForm = NULL;
4 ]' y7 \: L1 G6 l7 t- P, `vector< ModelObject *> objects;
, S! c$ Y5 W7 ~" B( x; z( z...
" M. y8 O4 n1 Y! c) O3 P// Use the Item1 i! n. y7 T& n
theForm = theItem->get_item_master_tag();
* Q; Y% A9 v7 I- E/ a& N3 L% Gobjects = theItem->get_revision_list();7 s7 e( p* S  u9 }$ M3 W
o New way0 o& l' b  T) r" @
// Declare AutoPtr for an Item, Form and vector of ModelObjects0 f2 D# \) f3 m) u1 ~7 q7 a5 @
// all AutoPtrs are instantiated as NULL5 R. u3 w  P; z" s1 Q) w' H9 j+ e+ l
Teamcenter::Soa::Common::AutoPtr<Item> theItem;
1 [/ t+ S* z' l  n3 N1 i& aTeamcenter::Soa::Common::AutoPtr<Form> theForm;  _( B5 v' J, o
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;
( {' n/ |% l; a0 N// Use of the ModelObject variables remains unchanged+ j7 O( Q& Q8 V: ?& h
theForm = theItem->get_item_master_tag();; v* n3 h" N' B+ o  E
objects = theItem->get_revision_list();
" G, h+ I% O* ?% c' J. \  N
1 ?7 ~3 |, f, U/ x/ v5 V: B7 e9 \9 q; P& P6 q
2 类型转换 & [5 r# M  i" r, _# G
0 r! ^) f" H% f  q4 g
o Old way. l& G, P2 |& A& Z9 ~
// Declare the variables
' z* M  ^* [3 R- d% \User *user;! H6 g8 A. u4 h) p5 c- d  Z% P
ModelObject *anObj;/ p& N: ]/ @& g, ~3 [( O0 O  e
Folder *folder;
- S) Y+ N0 u; h  }: N6 l7 k% Puser = sessionService->login(name,pass, “”,””, descrim ).user;
) B2 M  ~3 r, C6 R+ O// Cast to the base ModelObject class. K# U8 F- u  d) `) T! u0 G
anObj = (ModelObject*)user;; V6 d8 o: n4 ~1 c9 S1 E
// Cast to a speicfic sub-type, if not NULL
* D3 N% \* c, [/ T// do something with the new pointer
' t: _) g6 M9 m1 V. {( m3 @; E6 s9 kuser = dynamic_cast<User*>(anObj);
  y2 H: `) B) F2 r( wif(user != NULL)$ Z% d# Z+ Q3 N) m6 P% K% S
{4 x5 T4 @3 r  q- U: O4 c
folder = user->get_home_folder();$ S# s, c2 F3 ]% R  L( m: i! Y
}7 W; _$ Z" d! H# Z, J( d
o New way
. _% T- z$ p! E# ~, E" a// Declare the variables) M! }0 N4 t: S8 }
Teamcenter::Soa::Common::AutoPtr<User> user;
8 k1 D7 h; M6 m3 s9 g6 n5 sTeamcenter::Soa::Common::AutoPtr<ModelObject> anObj;) B# O$ L4 `3 U
Teamcenter::Soa::Common::AutoPtr<Folder> folder;& ~6 Y0 {, R) u, z0 B9 C0 X
user = sessionService->login(name,pass, “”,””, descrim ).user;7 K& }6 N4 V' D  `
// Cast to the base ModelObject class$ n/ k/ c9 ~  p; a
anObj = user.cast<ModelObject>();
6 ~) S: L9 u( E3 w// Put the cast to a speicfic sub-type, in a try/caTCh block
6 l% f! J' c- U// if std::bad_cast not thrown, then cast was successful
, i+ K# P9 p7 ?* c4 Otry
! Q: e, z- `& K- Y0 y2 Q* o{
+ e3 o/ M# i# y/ y6 [: Q) l; b4 A9 Wuser = anObj.dyn_cast< User >();. [5 D# k/ p1 N& O6 h
folder = user->get_home_folder();
6 j( u+ b- b) H& Z) v}
# b) N8 x0 i) d' o% g, j3 h. d' Ocatch(std::bad_cast&){}
  W, H' @8 b9 x/ y+ F  Y6 u$ Y: k0 p* o7 U) M$ x
: ]9 C: g, c! {; v/ B8 Q, m0 t
3 关于NULL 赋值
- A; Y% P1 w8 `6 b+ T" @1 j  o; t3 y( Q9 \9 B
o Old way
  j4 }) M; r3 Z- v+ ?4 P" ?// Declare the variables
4 G0 I3 N7 ?! T% T) N. nLoginResponse response;: G- p$ N" k4 H
User * user;
7 t+ d" c7 N' }+ s6 S: t0 C// Call a service that returns a ModelObject (User)
8 y8 v$ ]3 o# g; A; x5 P2 G/ r1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
2 s% n3 m: ^# o" A3 F6 f1 {+ k7 Vuser = response.user;
0 J1 {" l% @0 t. H* O' k( ^// Test that instnace against NULL, S2 H0 o8 s0 d+ ?% k; r& _8 v
if( user == NULL)
& ?8 C7 P0 [  ?0 ~/ |- j3 d{
: F' z1 N) \. D4 O...
" L! @/ K$ E/ o. }. S, [: Z* y}' _: n! W/ l  H4 W
else
3 A  g" w2 Q4 e) y5 ]: k{' q( r1 o1 S8 b  J. D
// Assign NULL to the pointer
$ P5 k" ?% L, v# `1 C8 muser = NULL;7 E# ^! c, a( @/ U5 t4 d
}
' L" l$ K& q8 L- po New way: v+ X7 M9 k- D' T
// Declare the variables
' |% T% [6 g& J3 _+ L" z// The service data structures do not change, only1 `( }  C) h7 K3 m5 U& V
// references to ModelObjects+ T- M$ g( w' J0 X) O+ J' i/ p
LoginResponse response;$ l5 X. `, F: T5 D0 @
Teamcenter::Soa::Common::AutoPtr<User> user;4 S7 D/ ^' I: O7 |% ]
// Call a service that returns a ModelObject (User)
7 C$ l: G2 o9 p9 @- N8 nresponse = sessionService->login(name,pass, “”,””, descrim );: Q- n1 h1 _0 \/ A$ s  C2 p* M: T
user = response.user;8 f4 ~& s9 O' V/ L$ Z& ~
// Since we are not dealing directly with pointers,
. l2 O3 _* s: I* K# h6 U. n9 w  ?// NULL does not make sense here, use the isNull method from the" Y4 p4 l9 V  [( R) l
// AutoPtr template class.5 Q1 q4 a  H0 H% I
if( user.isNull())  j0 c) B- l! y
{
, t$ R5 M  l  u# o: R, O9 ]...2 |4 a- m( I% _# m/ ^8 b3 b
}8 q" T% M  m8 r6 l/ V
else. n& f* @) F2 h, ~1 A' T
{' ?6 O% f$ O$ j. q3 h
// Release the instance and5 A8 g! p  J( o" W; m, n: E! s
user.release();' Q) u: v0 T) L" u9 O& [6 J
}
% M) P/ F2 d# _! T& v9 |3 S9 q% B7 D6 V! C: y% G- K

( J+ D: j6 }8 n6 n7 o/ l& G- {
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了