SIDL Feature | C++ Implementation |
---|---|
packages | C++ namespaces (no name transformations) |
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 "_" may be Babel internals, or specific to 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 | Assignment operators are overloaded to handle safe casting up and down the inheritance hierarchy. User should never call dynamic_cast<>() 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 (_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.
sidl::BaseClass object = sidl::BaseClass::_create(); sidl::BaseInterface interface = object;
Here is an example call to the addSearchPath in the SIDL.Loader class:
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:
bool b1, bresult; int i1, iresult, nresult; Overload::Sample t = Overload::Sample::_create(); nresult = t.getValue(); bresult = t.getValue(b1); iresult = t.getValue(i1);