Implicitly defined methods

The C binding for interfaces and classes includes two methods for perform type casts. The methods are named _cast and _cast2. The leading underscore prevents these built in methods from conflicting with a user method because user methods cannot begin with an underscore. These methods increases the reference count of the underlying object if the cast succeeds -- in Babel releases prior to 0.11.0 these methods did not increment the reference count. Every object has these two methods, we will use sidl.BaseClass as an example. Here are the signatures for _cast and _cast2 from sidl.BaseClass.


sidl_BaseClass
sidl_BaseClass__cast(void* obj, /* out */ sidl_BaseInterface *_ex);

void*
sidl_BaseClass__cast2(void* obj, const char* type,
                      /* out */ sidl_BaseInterface *_ex);

The _cast method attempts to cast a SIDL interface or object pointer to a pointer to sidl.BaseClass. The _cast2 method attempts to cast a SIDL interface or object pointer to a pointer to an interface or object pointer of the type named type. In the case of _cast2, the client is responsible for casting the return value into the proper pointer type. Both methods are NULL safe. A NULL return value indicates that the cast failed or that obj was NULL.

Non-abstract classes have an additional implicit method called _create to create new instances of the class. Interfaces and abstract classes do not have this method because you cannot instantiate them. The _create method returns a new reference that the client must manage. Here is an example of its signature.


/**
 * Constructor function for the class.
 */
sidl_BaseClass
sidl_BaseClass__create(/* out */sidl_BaseInterface *_ex);



babel-0.99.0
users_guide Last Modified 2006-04-20

http://www.llnl.gov/CASC/components
components@llnl.gov