1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 2002-2-1 (1.70)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Calling Methods from C++</TITLE>
<META NAME="description" CONTENT="Calling Methods from C++">
<META NAME="keywords" CONTENT="users_guide">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="LaTeX2HTML v2002-2-1">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
<LINK REL="STYLESHEET" HREF="users_guide.css">
<LINK REL="next" HREF="node126.html">
<LINK REL="previous" HREF="node124.html">
<LINK REL="up" HREF="node120.html">
<LINK REL="next" HREF="node126.html">
</HEAD>
<BODY >
<DIV CLASS="navigation"><!--Navigation Panel-->
<A NAME="tex2html2583"
HREF="node126.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2577"
HREF="node120.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2571"
HREF="node124.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2579"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html2581"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2584"
HREF="node126.html">Catching and Throwing Exceptions</A>
<B> Up:</B> <A NAME="tex2html2578"
HREF="node120.html">C++ Bindings</A>
<B> Previous:</B> <A NAME="tex2html2572"
HREF="node124.html">SIDL's Main C++ Header</A>
<B> <A NAME="tex2html2580"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html2582"
HREF="node317.html">Index</A></B>
<BR>
<BR></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION03250000000000000000"></A>
<A NAME="6608"></A>
<BR>
Calling Methods from C++
</H1>
Since C++ is an object-oriented language, there is a lot less programmer
overhead in using SIDL from the C++ perspective than from non-OO
languages such as C or FORTRAN 77.
<P>
<A NAME="6609"></A><A NAME="6610"></A>
<A NAME="6611"></A><A NAME="6612"></A>
<A NAME="6613"></A>
<P>
<BR><P></P>
<DIV ALIGN="CENTER">
<A NAME="tbl:cxx:features"></A>
<DIV ALIGN="CENTER">
<A NAME="6615"></A>
<TABLE CELLPADDING=3 BORDER="1">
<CAPTION><STRONG>Table 7.2:</STRONG>
SIDL Features Mapped onto C++</CAPTION>
<TR><TH ALIGN="CENTER"><SPAN CLASS="textbf">SIDL Feature</SPAN></TH>
<TH ALIGN="LEFT" VALIGN="TOP" WIDTH=342><SPAN CLASS="textbf">C++ Implementation</SPAN></TH>
</TR>
<TR><TD ALIGN="CENTER">packages</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>C++ namespaces (no name transformations)</TD>
</TR>
<TR><TD ALIGN="CENTER">version numbers</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>ignored</TD>
</TR>
<TR><TD ALIGN="CENTER">interface</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>C++ class (called "stub", serves as a proxy to the implementation)</TD>
</TR>
<TR><TD ALIGN="CENTER">class</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>C++ class (called "stub", serves as a proxy to the implementation)</TD>
</TR>
<TR><TD ALIGN="CENTER">methods</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>C++ member functions; uses base method name when overloading; no name
mangling;
NOTE: Member functions beginning with a leading underscore
"_" may be Babel internals, or specific to C++ binding.</TD>
</TR>
<TR><TD ALIGN="CENTER">static methods</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>Static C++ member functions; uses base method name when overloading;
no name mangling;
even works for dynamically loaded object's exceptions
thrown and caught using C++ exception handling.</TD>
</TR>
<TR><TD ALIGN="CENTER">reference counting</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>SIDL C++ stubs can be treated as smart-pointers.
Constructors, destructors, and operators are overloaded
so that explicit
calls to <TT>addRef()</TT> or <TT>deleteRef()</TT>
are rarely needed.</TD>
</TR>
<TR><TD ALIGN="CENTER">casting</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>Assignment operators are overloaded to handle safe
casting up and down the inheritance hierarchy.
User should never call <TT>dynamic_cast<>()</TT> on a
SIDL object since the stubs inheritance hierarchy
does not follow the SIDL inheritance hierarchy.
Attempted downcasts using assignment should be checked
by a call to (<TT>_is_nil()</TT>, or <TT>_not_nil()</TT>).</TD>
</TR>
<TR><TD ALIGN="CENTER">instance creation</TD>
<TD ALIGN="LEFT" VALIGN="TOP" WIDTH=342>Use static member function "<TT>_create</TT>". The
default constructor for a C++ stub creates the
equivalent of a NULL pointer. Works only
with non-abstract classes.</TD>
</TR>
</TABLE>
</DIV>
</DIV>
<BR>
<P>
These proxy classes (we call "stubs") serve as the firewall
between the application in C++ and Babel's internal workings.
As one would expect, the proxy classes maintain minimal state so that,
unlike C or FORTRAN 77, there is no special context argument added to
non-static member functions.
<P>
Below are examples using standard classes. The first is an example of creating
an object of the base class and its association to the base interface.
<P>
<BR>
<PRE CLASS="verbatim">sidl::BaseClass object = sidl::BaseClass::_create();
sidl::BaseInterface interface = object;
</PRE></td></tr></table></blockquote>
<P>
Here is an example call to the addSearchPath in the SIDL.Loader class:
<P>
<BR>
<PRE CLASS="verbatim">std::string s("/try/looking/here");
sidl::Loader::addSearchPath( s );
</PRE></td></tr></table></blockquote>
<P>
Examples of calls to SIDL overloaded methods are based on the
<TT>overload_sample.sidl</TT> file shown in Section <A HREF="node107.html#sec:overloading">5.6</A>.
Recall that the file describes three versions of the <TT>getValue</TT> method.
The first takes no arguments, the second takes an integer argument, and the
third takes a boolean. Each is called in the code snippet below:
<P>
<BR>
<PRE CLASS="verbatim">
bool b1, bresult;
int i1, iresult, nresult;
Overload::Sample t = Overload::Sample::_create();
nresult = t.getValue();
bresult = t.getValue(b1);
iresult = t.getValue(i1);
</PRE></td></tr></table></blockquote>
<P>
<DIV CLASS="navigation"><HR>
<!--Navigation Panel-->
<A NAME="tex2html2583"
HREF="node126.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="next.png"></A>
<A NAME="tex2html2577"
HREF="node120.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="up.png"></A>
<A NAME="tex2html2571"
HREF="node124.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="prev.png"></A>
<A NAME="tex2html2579"
HREF="node14.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="contents.png"></A>
<A NAME="tex2html2581"
HREF="node317.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html2584"
HREF="node126.html">Catching and Throwing Exceptions</A>
<B> Up:</B> <A NAME="tex2html2578"
HREF="node120.html">C++ Bindings</A>
<B> Previous:</B> <A NAME="tex2html2572"
HREF="node124.html">SIDL's Main C++ Header</A>
<B> <A NAME="tex2html2580"
HREF="node14.html">Contents</A></B>
<B> <A NAME="tex2html2582"
HREF="node317.html">Index</A></B> </DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<br><br>babel-0.10.2<br>users_guide Last Modified 2005-03-23<br><br><a href="http://www.llnl.gov/CASC/components">http://www.llnl.gov/CASC/components</a><br><a href="mailto:components@llnl.gov">components@llnl.gov</a>
</ADDRESS>
</BODY>
</HTML>
|