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

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

[复制链接]

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

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
& |$ w5 [$ N% o  U8 Y( V2 S0 t) u+ a" V

3 z/ t. Z: e1 b1 变量声明
( `9 J) {% H' |6 o- X9 u3 F) }& R* Y' U1 b( P

+ R$ e0 A4 N9 [( u  N- Oo Old way
& O8 }$ k, D6 r+ M- |// Declare pointers for an Item, Form and vector of ModelObjects  X% N4 X, \1 s( ^  W3 N
// initialize to NULL' |# I) V. v" F
Item *theItem = NULL;! Y. h. u* j8 G, R6 c$ ^
Form *theForm = NULL;" v. ^/ K8 q+ n
vector< ModelObject *> objects;1 Q6 G% X  V/ ~/ d9 j; _& s
...+ k. B3 C6 J" U" s# S/ D
// Use the Item
9 z2 j' Q9 F7 E- L) PtheForm = theItem->get_item_master_tag();) Q7 E& j( W0 t
objects = theItem->get_revision_list();4 M5 ]# \. L+ C! s3 S# b, N
o New way. L$ \) c0 s# B6 k9 V4 ~+ E% @9 H" ?
// Declare AutoPtr for an Item, Form and vector of ModelObjects
6 f0 J4 x& n4 E2 |- B; e// all AutoPtrs are instantiated as NULL
$ }/ r" ~- V  I; S: a3 ^- QTeamcenter::Soa::Common::AutoPtr<Item> theItem;
1 {6 g$ }) o# yTeamcenter::Soa::Common::AutoPtr<Form> theForm;
" y) C) M7 C3 Z  f+ qvector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;( i' `8 B6 Y) K: y. ~3 ^5 W
// Use of the ModelObject variables remains unchanged2 s" W6 R* i  u- v. O
theForm = theItem->get_item_master_tag();
* q% ^- E% Q8 k$ A' t+ r) yobjects = theItem->get_revision_list();
$ f8 Z& o, [7 m' P* X
' N  T* c  l$ g( L- d3 `5 x2 o7 Y, z! i7 j: v5 E# e
2 类型转换   n: @+ q' z6 I: E+ E4 f2 z

3 p( r: y% ~* ]9 N. A( l6 N  S( i% e7 lo Old way# q% c# _# T" e9 s6 m4 z
// Declare the variables
: H; r0 i3 Y0 R* k7 k0 xUser *user;
7 ?2 ]1 a( |' v1 }& mModelObject *anObj;3 g9 U2 G! f# G. }0 S9 W: C: ^! g3 A3 h
Folder *folder;
& y3 i2 T: n. Suser = sessionService->login(name,pass, “”,””, descrim ).user;, J; v" x% Z( X, X( z; \9 e/ o
// Cast to the base ModelObject class
) E9 O2 Y/ f, zanObj = (ModelObject*)user;
9 R1 f7 G1 N: y0 `// Cast to a speicfic sub-type, if not NULL6 \5 t, L0 ?  c$ D* o) g9 a5 c
// do something with the new pointer: X# Y; y  N$ B: n
user = dynamic_cast<User*>(anObj);
$ N1 D# i' _7 V$ s% v, Q8 Q5 Rif(user != NULL)1 B( G& x  G0 S4 U7 `( X' h1 R
{/ z. F% j9 Q% r0 E% _! O/ l
folder = user->get_home_folder();
/ c( ]9 s- h3 Z: _7 ~}. A. y; y& Q9 K8 q4 Y# M  C1 H( V; H
o New way
. \7 c) V# \, N( g( j// Declare the variables7 Y% M: X- p$ g. X! K8 v
Teamcenter::Soa::Common::AutoPtr<User> user;( `. |3 K! r: b/ r( E+ Q
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;3 u! c3 H! X+ _- A9 U: R- N5 j
Teamcenter::Soa::Common::AutoPtr<Folder> folder;
; c6 C5 N9 o7 \user = sessionService->login(name,pass, “”,””, descrim ).user;
5 {8 a. a( ?8 Z7 K  Y. c// Cast to the base ModelObject class
: P' c1 s3 \6 v: n' f4 r: L6 tanObj = user.cast<ModelObject>();
+ W4 t* e0 G3 E// Put the cast to a speicfic sub-type, in a try/caTCh block
  F4 P; s  L, N0 E3 \3 y; G5 ^// if std::bad_cast not thrown, then cast was successful
$ O2 o, p( k! ^5 G) `! |6 d! btry
( {) u. h! e8 k0 o0 P8 x{
: |! @9 S- w9 z6 K& a& H8 Luser = anObj.dyn_cast< User >();& n! S& ]& ~; Y7 e) N- L1 ~# t
folder = user->get_home_folder();
# l9 J1 ~3 N. n8 |$ r9 C}
+ O  j' h5 j& X8 [" C1 h* Ocatch(std::bad_cast&){}1 F: {" u' s1 u2 d3 G4 G5 ?4 b
; u/ W8 [& ~* A' A5 [

5 r; i' J( \9 W7 z& A% k3 关于NULL 赋值
' a: W% g8 g. \5 l: |9 r# `/ ?/ i! J$ q7 C, @
o Old way4 ]7 k. q. N; K
// Declare the variables
# w0 _6 U2 I7 G5 n4 f$ z8 v2 f0 FLoginResponse response;
. ]" p" q" u* G5 R# h. aUser * user;$ J. b# Z7 Q8 h, {1 |. k* g
// Call a service that returns a ModelObject (User)& d. b, K3 G  U
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );' ^1 {1 g) s- u! b
user = response.user;6 \! e* n9 ?! U
// Test that instnace against NULL
) w) m6 C9 X: ]7 O, X' a3 M. Vif( user == NULL)
# p( x0 s! ~9 \$ M' D7 W+ m{
, z" A, E; u  P8 p: T8 h1 P+ g" e/ r...5 S: E" |( d2 t1 \- f; O
}7 z2 C, W3 R; r& b; h- I/ n
else( h4 r* D' J9 l% n* p
{
# ^" l+ r# l2 c/ u5 M8 M4 t// Assign NULL to the pointer8 a$ u* e* z/ {9 v3 q& r& g
user = NULL;) I: Y5 h" {! C7 `9 f( k
}
- O* C# o2 P6 l+ u, D8 ]o New way" ]. o. ?* ?  E2 G% i2 e2 x( w
// Declare the variables. d, |- L3 U" F: E7 T
// The service data structures do not change, only  |# c) D5 m) p$ D
// references to ModelObjects
% h5 H( f) Y) M6 @1 ^& s( sLoginResponse response;
! m. a4 ^5 k6 m# uTeamcenter::Soa::Common::AutoPtr<User> user;" j6 A  f( k7 U* ]; h; [
// Call a service that returns a ModelObject (User)" f1 }0 B1 m8 k2 u) v6 [
response = sessionService->login(name,pass, “”,””, descrim );  x& C0 e- ^7 K( ^$ D" L5 P+ G0 G
user = response.user;2 g; x( L1 W( Y2 \/ A% L
// Since we are not dealing directly with pointers,* _( _* Y; I4 P, b: b4 i: @. `
// NULL does not make sense here, use the isNull method from the
$ {, Z+ M5 ^! U  o8 r8 h! a% S5 V+ `// AutoPtr template class.
1 K* D; z% R( B/ y3 }4 c3 oif( user.isNull()). X% r0 d+ s. l
{
* ^0 E7 H4 c. T- ^...
4 O. V7 C2 p8 C6 q0 r. O2 y) g}
- ?. I% I9 T( @1 d: ?6 {else. F  {2 b8 O% e1 l
{+ v2 Q; S- Q+ i# ~% p, f" Z
// Release the instance and
9 l; |& R' A1 M% x3 U  \user.release();" v; N+ I+ C5 T) T% ~7 C
}
1 L3 D, n2 h+ Q) P( M
1 i' z' G: i- W, [

0 j. f; R' s- z
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了