1-128 SOMobjects Base Toolkit: Programmer’s Reference Manual
somCastObj Method
Purpose
Changes the behavior of an object to that defined by any ancestor of the true class of the
object.
IDL Syntax
boolean somCastObj (in SOMClass ancestor);
Description
The somCastObj method changes the behavior of an object so that its behavior will be that
of an instance of the indicated ancestor class (with respect to any method supported by the
ancestor). The behavior of the object on methods not supported by the ancestor remains
unchanged.
This operation actually changes the class of the object (since an object’s behavior is defined
by its class). The name of the new class is derived from the initial name of the object’s class
and the name of the ancestor class, as illustrated in the following example.
The somCastObj method may be used on an object multiple times, always with the
restriction that the ancestor class whose behavior is selected is actually an ancestor of the
true (original) class of the object.
Parameters
receiver A pointer to an object of type SOMObject.
ancestor A pointer to a class that is an ancestor of the actual class of the receiver.
Return Value
The somCastObj method returns 1 (TRUE) if the operation is successful and 0 (FALSE)
otherwise. The operation fails if ancestor is not actually an ancestor of the class of the
object.
Example
#include <som.h>
main()
{
SOMClassMgr cm = somEnvironmentNew();
SOM_Test(1 == _somCastObj(cm, _SOMObject));
_somDumpSelf(cm, 0));
SOM_Test(1 == _somResetObj(cm));
_somDumpSelf(cm, 0);
}
/* output:
* {An instance of class SOMClassMgr–>SOMObject
* at address 20061268
* }
* {An instance of class SOMClassMgr at address 20061268
* ... <SOMClassMgr State Information> ...
* }
*/
Kommentare zu diesen Handbüchern