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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式* }, V* m; d! Y! N
# [+ D2 |7 g* l- ?0 p

3 b) e* B2 x+ }1 变量声明" |1 m9 I3 r9 l  @. ~
- L. {  ^! s* F) L3 m- \- l) ], W

; a" I9 ~) Y, P8 `$ a* io Old way
; A1 I# K+ A; C5 L// Declare pointers for an Item, Form and vector of ModelObjects# }4 {5 J; {  v! d$ f
// initialize to NULL# F* G1 f* |- x- I5 M& P
Item *theItem = NULL;3 k2 T% [! J2 {0 l
Form *theForm = NULL;6 C9 J1 C1 F( t0 n
vector< ModelObject *> objects;+ t* e6 B5 R) f  v) o
...
4 f. _) l) V! L0 b1 y6 s  F0 \// Use the Item
! a5 r' S; n2 h3 @/ j2 N7 `theForm = theItem->get_item_master_tag();
1 l7 \: `- w+ }4 ~objects = theItem->get_revision_list();
- C8 @9 [* t$ q# J% io New way
9 p9 E) Y- w# C8 O5 g// Declare AutoPtr for an Item, Form and vector of ModelObjects
6 x: i8 y6 e- E// all AutoPtrs are instantiated as NULL
. ^5 d$ f: k9 b* GTeamcenter::Soa::Common::AutoPtr<Item> theItem;# _3 X9 O8 q$ q1 [1 w! a
Teamcenter::Soa::Common::AutoPtr<Form> theForm;* O5 S. o; U: [: F& o  k
vector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;/ h: Y' A, r, I, F$ ~6 z. U
// Use of the ModelObject variables remains unchanged
. Z1 K- ?% ^3 g$ A7 p; p" btheForm = theItem->get_item_master_tag();
" r/ }8 z; s7 Sobjects = theItem->get_revision_list();& s# u. Y; l/ _5 S) ?1 E
7 ?) r; X) `2 u+ G/ v
1 W" [8 Q/ J' r
2 类型转换 % ^, o* O4 R' X  @: L

/ ?/ K  s$ j- Z+ L8 m/ uo Old way, N8 a5 D- [' A/ j" b
// Declare the variables
- @3 f8 n6 `: I& HUser *user;& \6 T3 G' g. ?, Q' l
ModelObject *anObj;
( U) D" }/ p, oFolder *folder;
" y3 C, Q7 O( ~" `* kuser = sessionService->login(name,pass, “”,””, descrim ).user;
1 q1 ~, |8 ?* d' O/ I3 A, [  J// Cast to the base ModelObject class0 |9 o& e. C# w# c: Q& o. |
anObj = (ModelObject*)user;
+ m4 l; w0 y4 r2 g// Cast to a speicfic sub-type, if not NULL+ [: o5 t$ I! V1 q3 W5 r: H8 s) F
// do something with the new pointer% b" l/ [' j! e! p! h
user = dynamic_cast<User*>(anObj);
8 j- L' r9 J6 J# `, [if(user != NULL)* H# i' Y3 D$ K% e8 m5 x
{
* o  O/ r/ U. a, f7 D3 ]folder = user->get_home_folder();
9 a3 i$ C5 f0 F1 ?! x}; v, p5 I" [+ K9 _( `1 `$ @
o New way
4 u/ ^8 P, Q9 W1 _, U// Declare the variables- A0 S4 s. \$ B" y' T
Teamcenter::Soa::Common::AutoPtr<User> user;( z; K* T% P  {6 r" d& n* i
Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;3 h" y- `! A3 c+ @4 ~
Teamcenter::Soa::Common::AutoPtr<Folder> folder;$ L9 m' p0 K$ v* ~  n( |  Z
user = sessionService->login(name,pass, “”,””, descrim ).user;
* o" G! r% q; W+ y// Cast to the base ModelObject class
' u# a6 R* q; d) B3 vanObj = user.cast<ModelObject>();) n7 l, v" e. [% b, ]
// Put the cast to a speicfic sub-type, in a try/caTCh block; Q# D$ H) `% d! p: L, [3 v3 D. A
// if std::bad_cast not thrown, then cast was successful
; `* p6 c9 ]7 @+ Vtry# P$ n9 T+ E! V" N/ R
{  L' E0 ^. w% E" F5 k6 [* E
user = anObj.dyn_cast< User >();
) P/ g- @2 G& H& ]6 t) a4 jfolder = user->get_home_folder();$ ~: O  K6 G( C9 @
}( P3 E$ [% k4 L: Z) j4 H
catch(std::bad_cast&){}" c0 L3 g8 ]3 X# R* U# d

: r- D+ d( {0 x. ]' f( S# P# \. o/ Y' G+ r3 @# q
3 关于NULL 赋值8 \4 B$ g9 O+ o
* ^2 T' M4 b( U8 \  I  D' f( ^, n
o Old way1 E8 O# l+ N0 p9 z
// Declare the variables
  P4 m5 ~" _4 v; N) k6 p$ zLoginResponse response;6 R3 q" a- N2 [9 w: `0 d, L) J
User * user;
( o0 B+ t/ F0 ^+ E( F( d// Call a service that returns a ModelObject (User)# K8 \9 X( `4 q. R  _5 R, ~$ j
1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
; c6 r8 e5 N. t4 z5 C$ ^user = response.user;
5 `6 U2 C  O( W5 n5 Z1 N// Test that instnace against NULL
" T; k4 `8 l+ hif( user == NULL)7 _# C) _6 _. Z! x
{; \; u5 b) Q7 B8 ]: N# l
...  l* L5 p& g% u* {/ `) v- r
}; @* J6 i( x6 r3 \3 g% c
else
& ^8 S9 o0 Z( U{0 k. k4 U$ w8 H8 g  Q
// Assign NULL to the pointer* D, F8 @- k, T& f& W
user = NULL;
! n& g! t) b. z}( B) S2 N* p6 B# R/ Y1 x; Y' ?
o New way
% J! o6 ?: n) X3 O// Declare the variables5 L6 e7 D7 d2 P. t- s8 g
// The service data structures do not change, only
9 H- w% ?, E8 p6 t6 B7 i4 j// references to ModelObjects) o7 q  u0 {# B
LoginResponse response;
4 E6 Q/ c$ L5 F& I- E/ qTeamcenter::Soa::Common::AutoPtr<User> user;6 \, n, r, q) `2 `
// Call a service that returns a ModelObject (User)
2 U. W% h4 }$ P; }0 sresponse = sessionService->login(name,pass, “”,””, descrim );
# |- g6 {" o" c5 Q' nuser = response.user;/ M( K' C5 x/ c- A( m4 x. @
// Since we are not dealing directly with pointers,4 G: V( J) g' T$ [
// NULL does not make sense here, use the isNull method from the
8 M. A) Y* u5 j! T// AutoPtr template class.$ C3 `- a. c$ P% Y: K' Z
if( user.isNull())
! R" F0 s" d2 j, P$ @  C{
5 P! s% V3 [6 w( p/ A4 z...2 s9 }: N4 G% V# T: Y
}
8 |# C9 u- B/ ~7 u2 y; W- Zelse8 h* f5 g2 @, g& [
{' C' S. r; x/ c, A
// Release the instance and8 ^! ?3 c7 z2 w: \/ g8 ]
user.release();  Y2 w  W! H0 c8 ]
}
6 I. A: F+ o% K( T3 e$ ^/ F4 C
9 {' k) p3 T; [- Y
2 F: z5 L% A* D7 Z1 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二次开发专题模块培训报名开始啦

    我知道了