All classes created from an IDL inherit the CORBA::Object.
The CORBA::Object interface defines operations that can be invoked on any object reference.
The IDL definition for CORBA::Object is:
module CORBA _{
Interface Object
{
boolean _is_a(in string logical_type_id);
boolean _is_equivalent(in Object other_obj);
boolean _non_existent( );
InterfaceDef _get_interface( );
static Objectr _duplicate(object_prt obj);
void release ( );
static Objectr _narrow(object_prt obj);
static Object is_nil( );
};
}
The C++ class definition created for the CORBA::Object IDL is:
Class Object
{
boolean _is_a(in string logical_type_id);
boolean _is_equivalent(in Object other_obj);
boolean _non_existent( );
InterfaceDef_ptr _get_interface( );
static Object_ptr _duplicate(object_prt obj);
void release ( );
static Object_ptr _narrow(object_prt obj);
static Object_ptr is_nil( );
};
The following methods can be performed on any object created from an IDL object:
When you need more than one copy of an object reference, the client may create a duplicate. If the given object reference is nil, the _duplicate function returns a nil object reference. The object returned by this call should be freed using CORBA::release or should be assigned to CORBA::Object_var for automatic destruction.
Note: The object implementation is not involved in creating the duplicate, and the implementation cannot distinguish whether the original or a duplicate was used in a particular request. For example:
CORBA::Object_ptr Account2 = CORBA::Object::_duplicate(Account);
When an object reference is no longer needed by a program, its storage may be reclaimed by use of the release operation.
Note: The object implementation is not involved and neither the object itself nor any other reference to it is affected by the release operation. For example:
Account2:: release( );
An operation on the object reference, get_interface, returns an object in the Interface Repository, which provides type information that may be useful to a program.
This member function is used to determine if an object is an instance of the repository type that you specify in the logical_type_id parameter. It facilitates maintaining type-safety for object references over the scope of an ORB. It returns TRUE if the object is an instance of the specified type, or if the object is an ancestor of the "most derived" type of that object.
For example:
CORBA::Boolean ab = op->_is_a("Account");
This member function is used to determine if two object references are equivalent, so far as the ORB can easily determine. It returns TRUE if the object reference is equivalent to the object reference you pass as a parameter. If two object references are identical, they are equivalent. Two different object references that refer to the same object are also equivalent.
For example:
CORBA::Object_ptr account2 = CORBA::Object::_duplicate(account1); CORBA::Boolean b = account1->_is_equivalent(account2);
This member function returns a reference to a nil object belonging to a given pseudo-object class. To test whether a given object is nil, use the appropriate CORBA::is_nil member function. Calling the CORBA:is_nil routine on any _nil member function always yields CORBA_TRUE.
For example:
CORBA::Object_ptr op = CORBA::Object::_nil( );
An object reference whose value is OBJECT_NIL denotes no object. You can test an object reference for this value by using the is_nil operation. The object implementation is not involved in the nil test.
For example:
CORBA::Object_ptr op = CORBA::Object::_nil( );
If (op::is_nil) { /* no object */ }
This member function may be used to determine if an object (that is, a proxy object) has been destroyed. It does this without invoking any application-level operation on the object and so will never affect the object itself. It returns TRUE (rather than raising CORBA::OBJECT_NOT_EXIST) if the ORB knows authoritatively that the object does not exist; otherwise, it returns FALSE.
This member function defines a static member function named _narrow that returns a new object reference given an existing reference. Like CORBA::Object_duplicate, this function returns a nil object reference if the given reference is nil. Unlike _duplicate, the parameter to _narrow is a reference of an object of any interface type (object_ptr).
If the (runtime) type of the parameter object can be widened to the requested interface type, _narrow will return a valid object reference. Otherwise, _narrow returns a nil object reference.
If successful, _narrow creates a new object reference and does not consume the given object reference; the caller is responsible for releasing both the original and the new reference.
The _narrow operation can throw CORBA system exceptions.
For example:
Savings_ptr ps = new Savings("1234")
Account_ptr ap = Account::_narrow(ps);
Object references are associated with ORB internal identifiers, which may indirectly be accessed by applications using the hash( ) operation. The value of this identifier does not change during the lifetime of the object reference, and so neither will any hash function of that identifier.
The value of this operation is not guaranteed to be unique; that is, another object reference may return the same hash value. However, if two object references hash differently, applications can determine that the two object references are not identical.
The is_equivalent( ) operation is used to determine if two object references are
equivalent, so far as the ORB can easily determine. It returns TRUE if the target object
reference is known to be equivalent to the other object reference passed as its parameter; otherwise, it returns FALSE.
If two object references are identical, they are equivalent. Two different object references that refer to the same object are also equivalent.