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

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

[复制链接]

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

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

admin 楼主

2015-2-3 09:18:14

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

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

x
Teamcenter SOA开发中关于变量声明,转换等代码的新处理方式
; C$ R) C& s" j) N6 W+ F
4 x& h* ^* z6 A+ {
  Q. ^. T/ s! \$ t: a) d9 I
1 变量声明
# V7 ~. B! e4 {6 h# X/ F% u: v6 e2 ~& ?4 _

: z; h  w: h5 s* A3 ao Old way9 W6 n8 L& _5 I2 _3 N1 L
// Declare pointers for an Item, Form and vector of ModelObjects
% [* ]( e9 s% F! z3 w// initialize to NULL5 B/ c8 k8 \' C# g
Item *theItem = NULL;1 \7 N/ @9 v4 u" V& f( F* q% K
Form *theForm = NULL;, p% V% p6 v! ^
vector< ModelObject *> objects;
2 }+ U% `* M. E/ e$ G) O! s7 P...3 g4 Q) @8 [: x6 v4 t
// Use the Item0 R/ C8 V% l0 V! i  X
theForm = theItem->get_item_master_tag();
( |. I- t3 f" yobjects = theItem->get_revision_list();
1 F* A, v+ I0 d4 N# Ro New way: u! K" Q! f" X
// Declare AutoPtr for an Item, Form and vector of ModelObjects4 ^% Q3 O2 g2 _/ X+ w
// all AutoPtrs are instantiated as NULL
: v% ~# X* F+ T7 B' l& |Teamcenter::Soa::Common::AutoPtr<Item> theItem;
' ?  s- Z8 y, a! }5 pTeamcenter::Soa::Common::AutoPtr<Form> theForm;
6 Y% E* E) u) ~9 [/ _6 \; nvector< Teamcenter::Soa::Common::AutoPtr <ModelObject> > objects;+ ]5 P" x4 n# {. i( M' ?/ P! X! [' Z
// Use of the ModelObject variables remains unchanged% ], g- h" C5 N8 P
theForm = theItem->get_item_master_tag();: i  w! l5 |+ W2 e% I  M) \1 Q$ R5 l
objects = theItem->get_revision_list();
& a; ~; ~) d5 ^8 a  [& l/ q0 ^* A' o
: p5 x! b; i+ r7 F3 D# v+ B! Q
2 类型转换 5 J4 `  d3 B. w$ W4 J# f8 s, h
9 I% [3 _/ G! w5 C9 P9 x/ W
o Old way: @: c# `. y4 m( [- k+ Q/ a7 {
// Declare the variables
) m) v2 ^! y; J6 {! E7 vUser *user;) u# \; y# T8 R/ D) X0 n. z% m
ModelObject *anObj;& c/ e3 o7 r( v0 x
Folder *folder;; x) R9 @& t9 A* \
user = sessionService->login(name,pass, “”,””, descrim ).user;
, X8 y" S2 |; h/ f// Cast to the base ModelObject class
) u) ~* q& p. Q% kanObj = (ModelObject*)user;2 v( r" f) M& x' Q- M7 q4 H" {
// Cast to a speicfic sub-type, if not NULL% c' a& e% `/ n
// do something with the new pointer2 n1 x  @+ e/ ?* V
user = dynamic_cast<User*>(anObj);
3 Y, G8 W% b* v/ j2 _0 S/ Bif(user != NULL)
  E2 @8 ?+ }+ E1 l" D, q# v2 _: I% Y{
7 ^2 T& w. P# V: n! yfolder = user->get_home_folder();7 Q7 ~& j6 `4 t7 y& r2 c5 Z
}: f& z2 L. E/ u, P  L0 c
o New way& l6 i; f8 v- @( e
// Declare the variables
  F$ w) q6 N* f2 }' N7 c. S: O0 p" V; `Teamcenter::Soa::Common::AutoPtr<User> user;
  \% @/ M* L( c$ ?Teamcenter::Soa::Common::AutoPtr<ModelObject> anObj;
1 C5 \' S9 r; p" Q: [% ^6 pTeamcenter::Soa::Common::AutoPtr<Folder> folder;1 b& h! U, J+ @- m- z- @5 _: h
user = sessionService->login(name,pass, “”,””, descrim ).user;- }& I5 t, ~3 ^# a
// Cast to the base ModelObject class3 R3 J- {2 o" Y2 t9 C! {+ l
anObj = user.cast<ModelObject>();
% K3 M1 I7 @$ E3 n: m! x" S" @1 h// Put the cast to a speicfic sub-type, in a try/caTCh block& j" W! z  I& q+ I
// if std::bad_cast not thrown, then cast was successful
1 z3 e, N8 l$ @& F0 J0 Jtry/ H0 x$ S' X; Z3 Z8 w" V% B
{% ?+ ]+ N. z4 I1 i  U
user = anObj.dyn_cast< User >();
/ n$ p0 u( z. y+ P# L/ o, Ffolder = user->get_home_folder();
# s) K8 q" W3 [5 m8 ^4 a7 s}5 B& \8 p  @6 D7 I
catch(std::bad_cast&){}
* M! r6 {+ t+ l; I" I0 ^' k7 _
0 r6 v, n7 n) l6 {: S) }' V& r* h  G$ b- p2 b6 M1 P& A+ T
3 关于NULL 赋值) i$ ], _& D: M6 i

! w4 ~1 p, G+ c8 h8 wo Old way
2 g9 Z9 X& r- s// Declare the variables
: f" g  ?& @8 N; A7 M$ M% F* qLoginResponse response;
) _8 a: L6 A6 ^% o$ U& MUser * user;7 g/ F  L# D8 H6 J5 T* `& h7 j
// Call a service that returns a ModelObject (User)
& W5 a, O- t' q# L1-28 Services Guide PLM00076 Jresponse = sessionService->login(name,pass, “”,””, descrim );
5 L5 J2 W4 i3 q5 X' vuser = response.user;3 A  s7 R, X: T( y( X9 P$ u- o
// Test that instnace against NULL
2 Y+ j6 B7 G" W; ~if( user == NULL)) w' B* ^# Q1 Y8 v1 K) ?
{
# x- C; d9 G( J...
( Q7 L! }& F) b- Z}
4 l" N# W1 z* O9 t; melse
' x/ ]9 e  x0 Y6 {+ B6 J$ l+ w{
  n$ b/ W, P9 H7 `  c; C2 Z- x$ h// Assign NULL to the pointer, k3 ~; y+ E# m
user = NULL;7 `! O( B! `2 U4 E' r! y
}, H# O7 u4 G: z( o% J) C' L: f# G
o New way8 n+ i' a$ ^; C, Z5 m
// Declare the variables
  P  C6 g3 U2 g! W; l6 i// The service data structures do not change, only
3 A# }8 d% s, h// references to ModelObjects
, {. f9 G1 k; OLoginResponse response;' z7 g" _  F/ D
Teamcenter::Soa::Common::AutoPtr<User> user;
8 W# g! G  ~0 H# Q! `$ c8 n// Call a service that returns a ModelObject (User)
# ]9 f* z% `7 g0 n5 m+ Dresponse = sessionService->login(name,pass, “”,””, descrim );/ d, C$ {5 t0 z# }7 l8 V
user = response.user;
% w# X8 \9 U0 n1 h. x' T// Since we are not dealing directly with pointers,
/ l- ?2 e; L2 v' z2 `// NULL does not make sense here, use the isNull method from the; D: V) H. o7 e4 w7 `  q
// AutoPtr template class.
" b0 V( e: b+ X6 b+ m; ^if( user.isNull())/ _5 L4 F* c+ V: t% ^. C$ i7 A
{
3 H$ v/ i: P- G...
4 R$ ]. e! T& D}
+ d! \! y0 g1 i0 X6 D% oelse
# C0 m( M, `/ [{# t0 o. }$ p3 Q9 s2 w
// Release the instance and
% G# m' [* z! c* R" g: s) x5 Guser.release();. O  l5 q4 F1 i
}
* k* ?2 m* L' @) U' ~: T
8 {% f4 K4 a) l" T
1 y, O5 j) X) c$ l9 i( @) x
上海点团信息科技有限公司,承接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二次开发专题模块培训报名开始啦

    我知道了