SIDL Feature | C++ Implementation |
---|---|
packages | C++ namespaces (no name transformations, but UCxx binding nests everything in a ucxx namespace until Babel 1.0 release.) |
version numbers | ignored |
interface | C++ class (called ``stub'', serves as a proxy to the implementation) |
class | C++ class (called ``stub'', serves as a proxy to the implementation) |
methods | C++ member functions; uses base method name when overloading; no name mangling; NOTE: Member functions beginning with a leading underscore(_) indicate a builtin function that is implicit by Babel or the C++ binding. |
static methods | 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. |
reference counting | SIDL C++ stubs can be treated as smart-pointers. Constructors, destructors, and operators are overloaded so that explicit calls to addRef() or deleteRef() are rarely needed. |
casting | Upcasting is safely handled with simple assignment. Downcasting should be done with sidl::babel_cast<>(). User should never call dynamic_cast<>() on a SIDL object since Babel's runtime system needs to be involved in verifying legality of the downcast. Downcasts should be checked by a call to (_is_nil(), or _not_nil()). |
instance creation | Use static member function ``_create''. The default constructor for a C++ stub creates the equivalent of a NULL pointer. Works only with non-abstract classes. |
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.
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.
#ifdef SIDL_USE_UCXX using namespace ucxx; #endif sidl::BaseClass object = sidl::BaseClass::_create(); sidl::BaseInterface interface = object;
Here is an example call to the addSearchPath in the SIDL.Loader class:
#ifdef SIDL_USE_UCXX using namespace ucxx; #endif std::string s("/try/looking/here"); sidl::Loader::addSearchPath( s );
Examples of calls to SIDL overloaded methods are based on the overload_sample.sidl file shown in Section 5.6. Recall that the file describes three versions of the getValue 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:
#ifdef SIDL_USE_UCXX using namespace ucxx; #endif bool b1, bresult; int i1, iresult, nresult; Overload::Sample t = Overload::Sample::_create(); nresult = t.getValue(); bresult = t.getValue(b1); iresult = t.getValue(i1);