C bindings for interfaces and classes include two implicitly defined
methods for performing type casts. The methods are _cast and
_cast2.
The _cast method casts a SIDL interface or object pointer to a
sidl.BaseClass pointer. The _cast2 method casts a SIDL
interface or object pointer to a named type pointer.
In the latter case, the client is responsible
for casting the return value into the proper pointer type.
Using sidl.BaseClass as an example, signatures of the
two methods are
sidl_BaseClass sidl_BaseClass__cast(void* obj, /* out */ sidl_BaseInterface *_ex); void* sidl_BaseClass__cast2(void* obj, const char* type, /* out */ sidl_BaseInterface *_ex);
Using either method results in the reference count of the underlying object being increased if the cast succeeded. Success can be determined by checking the return value for a non-NULL result. That is, if a NULL value is returned from either method, then the cast failed or obj was NULL.
NOTE
These methods did not increment the reference count in Babel releases prior
to 0.11.0.